var alphabet = "abcdefghijklmnopqrstuvwxyz";
var numeric  = "0123456789";

	 
function referal()
{
	  if(  document.getElementById('success_referal'))
	  document.getElementById('success_referal').innerHTML="Successfully mail has been sent";
}

function hidesuccess()
{
	   if(document.getElementById('success_referal'))
	  document.getElementById('success_referal').innerHTML="";
}
	 
	  

function IsDateinPast_Today(dtStr,Label,element)
{
	if(IsDate(dtStr,Label,element))
	{
		today=new Date();
		indate=new Date();
		dtStr=trim(dtStr);
		if(dtStr!="")
		{
			dateArr=dtStr.split("/");
			indate.setDate(dateArr[0]); indate.setMonth(dateArr[1]-1); indate.setFullYear(dateArr[2]);
			if(indate<today)
			{
				alert("Invalid "+Label+"\n"+Label+" must be in the Today or in Future");
				element.focus();
				element.select();
			}
		}
	}
}



function sendInvitation(ReferFrm)
{
	
	
	//document.getElementById('success').innerHTML="";
	
	if(!isEmail(ReferFrm.tomail.value,"Email"))
	{ 
	   
		document.getElementById('to').innerHTML="Invalid Email";
		ReferFrm.tomail.focus();
		return false;
	}
/*	if(ReferFrm.subject.value == "")
	{
		alert("Subject Field Cannot Be Empty");
		ReferFrm.subject.focus();
		return false;
	}*/
	
	    document.getElementById('to').innerHTML="";
		
	    
		
	   ReferFrm.getReferVal.value=1;
	   ReferFrm.action="friendreferral.php";
	   ReferFrm.submit();
	
}

function IsDate(dtStr,Label)
{
	var daysInMonth = DaysArray(12)
	var dtCh= "/";
    var minYear=1900;
    var maxYear=2100;
	var errmsg;
	var isDate=true;
	dtStr=trim(dtStr);
	if(dtStr!="")
	{
		var pos1=dtStr.indexOf(dtCh)
		var pos2=dtStr.indexOf(dtCh,pos1+1)
		var strMonth=dtStr.substring(pos1+1,pos2)
		var strDay=dtStr.substring(0,pos1)
		var strYear=dtStr.substring(pos2+1)
		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 (strYear.charAt(0)=="0" && strYr.length>1) strYear=strYear.substring(1)
		}
		month=parseInt(strMonth)
		day=parseInt(strDay)
		year=parseInt(strYear)
		if (pos1==-1 || pos2==-1) 
			{errmsg="Enter a valid Date for "+Label+"\nDate Format is mm/dd/yyyy";
			isDate=false;}
		if (strMonth.length<1 || month<1 || month>12)
			{errmsg="Enter a valid month between 1 and 12 for "+Label+"\nDate Format is mm/dd/yyyy";
			isDate=false;}
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
			{errmsg="Enter a valid date for "+Label+"\nDate Format is mm/dd/yyyy";
			 isDate=false;}	
		if (strYear.length != 4 || year==0 || year<minYear || year>maxYear)
		  {	errmsg="Enter a valid year between "+minYear+" and "+maxYear+" for "+Label+"\nDate Format is mm/dd/yyyy";  
			isDate=false;}
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr,dtCh))==false)
		   {errmsg="Enter a valid Date for "+Label+"\nDate Format is mm/dd/yyyy";
			isDate=false;}
		if(!isDate)
		{
		  alert(errmsg); 
		}
   	}
  	return isDate;	
}


function IsFutStartDate(sDate,eDate,Label)
{
	var d1 = eDate;
	DateArray = d1.split("/");
	
	var dd = sDate;
	var Dob = dd.split("/");
	//var CDate = dd.getDate();
	//var CMonth = dd.getMonth();
	//var CYear = dd.getFullYear();
	//var CMonth1 = CMonth+1;
	
	if(DateArray[2]<Dob[2]) 
	{
		return false;
	}
	if(DateArray[2]==Dob[2]) 
	{ 
		if(DateArray[1]<Dob[1])
		{
			return false;
		}
	
		if(DateArray[1]==Dob[1])
		{
			if(DateArray[0]<Dob[0])
			{
				return false;
			}
		}
		return true;
	}
	return true;
}

////////////////////////////////////////////////////////////Date Validation Script function END///////////////////////////////////////////////////
function IsChar(sText,Label)
{

   var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
   var IsChars=true;
   var Char;
   if(sText=="") {alert(Label+ " is required");return false}
   for (i = 0; i < sText.length && IsChars == true; i++) 
   { 
      Char = sText.charAt(i); 
      if(ValidChars.indexOf(Char) == -1) 
      {
		 IsChars = false;
      }
   }
   if(!IsChars)
   	alert(Label+ " Should Not Be numeric")
   return IsChars;
}

function IsValidText(sText,Label)
{
   var ValidChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
   var IsValidText=true;
   var Char;
   if(sText=="") {alert(Label+ " is required");return false}
   for (i = 0; i < sText.length && IsValidText == true; i++) 
   { 
      Char = sText.charAt(i).toUpperCase(); 
      if(ValidChars.indexOf(Char) == -1) 
      {
         IsValidText = false;
      }
   }
   if(!IsValidText)
   	alert(Label+ " Must Be Alpha Numeric")
   return IsValidText;
}

function IsValidCompany(sText,Label)
{
   var ValidChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ -',.";
   var IsValidText=true;
   var Char;
   if(sText=="") {alert(Label+ " is required");return false}
   for (i = 0; i < sText.length && IsValidText == true; i++) 
   { 
      Char = sText.charAt(i).toUpperCase(); 
      if(ValidChars.indexOf(Char) == -1) 
      {
         IsValidText = false;
      }
   }
   if(!IsValidText)
   	alert(Label+ " Invalid Characters found")
   return IsValidText;
}


function IsAddress(sText,Label)
{
   var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .1234567890-,#()'[]{}";
   var IsValidText=true;
   var Char;
   if(sText=="") {alert(Label+ " is required");return false}
   for (i = 0; i < sText.length && IsValidText == true; i++) 
   { 
      Char = sText.charAt(i).toUpperCase(); 
      if(ValidChars.indexOf(Char) == -1) 
      {
         IsValidText = false;
      }
   }
   if(!IsValidText)
   	alert(Label+ " Invalid Charactes found")
   return IsValidText;
}

function IsvalidCity(sText,Label)
{
   var ValidChars = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ-";
   var IsValidText=true;
   var Char;
   if(sText=="") {alert(Label+ " Should not be Empty");return false}
   for (i = 0; i < sText.length && IsValidText == true; i++) 
   { 
      Char = sText.charAt(i).toUpperCase(); 
      if(ValidChars.indexOf(Char) == -1) 
      {
         IsValidText = false;
      }
   }
   if(!IsValidText)
   	alert(Label+ " Invalid Charactes found")
   return IsValidText;
}

function IsAlphaAndNumeric(sText,Label)
{
	
	
	   var ValidChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz";
	   var IsAlphaAndNumeric=true;
	   var Char;
	   if(trim(sText)!=""){
		   if(sText=="") {alert(Label+ " Should not be Empty");return false}
		   sText = trim(sText)
		   for (i = 0; i < sText.length && IsAlphaAndNumeric == true; i++) 
		   { 
			  Char = sText.charAt(i).toUpperCase(); 
			  if(ValidChars.indexOf(Char) == -1) 
			  {
				 IsAlphaAndNumeric = false;
			  }
		   }
	   }
	   if(!IsAlphaAndNumeric)
		alert(Label+ " Must Be Alpha Numeric")
	   return IsAlphaAndNumeric;
	   
   
   
}

function IsValidURLhttp(strURL,n)
	{
		strURL 		= strURL.toUpperCase();		
		if(strURL==""||strURL=="HTTP://") {
			alert("Invalid URL");
			return false;	
		}	
		thePrefix 	= strURL.substr(0,7).toUpperCase();
		if(thePrefix!="HTTP://") {
			alert("Invalid URL");
			return false;					
		}	
		if(n!=-1) if(strURL.split("/").length>n) return false;		
		return true
	}
	
function IsValidURL(Val,Label)
{
	var inValidChars = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890-_:/.";
    for (i = 0; i < Val.length; i++){   
        var c = Val.charAt(i);
        if (inValidChars.indexOf(c) == -1 ){
			alert("Invalid characters found in "+Label);
			return false;
		}
    }
	var c,cnd,msg,len;
	c=0;
	cnd="http://";
	msg="Enter valid URL eg. 'http://www.msn.com'";
	len=7;
	if (Label=="web")
	{
		cnd="www";
		msg="Enter valid Website name eg. 'www.msn.com'";
		len=3;
	}
	if (Val.substring(0,len)!=cnd)
	{
		alert(msg);
		return false;
	}
	else
	{
		for (i=0;i<Val.length;i++)
		{
			if ((Val.charAt(i))==".")
				c=c+1;
		}
		
		if (c<2)
		{
				alert(msg);
				return false;
		}
	}
	return true;
}

function IsFax(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 in Format eg:229-230-4443 or (229) 230-4443 or 229.230.4443")
   return IsNumber;
}

function IsZipCode(sText,Label)
{
   var ValidChars = "0123456789-";
   var IsZip=true;
   var Char;
   if(sText=="") {alert(Label+ " Should not be Empty");return false}
   for (i = 0; i < sText.length && IsZip == true; i++) 
   { 
      Char = sText.charAt(i); 
      if(ValidChars.indexOf(Char) == -1) 
      {
         IsZip = false;
      }
   }
   if(!IsZip)
   	alert(Label+ " Must Be in Format 90001 or 90001-2345")
   return IsZip;
}

function isWhitespace(s)
{
	// 	Check if s is empty

//	if (isEmpty(s)) return true;	

	// Checks for whitespace. If there is atleast a non-whitespace character
	// the function will return false.

	var spaces = " \n\t\r"
	var i;
	for(i=0;i<s.length;++i)
		if (spaces.indexOf(s.charAt(i)) == -1) 
			return false;
	return true;
}

function IsPassword(sPass1,Lable)
{
	 
	if(trim(sPass1)=="")
	{
		alert(Lable +" Should Not be Empty")
		return false
	}
	else if(!IsValidText(sPass1, Lable))
    {
		//alert("Password should have combination of numbers and letters")
		return false
    }
	else if (sPass1.length < 5)
	{
		alert("Password must have atleast 5 Characters");
		return false
	}
	else if (sPass1.length > 10)
	{
		alert("Password must be of maximum 10 Characters");
		return false
	}
	else {
		return true;
	}
/*	if(sPass1!=sPass2)
	{
		alert("Password Mismatch")
		return false
	}
	IsFound = false
	for(i=0;i<objBlock.length && !IsFound ;i++)
	{
		reg = new RegExp(objBlock[i])
		if(sPass1.match(reg))
		{
			IsFound = true
		}
	}
	if(IsFound)
	{
		alert("Password should not have "+strLabel)
		return false
	}*/
	
}

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

function IsValidAmount(sText,Label)
{
	if(!IsAmount(sText))
	{
		alert("Invalid "+Label+".. "+Label+" should be numeric")
		return false;
	}
	AmtArray = sText.split(".")
	if(AmtArray.length>2)
	{
		alert("Invalid "+Label+".. "+Label+" should have single period for float")
		return false;
	}
	if(AmtArray.length>1)
	{
		FloatAmt = AmtArray[1];
		if(FloatAmt.length>2)
		{
			alert("Invalid "+Label+"..  Float value shpould have two digits")
			return false;
		}
	}
	return true
}

function IsFloat(sText,Label)
{
	if(!IsAmount(sText))
	{
		alert("Invalid "+Label+".. "+Label+" should be numeric")
		return false;
	}
	AmtArray = sText.split(".")
	if(AmtArray.length>2)
	{
		alert("Invalid "+Label+".. "+Label+" should have single period for float")
		return false;
	}
	return true
}



function isEmail(s)
{
	var i = 1,Length = s.length,result;
	
	if(s==""){
		
		//alert("Your email address is required");
		return false;
	}
	
	while((i<Length) && (s.charAt(i) != '@')) i++;
	
	if ((i == Length) || (s.charAt(i) != '@'))
	{

	//alert("You are missing the '@' in your email address");
		return false;
	}
	
	i+=2;
	
	while((i<Length) && (s.charAt(i) != '.')) i++;

	if ((i == Length) || (s.charAt(i) != '.'))
	{
		//alert("You are missing the '.' in your email address.");
		return false;
	}

	if (i+1 >= Length)
	{
		//alert("Email address should have atleast one character after . ");
		return false;
	}
	
	return true;
}

function isEmailAddr(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;
}

//This function checks the matching of Passwords.
function IsMatch(Val1,val2,Label)
{
	if(trim(Val1)!=trim(val2))
	{
		alert(Label+"  Should Match")
		return false
	}
	return true
}

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
}
function floatRound(number,X) {
	X = (!X ? 2 : X);
	return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s,Lable){
	if(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")))
		{
			alert(Lable+" Should be Numeric ")
		 	return false;
		}
    }
    // All characters are numbers.
	}
	else
	{
		return true;
	}	
    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 isDate(dtStr,Label){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	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+"\nDate Format is mm/dd/yyyy")
		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+"\nDate Format is mm/dd/yyyy")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear+" for "+Label+"\nDate Format is mm/dd/yyyy")
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date for "+Label+"\nDate Format is mm/dd/yyyy")
		return false
	}
return true
}

function IsValidTime(timeStr) {
// Checks if time is in HH:MM:SS AM/PM format.
// The seconds and AM/PM are optional.

var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;

var matchArray = timeStr.match(timePat);
if (matchArray == null) {
alert("Time is not in a valid format.");
return false;
}
hour = matchArray[1];
minute = matchArray[2];
second = matchArray[4];
ampm = matchArray[6];

if (second=="") { second = null; }
if (ampm=="") { ampm = null }

if (hour < 0  || hour > 23) {
alert("Hour must be between 1 and 12. (or 0 and 23 for military time)");
return false;
}
if (hour <= 12 && ampm == null) {
if (confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time")) {
alert("You must specify AM or PM.");
return false;
   }
}
if  (hour > 12 && ampm != null) {
alert("You can't specify AM or PM for military time.");
return false;
}
if (minute<0 || minute > 59) {
alert ("Minute must be between 0 and 59.");
return false;
}
if (second != null && (second < 0 || second > 59)) {
alert ("Second must be between 0 and 59.");
return false;
}
return false;
}

function EditPopup(theURL)
{
	
	ScreenWidth  = screen.width
	ScreenHeight = screen.height
	PopupWidth   =ScreenWidth/1
	PopupHeight  = ScreenHeight/1.25
	PopupLeft    = (ScreenWidth-PopupWidth)/2
	PopupTop     = (ScreenHeight-PopupHeight)/2
	//PopupTop     = 10
	theURL = theURL
	MM_openPopupWindow(theURL,'PopupWindow','maximize=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width='+PopupWidth+',height='+PopupHeight+',left='+PopupLeft+',top='+PopupTop);				
}
	
	function MM_openPopupWindow(theURL,winName,features) 
	{ 
		var hWnd =   window.open(theURL,winName,features);
		if ((document.window != null) && (!hWnd.opener))
			hWnd.opener = document.window;
	}
		
	function isLogin(s)
	{
		if (s.length < 5)
		{
			alert("min. length of Login ID is 5");
			return false;
		}
	
		if (!isValidwithBag(s,alphabet + numeric + "-._"))
	
		{
			alert("Login ID should contain only the characters from alphabet, numbers and '-._'");
			return false;
		}
		if (!isValidwithBag(s.charAt(s.length-1),alphabet + numeric))
		{
			alert("Login ID should end with an alphanumeric characters.");
			return false;
		}
		if (!isValidwithBag(s.charAt(0),alphabet + numeric))
		{
			alert("Login ID should start with an alphanumeric characters.");
			return false;
		}
		return true;
	}
	


	function isValidwithBag(name,Bag)
	{
		var i;
		name = name.toLowerCase();
		for(i=0;i<name.length;++i)
			if (Bag.indexOf(name.charAt(i)) == -1) 
				return false;
		return true;
	}		

	function isEmpty(s)
	{
		// if the string is null or having the length of zero
		// the function will return true
		return((s==null) || (s.length==0));
	}

	function isWhitespace(s)
	{
		// 	Check if s is empty
	
		if (isEmpty(s)) return true;	
	
		// Checks for whitespace. If there is atleast a non-whitespace character
		// the function will return false.
	
		var spaces = " \n\t\r"
		var i;
		for(i=0;i<s.length;++i)
			if (spaces.indexOf(s.charAt(i)) == -1) 
				return false;
		return true;
	}
	
	 function DateDiff(obj2,obj1)
	 {
		// obj2 is Date object
		// obj1 is the text object having the date value
		// will return + value if obj2 < obj1
		// will return - value if obj2 > obj1
		// will return 0 if both are equal.
			alert(obj2);
			alert(obj1);
			var cal1 = obj1.value;
			var Date1;
			var calMode = 0;
	
			if (cal1.length == 10)
			{
				if(calMode == 0)
				{
					Day1 = cal1.substr(3,2)
					Month1 = cal1.substr(0,2);
				}
				else
				{
					Day1 = cal1.substr(0,2)
					Month1 = cal1.substr(3,2);
				}
				Year1 = cal1.substr(6,4);
	
				Date1 = new Date(Year1,Month1-1,Day1);
	
				return (Date1 - obj2);
			}
	
	 }

	function isYear(valu)
	{ 
		var ret=true;
		year = new Date();
		var currentyearvalue = year.getYear();
		var oper=currentyearvalue-18;
		var yearval=valu;
	
		if((yearval <1900)||(yearval>oper))
			{ 
			ret=false;
			   return ret;
			}
			return ret;
	}


function DisableRightClick(ie) {
	var warning = "Copy or Paste not allowed!  Please Key in the required data!";
	if (navigator.appName == 'Netscape' && ie.which == 3) {
		alert(warning);
		return false;
	}	else if (navigator.appName == 'Microsoft Internet Explorer' &&
		event.button==2) {
		alert(warning);
		return false;
	}
	return true;
}
function keyWhat(e){
   if (navigator.appName == 'Microsoft Internet Explorer'){
                 //For shift, ctrl and alt keys
     if(event.keyCode == 17 || event.keyCode == 45){ 
          alert("Copy or Paste not allowed!  Please Key in the required data!");
                     return false;
                 }
   }
}//end of function

