var lib={};
lib.d=YAHOO.util.Dom;
var oldTab="";
var sideTab="";
function changeTabs(e)
{
	lib.d.removeClass(document.getElementById(oldTab),"defaultTab");
	lib.d.addClass(document.getElementById(e),"defaultTab");
	oldTab=e;
}
function changeSideTabs(e)
{
	lib.d.setStyle(document.getElementById(sideTab),"background","none");
	lib.d.setStyle(document.getElementById(sideTab+"Link"),"color","#999");
	lib.d.setStyle(document.getElementById(e),"background","#990000");
	lib.d.setStyle(document.getElementById(e+"Link"),"color","#fff");
	
	sideTab=e;
}
function ShowHide(id) {
    var e = document.getElementById(id);
    if(e.style.display == 'block')
       e.style.display = 'none';
    else
       e.style.display = 'block';
 }


function ModalPanel(id,w,isModal,customClose)
{
	var closeButtonFlag;
	if (typeof(customClose) != "undefined")
		closeButtonFlag=false;
	else
		closeButtonFlag=true;
	
   this.modalPanel = new YAHOO.widget.Panel(id,  
                                                    { width: w, 
                                                      fixedcenter: true, 
                                                      close:true, 
                                                      draggable: false, 
                                                      zindex:4,
                                                      modal: true,
                                                      visible: false
                                                    } 
                                                );
};

ModalPanel.prototype.showPanel=function(){
	 this.modalPanel.show();  
	};
	ModalPanel.prototype.hidePanel=function(){
		 this.modalPanel.hide();  
		};
	ModalPanel.prototype.createHeader=function(ele)
	{
	    
	    var headText=document.getElementById(ele).innerHTML;
	    this.modalPanel.setHeader(headText);    
	};

	ModalPanel.prototype.renderDialog=function()
	{
	 this.modalPanel.render(document.body);
	};

   

	ModalPanel.prototype.createBody=function(ele){
	var bodyText=document.getElementById(ele).innerHTML;
	this.modalPanel.setBody(bodyText);
	this.modalPanel.render(document.body);
	};

	ModalPanel.prototype.setBody=function(b)
	{
	this.modalPanel.setBody(b);
	}
	ModalPanel.prototype.setHeader=function(h)
	{
	this.modalPanel.setHeader(h);
	}
	
	ModalPanel.prototype.refineLookOfBody=function(){
		lib.d.addClass(this.modalPanel.id,"pymkPanel");
		var bodyDiv= new Array();
		bodyDiv=lib.d.getElementsByClassName("bd","div",this.modalPanel.id);
		lib.d.addClass(bodyDiv,"pymkPanelBody");
		
		};
	
	function showAboutUs()
	{
		var aboutUs= new ModalPanel("about","810px",true,true);
		aboutUs.createBody("aboutusBlock");
		aboutUs.setHeader("<strong>About USC Trojan Cricket Club</strong>")
		aboutUs.renderDialog();
		aboutUs.showPanel();
	}
	

	 function validateAddPlayerForm()
	 {
		 var submitFlag=false;
		 if (checkempty("fn"))
		 {
			 submitFlag=true;
			 if (checkempty("ln"))
			 {
				 submitFlag=true;
				 if (checkempty("dob") && isValidDate(document.getElementById("dob").value))
				 {
					 submitFlag=true;
					 if (checkempty("email") && emailcheck(document.getElementById("email").value))
					 {
						 submitFlag=true;
						 
						 if (checkempty("ph"))
						 {
							 submitFlag=true;
							 if (checkempty("role"))
							 {
								 submitFlag=true;
								 
							 }
							 else
								 {
								 	submitFlag=false;
								 	alert("Role Is required");
								 	document.getElementById("role").focus();
								 	
								 }
						 }
						 else
							 {
							 	submitFlag=false;
							 	alert("Phone Is required");
							 	document.getElementById("ph").focus();
							 	
							 }
					 }
					 else
						 {
						 	submitFlag=false;
						 	alert("Email Is required");
						 	document.getElementById("email").focus();
						 	
						 }
				 }
				 else
					 {
					 	submitFlag=false;
					 	alert("Date of Birth Is required");
					 	document.getElementById("dob").focus();
					 	
					 }
			 }
			 else
				 {
				 	submitFlag=false;
				 	alert("Last Name is required");
				 	document.getElementById("ln").focus();
				 	
				 }
		 }
		 else
			 {
			 	submitFlag=false;
			 	alert("First Name is required");
			 	document.getElementById("fn").focus();
			 	
			 }
	      
		 
		 
		 return submitFlag;
	 }
	 function isValidDate(dateStr) {
		// Checks for the following valid date formats:
		// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
		// Also separates date into month, day, and year variables

		var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

		// To require a 4 digit year entry, use this line instead:
		// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

		var matchArray = dateStr.match(datePat); // is the format ok?
		if (matchArray == null) {
		alert("Date is not in a valid format.")
		return false;
		}
		month = matchArray[1]; // parse date into variables
		day = matchArray[3];
		year = matchArray[4];
		if (month < 1 || month > 12) { // check month range
		alert("Month must be between 1 and 12.");
		return false;
		}
		if (day < 1 || day > 31) {
		alert("Day must be between 1 and 31.");
		return false;
		}
		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Month "+month+" doesn't have 31 days!")
		return false
		}
		if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
		alert("February " + year + " doesn't have " + day + " days!");
		return false;
		   }
		}
		return true;  // date is valid
		}
		//  End -->
		
		 
	 function emailcheck(str) {

			var at="@"
			var dot="."
			var lat=str.indexOf(at)
			var lstr=str.length
			var ldot=str.indexOf(dot)
			if (str.indexOf(at)==-1){
			   alert("Invalid E-mail ID")
			   return false
			}

			if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			   alert("Invalid E-mail ID")
			   return false
			}

			if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			    alert("Invalid E-mail ID")
			    return false
			}

			 if (str.indexOf(at,(lat+1))!=-1){
			    alert("Invalid E-mail ID")
			    return false
			 }

			 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			    alert("Invalid E-mail ID")
			    return false
			 }

			 if (str.indexOf(dot,(lat+2))==-1){
			    alert("Invalid E-mail ID")
			    return false
			 }
			
			 if (str.indexOf(" ")!=-1){
			    alert("Invalid E-mail ID")
			    return false
			 }

			 return true					
		}



	 function checkempty(id)
	 {
		 if ((document.getElementById(id).value).length<2)
			 return false;
		 else
			 return true;
	 }
