function IsNumber(sText,Label)
{
   var ValidChars = "0123456789-";
   var IsNumber=true;
   var Char;
   if(sText=="") {alert(Label+ " Should not be Empty");return false}
   for (i = 0; i < sText.length && IsNumber == true; i++)     
   { 
      Char = sText.charAt(i); 
      if(ValidChars.indexOf(Char) == -1) 
      {
         IsNumber = false;
      }
   }
   if(!IsNumber)
   	alert(Label+ " Must Be Numeric")
   return IsNumber;
}


function IsVaildNumber(sText)
{
   var ValidChars = "0123456789-";
   var IsNumber=true;
   var Char;
   if(sText=="") 
   {
	   IsNumber = false;
	}else{
	   for (i = 0; i < sText.length && IsNumber == true; i++)     
	   { 
		  Char = sText.charAt(i); 
		  if(ValidChars.indexOf(Char) == -1) 
		  {
			 IsNumber = false;
		  }
	   }
	}
    return IsNumber;
}

function isEmailAddr(email,Label) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
return (true)
}
alert("Invalid "+Label+" Address! Please re-enter.")
return (false)
}


function isEmailAddr1(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function trim(Val)
{
	while(''+Val.charAt(0)==' ')
	Val=Val.substring(1,Val.length);
	return Val;
}

function IsValid(Val,Label)
{
	if(trim(Val)=="")
	{
		alert(Label+" is required")
		return false
	}	
	return true
}

function splitText(theNotes)
{
		theString = theNotes.split("\n")
		NewString = ""
		for(i=0;i<theString.length;i++)
		{
			NewString+=theString[i]+"|"
		}
		return NewString
}

var dtCh= "/";
var minYear=1900;
var maxYear=2100;
var minimumYear=1960;
var dateofhire = new Date();
var maximumYear = dateofhire.getFullYear();

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isvalidDate(dtStr,Label){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strMonth=dtStr.substring(0,pos1)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy for "+Label)
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month for "+Label)
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day for "+Label)
		return false
	}
	if (strYear.length != 4 || year==0 || year<minimumYear || year>maximumYear){
		alert("Please enter a valid 4 digit year between "+minimumYear+" and "+maximumYear+" for "+Label)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date for "+Label)
		return false
	}
return true
}

function IsCurrentDate(val,Label) {
	var d1 = val;
	DateArray = d1.split("/");
	
	var dd = new Date();
	var CDate = dd.getDate();
	var CMonth = dd.getMonth();
	var CYear = dd.getFullYear();
	var CMonth1 = CMonth+1;
	if(DateArray[2]>CYear) {
	alert(Label+" Should not be Future Date"); // Year
	return false;
	}
	if(DateArray[2]==CYear) 
	{ 
		if(DateArray[0]>CMonth1)
		{
			alert(Label+" Should not be Future Date"); // Day
			return false;
		}
		if(DateArray[0]==CMonth1)
		{
			if(DateArray[1]>CDate)
			{
				alert(Label+" Should not be Future Date"); // Month
				return false;
			}
		}
		return true;
	}
	return true;
}
function y2k(number) {
	return (number < 1000) ? number + 1900 : number;
}
function validDate(month,year) {
	mm = parseInt(month);
	yy = parseInt(year);
	current = new Date();
	currMonth = parseInt(current.getMonth()+1);
	currYear = parseInt(y2k(current.getYear()));		
	if ((yy == currYear) && (mm < currMonth)) {
		return false;
	}
	else if (yy < currYear) {
		return false;
	}
	return true;
}
function IsValidPhone(sText)
{
   var ValidChars = "0123456789xX()+._- ";
   var IsNumber=true;
   var Char;
   if(sText=="") 
   {
	   IsNumber = false;
	}else{
	   for (i = 0; i < sText.length && IsNumber == true; i++)     
	   { 
		  Char = sText.charAt(i); 
		  if(ValidChars.indexOf(Char) == -1) 
		  {
			 IsNumber = false;
		  }
	   }
	}
    return IsNumber;
}

 //us no
function validatePhone(phoneField,phonenum,format) 
{

	var num = phoneField.value.replace(/[^\d]/g,'');
	if(num.length > 11) {
	
		 alert('Please enter a valid phone number including area code');   
		 return false;
	
	} else {
	
		switch(format) {
	
			case '0': //Format (xxx)-xxx-xxxx
	
				phonenum.value = "(" + num.substring(0,3) + ")-" + num.substring(3, 6) + "-" + num.substring(6);
	
				break;
	
			case '1': //Format xxx-xxx-xxxx
	
				phonenum.value = num.substring(0,3) + "-" + num.substring(3, 6) + "-" + num.substring(6,10) + " " + "x" + num.substring(10);
	
				break;
	
			default: //Format xxxxxxxxxx
	
				phonenum.value = num;
	
				break;
	
		}

}

return true;
}	


function IsNumeric(sText,Label)
{

   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;
      }
   }
   if(!IsNumber)
   	alert(Label+ " Must Be numeric")
   return IsNumber;
}
function isUrl(s) {
	var regexp = /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;
 	return regexp.test(s);
}
function IsValidURL(strURL,n)
{
	strURL 		= strURL.toUpperCase();
			
	if(strURL==""||strURL=="HTTP://") return false	
	thePrefix 	= strURL.substr(0,7).toUpperCase();
	if(thePrefix!="HTTP://") return false;
	if(n!=-1) if(strURL.split("/").length>n) return false;
	
	return true
}
var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
	input.value = input.value.slice(0, len);
	input.form[(getIndex(input)+1) % input.form.length].focus();
}

function containsElement(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length)
	if(arr[index] == ele)
	found = true;
	else
	index++;
	return found;
}

function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
		if (input.form[i] == input)index = i;
		else i++;
		return index;
	}
	return true;
}

var ShowLinkAlbum = function()	{
		$("Link").style.visibility	= "visible";
		$("Link").style.position	= "relative";
		$("LinkTitle").style.visibility	= "hidden";
		$("LinkTitle").style.position	= "absolute";
	}
	
var HideLink = function()	{
		$("Link").style.visibility	= "hidden";
		$("Link").style.position	= "absolute";
		$("LinkTitle").style.visibility	= "visible";
		$("LinkTitle").style.position	= "relative";

	}
/*_______________________________________________________________________________________________________________________________ */

function ShiftPage(Page,Display)	{
	document.forms[document.forms.length-1].Page.value=Page;
	document.forms[document.forms.length-1].Display.value=Display;
	document.forms[document.forms.length-1].submit();
}

function UIShiftPage(Page,Display)	{
	document.forms[document.forms.length-1].Page.value=Page;
	document.forms[document.forms.length-1].Display.value=Display;
	document.forms[document.forms.length-1].submit();
}
// Trim function

var whitespace=new String(' \t\n\r\f');

function trimL(s){
	if(whitespace.indexOf(s.charAt(0))!=-1) {
		var j=0,i=s.length;
		while(j<i&&whitespace.indexOf(s.charAt(j))!=-1)
			j++;
			s=s.substring(j,i);
		}
		return s;
	}
	function trimR(s) {
		if(whitespace.indexOf(s.charAt(s.length-1))!=-1) {
			var i=s.length-1;
			while(i>=0&&whitespace.indexOf(s.charAt(i))!=-1)
				i--;
				s=s.substring(0,i+1);
		}
	return s;
}

function trim(s) {
	return trimR(trimL(s));
}


function stripSlashes(str)
{
return str.replace(/\\/g, '');
}

function IsFloatNumber(sText,Label,sField)
{
	if(sText==""){
		return false;
	}
   var ValidChars = "0123456789.";
   var IsNumberValue = true;
   var Char;
   sText = trim(sText);
   //if(sText=="" && !sField) {alert(Label+ " Should not be Empty");return false}
   for (i = 0; i < sText.length && IsNumberValue == true; i++) 
   { 
      Char = sText.charAt(i); 
      if(ValidChars.indexOf(Char) == -1) 
      {
         IsNumberValue = false;
      }
   }

   return IsNumberValue;
}

function isCreditCard(st) {
  // Encoding only works on cards with less than 19 digits
  if (st.length > 19)
    return (false);

  sum = 0; mul = 1; l = st.length;
  for (i = 0; i < l; i++) {
    digit = st.substring(l-i-1,l-i);
    tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }
// Uncomment the following line to help create credit card numbers
// 1. Create a dummy number with a 0 as the last digit
// 2. Examine the sum written out
// 3. Replace the last digit with the difference between the sum and
//    the next multiple of 10.

//  document.writeln("<BR>Sum      = ",sum,"<BR>");
//  alert("Sum      = " + sum);

  if ((sum % 10) == 0)
    return (true);
  else
    return (false);

} // END FUNCTION isCreditCard()

/*  ================================================================
    FUNCTION:  isVisa()
 
    INPUT:     cc - a string representing a credit card number

    RETURNS:  true, if the credit card number is a valid VISA number.
		    
	      false, otherwise

    Sample number: 4111 1111 1111 1111 (16 digits)
    ================================================================ */

function isVisa(cc)
{
  if (((cc.length == 16) || (cc.length == 13)) && (cc.substring(0,1) == 4))
    return isCreditCard(cc);
  return false;
}  // END FUNCTION isVisa()




/*  ================================================================
    FUNCTION:  isMasterCard()
 
    INPUT:     cc - a string representing a credit card number

    RETURNS:  true, if the credit card number is a valid MasterCard
		    number.
		    
	      false, otherwise

    Sample number: 5500 0000 0000 0004 (16 digits)
    ================================================================ */

function isMasterCard(cc)
{
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 16) && (firstdig == 5) &&
      ((seconddig >= 1) && (seconddig <= 5)))
    return isCreditCard(cc);
  return false;

} // END FUNCTION isMasterCard()





/*  ================================================================
    FUNCTION:  isAmericanExpress()
 
    INPUT:     cc - a string representing a credit card number

    RETURNS:  true, if the credit card number is a valid American
		    Express number.
		    
	      false, otherwise

    Sample number: 340000000000009 (15 digits)
    ================================================================ */

function isAmericanExpress(cc)
{
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 15) && (firstdig == 3) &&
      ((seconddig == 4) || (seconddig == 7)))
    return isCreditCard(cc);
  return false;

} // END FUNCTION isAmericanExpress()



/*  ================================================================
    FUNCTION:  isDiscover()
 
    INPUT:     cc - a string representing a credit card number

    RETURNS:  true, if the credit card number is a valid Discover
		    card number.
		    
	      false, otherwise

    Sample number: 6011000000000004 (16 digits)
    ================================================================ */

function isDiscover(cc)
{
  first4digs = cc.substring(0,4);
  if ((cc.length == 16) && (first4digs == "6011"))
    return isCreditCard(cc);
  return false;

} // END FUNCTION isDiscover()

function formvalidation(value,id,type) {
	if(type == '') {
		if(value == '') {
			if(document.getElementById("error_"+id))
				document.getElementById("error_"+id).style.display 	= "block";
			document.getElementById(id+"_img").innerHTML 	= "<img src='images/icon_error.gif' align='top' />";
		} else {
			if(document.getElementById("error_"+id))
				document.getElementById("error_"+id).style.display 	= "none";
			document.getElementById(id+"_img").innerHTML 	= "<img src='images/icon_ok.gif' align='top' />";
		}
	}
	if(type == 'email') {
		if(!isEmailAddr1(value)) {
			if(document.getElementById("error_"+id)) {
				document.getElementById("error_"+id).style.display 	= "block";
				document.getElementById("error_"+id).innerHTML 	= "Please eneter a valid email address.";
			}
			document.getElementById(id+"_img").innerHTML 	= "<img src='images/icon_error.gif' align='top' />";
		} else {
			if(document.getElementById("error_"+id))
				document.getElementById("error_"+id).style.display 	= "none";
			document.getElementById(id+"_img").innerHTML 	= "<img src='images/icon_ok.gif' align='top' />";
		}
	}
	if(type == 'number') {
		if(value == '') {
			if(document.getElementById("error_"+id))
				document.getElementById("error_"+id).style.display 	= "block";
			document.getElementById(id+"_img").innerHTML 	= "<img src='images/icon_error.gif' align='top' />";
		} else {
			if(document.getElementById("error_"+id))
				document.getElementById("error_"+id).style.display 	= "none";
			document.getElementById(id+"_img").innerHTML 	= "<img src='images/icon_ok.gif' align='top' />";
		}
		if(!IsVaildNumber(value)) {
			if(document.getElementById("error_"+id)) {
				document.getElementById("error_"+id).style.display 	= "block";
				document.getElementById("error_"+id).innerHTML 	= "Please eneter a valid email address.";
			}
			document.getElementById(id+"_img").innerHTML 	= "<img src='images/icon_error.gif' align='top' />";
		} else {
			if(document.getElementById("error_"+id))
				document.getElementById("error_"+id).style.display 	= "none";
			document.getElementById(id+"_img").innerHTML 	= "<img src='images/icon_ok.gif' align='top' />";
		}
	}
	if(type == 'phone') {
		if(!IsValidPhone(value)) {
			if(document.getElementById("error_"+id)) {
				document.getElementById("error_"+id).style.display 	= "block";
				document.getElementById("error_"+id).innerHTML 	= "Please eneter a valid email address.";
			}
			document.getElementById(id+"_img").innerHTML 	= "<img src='images/icon_error.gif' align='top' />";
		} else {
			if(document.getElementById("error_"+id))
				document.getElementById("error_"+id).style.display 	= "none";
			document.getElementById(id+"_img").innerHTML 	= "<img src='images/icon_ok.gif' align='top' />";
		}
	}
	if(type == 'checkbox') {
		if(document.getElementById(value).checked == false) {
			if(document.getElementById("error_"+id))
				document.getElementById("error_"+id).style.display 	= "block";
			document.getElementById(id+"_img").innerHTML 	= "<img src='images/icon_error.gif' align='top' />";
		} else {
			if(document.getElementById("error_"+id))
				document.getElementById("error_"+id).style.display 	= "none";
			document.getElementById(id+"_img").innerHTML 	= "<img src='images/icon_ok.gif' align='top' />";
		}
	}
}

function ShowProgressbar(showflag) {
	if(parseFloat(showflag) == 1) {
		if(document.getElementById('loading1')) {
			document.getElementById('loading1').style.display = 'block';
		}
		document.getElementById('loading').style.display = 'block';
	} else {
		if(document.getElementById('loading1')) {
			document.getElementById('loading1').style.display = 'none';
		}
		document.getElementById('loading').style.display = 'none';
	}
}

