// JavaScript Document

function isEmpty(mytext) {
	var re = /^\s{1,}$/g; //match any white space including space, tab, form-feed, etc.
	if ((mytext.length==0) || (mytext=="") || ((mytext.search(re)) > -1)) {
		return true;
	}
	else {
		return false;
	}
}

function isNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
	  { 
	  Char = sText.charAt(i); 
	  if (ValidChars.indexOf(Char) == -1) 
		 {
		 IsNumber = false;
		 }
	  }
   return IsNumber;

}

function isTime(strValue) {
	var objRegExp = /(00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23)[:](0|1|2|3|4|5)\d{1}/
	if(objRegExp.test(strValue) || isEmpty(strValue)){
		return true;
	}else{
		return false;
	}
}

function isDate(strValue) {
  if(isEmpty(strValue)){
	  return true;
  }else{
	  var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
	 
	  //check to see if in correct format
	  if(!objRegExp.test(strValue))
		return false; //doesn't match pattern, bad date
	  else{
		var strSeparator = strValue.substring(2,3) 
		var arrayDate = strValue.split(strSeparator); 
		//create a lookup for months not equal to Feb.
		var arrayLookup = { '01' : 31,'03' : 31, 
							'04' : 30,'05' : 31,
							'06' : 30,'07' : 31,
							'08' : 31,'09' : 30,
							'10' : 31,'11' : 30,'12' : 31}
		var intDay = parseInt(arrayDate[0],10); 
	
		//check if month value and day value agree
		if(arrayLookup[arrayDate[1]] != null) {
		  if(intDay <= arrayLookup[arrayDate[1]] && intDay != 0)
			return true; //found in lookup table, good date
		}
		
		//check for February (bugfix 20050322)
		//bugfix  for parseInt kevin
		//bugfix  biss year  O.Jp Voutat
		var intMonth = parseInt(arrayDate[1],10);
		if (intMonth == 2) { 
		   var intYear = parseInt(arrayDate[2]);
		   if (intDay > 0 && intDay < 29) {
			   return true;
		   }
		   else if (intDay == 29) {
			 if ((intYear % 4 == 0) && (intYear % 100 != 0) || 
				 (intYear % 400 == 0)) {
				  // year div by 4 and ((not div by 100) or div by 400) ->ok
				 return true;
			 }   
		   }
		}
	  }  
	  return false; //any other values, bad date
  }
}

function contains(arryA,needle){
	for(var i=0;i<arryA.length;i++){
		if(arryA[i]===needle){
			return true;
		}
	}
  	return false;
}

// date picker stuff
$(function()
{
	$('.date-pick').datePicker({startDate:'01/01/1996'})
	$('#activedate').bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#expirydate').dpSetStartDate(d.addDays(1).asString());
			}
		}
	);
	$('#expirydate').bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#activedate').dpSetEndDate(d.addDays(-1).asString());
			}
		}
	);
	
});

function generalSetUp(){
	if(typeof setUpGalleryPhotoClick == 'function') {
		setUpGalleryPhotoClick();
	}
	if(typeof setUpWrestlerTabs == 'function') {
		setUpWrestlerTabs();
	}
	if(typeof setUpGalleryTabs == 'function') {
		setUpGalleryTabs();
	}
	if(typeof setUpGalleryLightBox == 'function') {
		setUpGalleryLightBox();
	}
	if(typeof setUpPikaChoose == 'function') {
		setUpPikaChoose();
	}
	
	//generic containers
	if(typeof setUpTabContainer == 'function') {
		setUpTabContainer();
	}
	
	for(i = 0; i < 100; i++){
		$('.lightbox' + i + ' a').lightBox();
		$('#wrestlers .lightbox' + i + ' a').lightBox();
		$('#matches .lightbox' + i + ' a').lightBox();
		$('#events .lightbox' + i + ' a').lightBox();
	}
}



