// start tool tip
     function showtip(current,e,num,pos)
        {
         if (document.layers) // Netscape 4.0+
            {
             theString="<DIV style='border:1px solid black;font-size:12px;layer-background-color:lightyellow;background-color:lightyellow'>"+ '<font face="<?=$sitefont?>, <?=$sitefont?>, Helvetica, sans-serif" size="1">'+num+'</font>' +"</DIV>"
             document.tooltip.document.write(theString)
             document.tooltip.document.close()
             document.tooltip.left=e.pageX
             document.tooltip.top=e.pageY+2
             document.tooltip.visibility="show"
            }
         else
           {
            if(document.getElementById) // Netscape 6.0+ and Internet Explorer 5.0+
              {

			   elm=document.getElementById("tooltip")
               elml=current
               //elm.style.color="white"
               //elm.style.background="white"
               elm.innerHTML='<font face="<?=$sitefont?>, <?=$sitefont?>, Helvetica, sans-serif" size="1">'+num+'</font>'
               elm.style.height=elml.style.height
               elm.style.left=parseInt(elml.offsetLeft+elml.offsetWidth+22)
               //elm.style.top=(elml.offsetParent.offsetTop+tab.offsetTop)-elm.offsetHeight+16; 
               elm.style.top=(elml.offsetParent.offsetTop+tab.offsetTop)+elml.offsetTop-5;
			   if (pos==0)
               {
					elm.style.top=(elml.offsetParent.offsetTop+tab.offsetTop)+(elm.offsetHeight*3+(elml.offsetTop*4));
               }

               if (pos==1)
               {
					elm.style.top=(elml.offsetParent.offsetTop+tab.offsetTop)+(elm.offsetHeight+(elml.offsetTop*2));
               }
               if (pos==2)
               {	
					elm.style.top=(elml.offsetParent.offsetTop+tab.offsetTop)-elm.offsetHeight; //parseInt(e.clientY); //(current.offsetHeight*2))//+(elml.offsetTop*4)));
               }
               
               elm.style.visibility = "visible"
               window.status=''
               return true;
              }
           }
        }
function hidetip(){
if (document.layers) // Netscape 4.0+
   {
    document.tooltip.visibility="hidden"
   }
else
  {
   if(document.getElementById) // Netscape 6.0+ and Internet Explorer 5.0+
     {
      elm.style.visibility="hidden"
     }
  } 
}

//end tool tip
// following function checks for blank spaces or Trims the string.
function isexpo(str)
{
	var strValue = new String(str)
	//Checks for exponensial values
	if (strValue.indexOf("e") >= 0 || strValue.indexOf("E") >= 0)
	{
		alert("Exponential values are not allowed");
		return true;
	}	
}

function TrimString(str)
	{
		var st=new String(str)
		stpos=0;
		strln=st.length;
		while(stpos<strln)
		{
			if(st.substr(stpos,1)!=' ')
			{
				break;
			}
			stpos=stpos+1;
		}
		
		edpos=strln-1;
		while(edpos>=stpos)
		{
			if(st.substr(edpos,1)!=' ')
			{
				break;
			}
			edpos=edpos-1;
		}
		var retst=st.substring(stpos,edpos+1);
		return retst;
	}
	

// count no. of characters in a textfield. 

function CharacterLimit(obj,limit)
{	
	var strTemp=String(obj.value)
	if(strTemp.length>limit)
	{
		return false;
	}
	else
		return true;
}


//following function restrict the user to enter more than Limit characters.

function StopUser(obj,limit) 
{
	
	var strTemp=String(obj.value)
	if(strTemp.length >= limit)
		return false;
}


function CheckDate(obj)
{
	var dateStr = new String(obj.value);
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
	var str
	var matchArray = dateStr.match(datePat); 

	if (matchArray == null) {
		alert(" Please enter the date in MM/DD/YYYY format");
		return false;
	}
	month = matchArray[1]; 
	day = matchArray[3];
	year = matchArray[4];
	
	str=new String(year)
	if (str.length < 4) 
	{
		alert(" Please enter the date in MM/DD/YYYY format");
		return false;
	}
	
	if (year < 1900)
		{
		alert("The year in the date cannot be less than 1900.");
		return false;
		}
	if (month < 1 || month > 12) { 
		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) { 
		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;
		}
	
	
	}
}


function emailCheck (emailStr) {
var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name contains invalid characters.");
return false;
   }
}


if (user.match(userPat)==null) {
alert("The username doesn't seem to be valid.");
return false;
}

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}


var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("The domain name does not seem to be valid.");
return false;
   }
}


if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}


if (len<2) {
alert("This address is missing a hostname!");
return false;
}


return true;
}




function ValidateAlphaNumeric(Expression)
{
	var objRegExp = /^[a-zA-Z0-9\s]+$/;
	var flag = Expression.match(objRegExp);
	
	if (flag == null)
		return false;
	else 
		return true;
}


// Fucntion for checking the Dates 
//**************************************************************************
function chkdate(objName) {
	var strDatestyle = "US"; //United States date style
	//var strDatestyle = "EU";  //European date style
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var datefield = objName;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var err = 0;
	var strMonthArray = new Array(12);
	strMonthArray[0] = "Jan";
	strMonthArray[1] = "Feb";
	strMonthArray[2] = "Mar";
	strMonthArray[3] = "Apr";
	strMonthArray[4] = "May";
	strMonthArray[5] = "Jun";
	strMonthArray[6] = "Jul";
	strMonthArray[7] = "Aug";
	strMonthArray[8] = "Sep";
	strMonthArray[9] = "Oct";
	strMonthArray[10] = "Nov";
	strMonthArray[11] = "Dec";
	strDate = datefield.value;

	//if (strDate.length < 1) {
	//	return true;
	//}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
		strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) {
				err = 1;
				return false;
			}
			else {
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
		}
	}
	if (booFound == false) {
		if (strDate.length>5) {
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
		}
	}
	if (strYear.length == 2) {
		strYear = '20' + strYear;
	}
	// US style
	if (strDatestyle == "US") {
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}
	intday = parseInt(strDay, 10);
	if (isNaN(intday)) {
		err = 2;
		return false;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) {
		for (i = 0;i<12;i++) {
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
			}
		}
		if (isNaN(intMonth)) {
			err = 3;
			return false;
		}
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) {
		err = 4;
		return false;
	}
	if (intMonth>12 || intMonth<1) {
		err = 5;
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
	err = 6;
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
	err = 7;
		return false;
	}
	if (intMonth == 2) {
		if (intday < 1) {
			err = 8;
			return false;
		}
		if (LeapYear(intYear) == true) {
			if (intday > 29) {
				err = 9;
				return false;
			}
		}
		else {
			if (intday > 28) {
				err = 10;
				return false;
			}
		}
	}
	if (strDatestyle == "US") {
		datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
	}
	else {
		datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
	}
	return true;
}

//***************************************************

// Function for checking the leap year
//**************************************************************	
function LeapYear(intYear) {
	if (intYear % 100 == 0) {
		if (intYear % 400 == 0) { return true; }
	}
	else {
		if ((intYear % 4) == 0) { return true; }
	}
	return false;
}

//************************************************************************

function CheckTime(obj)
{	
	var dateStr = new String(obj.value);
	var timePat = /^(\d{1,2})(\:)(\d{2})$/;
	var matchArray = dateStr.match(timePat); 
	if (matchArray == null) {
		alert("Invalid time format. Please specify it in 00:00 format only");
		return false;
	}
	hour = matchArray[1]; 
	min = matchArray[3];
	if (hour <= 0 || hour > 12) { 
		alert("Hours must be between 1 and 12");
		return false;
	}
	if (min < 0 || min > 59) {
	alert("Minutes must be between 0 and 59.");
	return false;
	}
}		



function CheckTimeAMPM(obj)
{	
	var dateStr = new String(obj.value);
	var timePat = /^(\d{1,2})(\:)(\d{2})(\:)(\d{2})(\s)([p|P|a|A])([m|M])$/;
	var matchArray = dateStr.match(timePat); 
	if (matchArray == null) {
		alert("Invalid time format. Please specify it in 00:00:00 AM/PM format only");
		return false;
	}
	hour = matchArray[1]; 
	min = matchArray[3];
	if (hour < 0 || hour > 12) { 
		alert("Hours must be between 0 and 12");
		return false;
	}
	if (min < 0 || min > 59) {
	alert("Minutes must be between 0 and 59.");
	return false;
	}
}		
function DateComp(sdt1,sdt2) {

	if (isDate(sdt1) && isDate(sdt2))
	{
	}
	else
	{
		return false; 
	}

	var day1 = sdt1.charAt(0) == "0" ? parseInt(sdt1.substring(1,2)) : parseInt(sdt1.substring(0,2));
	var month1 = sdt1.charAt(3) == "0" ? parseInt(sdt1.substring(4,5)) : parseInt(sdt1.substring(3,5));
	var begin1 = sdt1.charAt(6) == "0" ? (sdt1.charAt(7) == "0" ? (sdt1.charAt(8) == "0" ? 9 : 8) : 7) : 6;
	var year1 = parseInt(sdt1.substring(begin1, 10));
	var dt1 = new Date(year1,month1,day1)
	
	var day2 = sdt2.charAt(0) == "0" ? parseInt(sdt2.substring(1,2)) : parseInt(sdt2.substring(0,2));
	var month2 = sdt2.charAt(3) == "0" ? parseInt(sdt2.substring(4,5)) : parseInt(sdt2.substring(3,5));
	var begin2 = sdt2.charAt(6) == "0" ? (sdt2.charAt(7) == "0" ? (sdt2.charAt(8) == "0" ? 9 : 8) : 7) : 6;
	var year2 = parseInt(sdt2.substring(begin2, 10));
	var dt2 = new Date(year2,month2,day2)

	if (year1 > year2 ) 
	   return true;
	else
	{
	  if (year1==year2)
	  {
			if (month1 > month2)
			{
				return true;
			}
			else
			{
				if  (month1 == month2)
				{
					if (day1 > day2)
						return true;
					else
						return false ;
				}
				else
				{
					return false;
				}	
			}			
	  }
	  else
	  {
		return false ;
	   }	
	}	   
}

function DateCompDifferentFormat(sdt1,sdt2) 
{

//	if (CheckDate(sdt1) && CheckDate(sdt2))
//	{
//	}
//	else
//	{
//		return false; 
//	}

	var month1 = sdt1.charAt(0) == "0" ? parseInt(sdt1.substring(1,2)) : parseInt(sdt1.substring(0,2));
	var day1 = sdt1.charAt(3) == "0" ? parseInt(sdt1.substring(4,5)) : parseInt(sdt1.substring(3,5));
	var begin1 = sdt1.charAt(6) == "0" ? (sdt1.charAt(7) == "0" ? (sdt1.charAt(8) == "0" ? 9 : 8) : 7) : 6;
	var year1 = parseInt(sdt1.substring(begin1, 10));
	var dt1 = new Date(year1,month1,day1)
	
	var month2 = sdt2.charAt(0) == "0" ? parseInt(sdt2.substring(1,2)) : parseInt(sdt2.substring(0,2));
	var day2 = sdt2.charAt(3) == "0" ? parseInt(sdt2.substring(4,5)) : parseInt(sdt2.substring(3,5));
	var begin2 = sdt2.charAt(6) == "0" ? (sdt2.charAt(7) == "0" ? (sdt2.charAt(8) == "0" ? 9 : 8) : 7) : 6;
	var year2 = parseInt(sdt2.substring(begin2, 10));
	var dt2 = new Date(year2,month2,day2)

//alert("year1="+year1+"year2="+year2+"month1="+month1+"month2="+month2+"day1="+day1+"day2="+day2)
	if (year1 > year2 ) 
	   return true;
	else
	{
	  if (year1==year2)
	  {
			if (month1 > month2)
			{
				return true;
			}
			else
			{
				if  (month1 == month2)
				{
					if (day1 > day2)
						return true;
					else
						return false ;
				}
				else
				{
					return false;
				}	
			}			
	  }
	  else
	  {
		return false ;
	   }	
	}	   
}



function isDate(str) {
  if (str.length != 10) { return false }

  for (j=0; j<str.length; j++) {
   if ((j == 2) || (j == 5)) {
      if (str.charAt(j) != "/") { return false }
    } 
    else 
    {
      if ((str.charAt(j) < "0") || (str.charAt(j) > "9")) { return false }
    }
  }

  var day = str.charAt(0) == "0" ? parseInt(str.substring(1,2)) : parseInt(str.substring(0,2));
  var month = str.charAt(3) == "0" ? parseInt(str.substring(4,5)) : parseInt(str.substring(3,5));
  var begin = str.charAt(6) == "0" ? (str.charAt(7) == "0" ? (str.charAt(8) == "0" ? 9 : 8) : 7) : 6;
  var year = parseInt(str.substring(begin, 10));
  
  if (day == 0) { return false }
  if (month == 0 || month > 12) { return false }
  if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
    if (day > 31) 
    { 
     return false; 
    }
  } else {
    if (month == 4 || month == 6 || month == 9 || month == 11) {
      if (day > 30) { return false }
    } else {
      if (year%4 != 0) {
        if (day > 28) { return false }
      } else {
        if (day > 29) { return false }
      }
    }
  }
  return true;
}