	//This file contains the functions for input data validation
	//at client side with the help of java script.
	
	function trim(inputString) 
	{
	   inputString=inputString.replace(/^\s+/g,"");
	   inputString=inputString.replace(/\s+$/g,"");
	   return inputString;
	} // Ends the "trim" function
	
	//  this function checks the given string is empty or not
	//  and return true or false accordingly.
	function is_empty(str)
	{
  		 str=trim(str);
		 if ((str.length==0)||(str==null))
			return true;
		 return false;
	}
	// End of is_empty Function

	
	//  this function checks the email format is correct or not
	//  and return true or false accordingly.
	function is_email(email)
	{
		if(!email.match(/^[A-Za-z0-9\._\-+]+@[A-Za-z0-9_\-+]+(\.[A-Za-z0-9_\-+]+)+$/))
			return false;
		return true;
	}
	// End of is_email Function

	//  this function checks the given number is signed/unsigned number
	//  and return true or false accordingly.
	function is_number(number)
	{
		if(!number.match(/^[\-\+0-9e1-9]+$/))
			return false;
		return true;
	}
	// End of is_number Function
	
	//  this function checks the given value is string
	//  and return true or false accordingly.
	function is_alpha(number)
	{
		if(!number.match(/^[a-zA-Z ]+$/))
			return false;
		return true;
	}
	// End of is_number Function

	// function used for phone number validation
	function is_validPhone(number)
	{
		if(!number.match(/^[0-9-]+$/))
			return false;
		return true;
	}
	
	// function used for phone number validation
	function is_validPhone1(number)
	{
		if(!number.match(/^[0-9-()+]+$/))
			return false;
		return true;
	}
	
	
	// for valid zip code
	// function used for phone number validation
	function is_validZip(number)
	{
		if(!number.match(/^[0-9]+$/))
			return false;
		return true;
	}


	function is_validCost(number)
	{
		if(!number.match(/^[0-9.]+$/))
			return false;
		return true;
	}

	
	/**
	*	Validate URL
	*	@added by : Alok Kumar
	*	@date : 02-May-2007
	*	@param : Field's docoument Id
	*/
	function validateURL(fld) { 
		
		// Replace "\" with "/" in Tag URL
		fld.value = fld.value.replace(/\\/g,"/");	
		
		var v = new RegExp(); 
		v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$"); 
		
		if (!v.test(fld.value)) { 			
			return false; 
		} 
		
		return true;
	} 
	
	/**
	*	Validate URL
	*	@added by : Alok Kumar
	*	@date : 12-July-2007
	*	@param : Field's docoument Id
	*	@description: check url as "http://" and "www.augme.com" 
	*/
	function validateURLbyPart(fld) { 	
		url = fld.value;		
				
		if(url.search(' ') != -1){
			alert('Space is not allowed in the website address.');
			return false;
		}		
		else if(url.lastIndexOf('http://') > 0){
			alert("There should be only single \"http://\" in a Tag URL.");
			return false;
		}
		
		
		// Replace "\" with "/" in Tag URL
		fld.value = url = url.replace(/\\/g,"/");
		
		// Find last postion of "/" in Tag URL
		lsIndex  = url.lastIndexOf("/");
		
		// if "/" found in the url
		/*if(lsIndex>0){		
			urlfirst = url.substr(0,lsIndex+1);
			if(!is_empty(urlfirst)){
				if(urlfirst != "http://"){
					alert("Please enter \"http://\" correctly for the website address.");
					return false;
				}
			}		
		}
		else{
			// Find last postion of "/" in Tag URL
			lsIndex  = url.lastIndexOf("http");
			
			//if "http" is in url but missing "//" then alert the user
			if(lsIndex>=0){
				alert("Please enter \"http://\" correctly for the website address.");
				return false;
			}
		}*/
		
		return true;				
	} 



//  this function checks the given number is unsigned number
//  and return true or false accordingly.
	function is_unsign_number(number)
	{
		if(!number.match(/^[\+0-9]+$/))
			return false;
		return true;
	}
	function is_double(number)
	{
		if(!number.match(/^[0-9]*\.?[0-9]*$/))
			return false;
		return true;
	}
// End of is_unsign_number Function
	
//  this function checks the given string is alphanumeric word or not
//  and return true or false accordingly.
	function is_alpha_numeric(str)
	{
		if(!str.match(/^[A-Za-z0-9 ]+$/))
			return false;
		return true;
	}
// End of is_alpha_numeric Function
	
	/**
	*	Validate Username 
	*	@added by : Alok Kumar
	*	@date : 15-May-2007
	*/
	
   	function is_username(e)
	{
		var evtobj=window.event? event : e //distinguish between IE's explicit event object (window.event) and Firefox's implicit.
		var unicode=evtobj.charCode? evtobj.charCode : evtobj.keyCode
		
		flag = false;
		//alert(unicode);
		//@ 		: 64 
		//ENTER KEY : 13
		
		if (unicode!=13 && unicode!=8  && unicode!=9 &&  unicode != 16 && unicode != 17 && unicode != 116 && unicode != 46 && unicode != 95){ 
			if (unicode<48||unicode>57 ){ //if not a number 0-9
				if(unicode >57){
					if(unicode<65||unicode>90){		 // A- Z and @			
						if(unicode >90){
							if(unicode<97||unicode>122){ //a-z						
								flag = true;
							}
						}
						else{
							flag = true;
						}					
					}											
				}
				else{
					flag = true;
				}				
			}
		}

		if(flag){
			alert("Please enter letter(a-z), numeric(0-9), dot(.) or underscore(_) only.");
			return false //disable key press
		}
					
		return true;
	}
	
	
	
	/**
	*	Check if First character is not Albhabets
	*/
	function checkFirstChar(fld){
			
		fld.value = trim(fld.value);
		str = fld.value;
		
		if(!is_empty(str)){	
			chr = str.charAt(0);
			if(!chr.match(/^[a-zA-Z ]+$/)){
				alert("First character should be letter(a-z) only.");
				fld.value = "";
				return false;
			}
		}
	}
	
	
	//Limit number of characters allowed
	function limitlength(obj, length){
		var maxlength=length
		if (obj.value.length>maxlength)
			obj.value=obj.value.substring(0, maxlength)
	}

	
	

	// date format validation
	function dateValidate(str) {
		var regStr = /^\d{4,4}-\d{1,2}-\d{1,2}$/; 
		if(str.match(regStr)) {
			return true;     
		} else {
			return false;
		}
	}
	
	

	function convertDate(d,dateformat)
	{
		if(dateformat==null)
			dateformat='dd-mm-yyyy';

		if(dateformat.match(/^dd[-\/]{1}mm[-\/]{1}yyyy$/i))
		{
			var T = d.split(/[-\/]/);
			var M = T[1];
			var D = T[0];
			var	Y = T[2];
		}
		else if(dateformat.match(/^yyyy[-\/]{1}mm[-\/]{1}dd$/i))
		{
			var T = d.split(/[-\/]/);
			var M = T[1];
			var D = T[2];
			var	Y = T[0];
		}
		else
			return d;

		return (M+"-"+D+"-"+Y);
	}

	function is_date(d,dateformat)
	{
		if(dateformat==null)
			dateformat='dd-mm-yyyy';

		if(!dateformat.match(/^mm[-\/]{1}dd[-\/]{1}yyyy$/i))
			d=convertDate(d,dateformat);

		if(d.search(/^(\d){1,2}[-\/\\](\d){1,2}[-\/\\]\d{4}$/)!=0)
			return -1;//Bad Date Format
		
		var T = d.split(/[-\/]/);
		var M = eval(T[0]);
		var D = T[1];
		var	Y = T[2];
	
		return D>0 && (D<=[,31,28,31,30,31,30,31,31,30,31,30,31][M] ||	D==29 && Y%4==0 && (Y%100!=0 || Y%400==0) ) 
	}
	
	/**
	*	@author 	: Alok Kumar
	*	@created on : 03-04-07
	*   @purpose	: to validate date field on "onChange" action
	*/
	function is_date1(fld,dateformat,msg)
	{
		d = fld.value;
		
		if(dateformat==null)
			dateformat='dd-mm-yyyy';

		if(!dateformat.match(/^mm[-\/]{1}dd[-\/]{1}yyyy$/i))
			d=convertDate(d,dateformat);

		if(d.search(/^(\d){1,2}[-\/\\](\d){1,2}[-\/\\]\d{4}$/)!=0){		
			alert(msg);
			fld.value="";			
			fld.focus();
			return false;						
		}
		
		var T = d.split(/[-\/]/);
		var M = eval(T[0]);
		var D = T[1];
		var	Y = T[2];
	
		return D>0 && (D<=[,31,28,31,30,31,30,31,31,30,31,30,31][M] ||	D==29 && Y%4==0 && (Y%100!=0 || Y%400==0) ) 
	}


	/// Usage : daetDiif(FirstDate,SecondDate,dateformat,returnas)
	/// returnas=null or 0 //Difrence will return in days
	/// returnas=null or 1 //Difrence will return in hours;
	/// returnas=null or 2 //Difrence will return in mins;
	/// returnas=null or 3 //Difrence will return in secs;
	/// returnas=null or 4 //Difrence will return in weeks;
	/// returnas=null or 5 //An array will return;


	function dateDiff(firstdate,secondate,dateformat,returnas)
	{
		date1 = new Date();
		date2 = new Date();
		diff  = new Date();
		
		firstdate=convertDate(firstdate);
		secondate=convertDate(secondate);

		if(is_date(firstdate,'mm-dd-yyyy')) 
		{ // Validates first date 
			date1temp = new Date(firstdate);
			date1.setTime(date1temp.getTime());
		}
		else
			return false; // otherwise exits

		if(is_date(secondate,'mm-dd-yyyy')) 
		{ // Validates second date 
			date2temp = new Date(secondate);
			date2.setTime(date2temp.getTime());
		}
		else
			return false; // otherwise exits

		// sets difference date to difference of first date and second date

		diff.setTime(date1.getTime() - date2.getTime());

		timediff = diff.getTime();
		
		if(returnas==null || returnas==0)
			return Math.floor(timediff / (1000 * 60 * 60 * 24)); 
		else if(returnas==1)
			return Math.floor(timediff / (1000 * 60 * 60)); 
		else if(returnas==2)
			return Math.floor(timediff / (1000 * 60)); 
		else if(returnas==3)
			return Math.floor(timediff / 1000); 
		else if(returnas==4)
			return Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
		else if(returnas==5)
		{
			weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
			timediff -= weeks * (1000 * 60 * 60 * 24 * 7);

			days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
			timediff -= days * (1000 * 60 * 60 * 24);

			hours = Math.floor(timediff / (1000 * 60 * 60)); 
			timediff -= hours * (1000 * 60 * 60);

			mins = Math.floor(timediff / (1000 * 60)); 
			timediff -= mins * (1000 * 60);

			secs = Math.floor(timediff / 1000); 
			timediff -= secs * 1000;

			retval=new Array(weeks,days,hours,mins,secs);

			return retval; // form should never submit, returns false
		}
	}

	function isPastDate(firstdate,secondate,dateformat)
	{

		diff=dateDiff(firstdate,secondate);
		
		if(diff<0)
			return true;
		return false;
	}

	function isValidCreditCard(type, ccnum) 
	{
	   if (type == "Visa" || type == "VI") {
		  // Visa: length 16, prefix 4, dashes optional.
		  var re = /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/;
	   } else if (type == "MasterCard" || type == "MC") {
		  // Mastercard: length 16, prefix 51-55, dashes optional.
		  var re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/;
	   } else if (type == "Discover"  || type == "NO") {
		  // Discover: length 16, prefix 6011, dashes optional.
		  var re = /^6011-?\d{4}-?\d{4}-?\d{4}$/;
	   } else if (type == "AmEx" || type == "AX") {
		  // American Express: length 15, prefix 34 or 37.
		  var re = /^3[4,7]\d{13}$/;
	   } else if (type == "Diners") {
		  // Diners: length 14, prefix 30, 36, or 38.
		  var re = /^3[0,6,8]\d{12}$/;
	   } else if (type == "Bankcard") {
		  // Bankcard: length 16, prefix 5610 dashes optional.
		  var re = /^5610-?\d{4}-?\d{4}-?\d{4}$/;
	   } else if (type == "JCB") {
		  // Bankcard: length 16, prefix 5610 dashes optional.
		  var re = /^[3088|3096|3112|3158|3337|3528]\d{12}$/;
	   } else if (type == "EnRoute") {
		  // Bankcard: length 15, prefix 5610 dashes optional.
		  var re = /^[2014|2149]\d{11}$/;
	   } else if (type == "Switch") {
		  // Bankcard: length 16, prefix 5610 dashes optional.
		  var re = /^[4903|4911|4936|5641|6333|6759|6334|6767]\d{12}$/;
	   }

	   if (!re.test(ccnum)) return false;
	   // Checksum ("Mod 10")
	   // Add even digits in even length strings or odd digits in odd length strings.
	   var checksum = 0;
	   for (var i=(2-(ccnum.length % 2)); i<=ccnum.length; i+=2) {
		  checksum += parseInt(ccnum.charAt(i-1));
	   }
	   // Analyze odd digits in even length strings or even digits in odd length strings.
	   for (var i=(ccnum.length % 2) + 1; i<ccnum.length; i+=2) {
		  var digit = parseInt(ccnum.charAt(i-1)) * 2;
		  if (digit < 10) { checksum += digit; } else { checksum += (digit-9); }
	   }
	   if ((checksum % 10) == 0) return true; else return false;
	}

	//Checks the phone number like (001)-330-330 OR 9992592892
	///Start Function
	function is_phone(varphone)
	{
		if(!varphone.match(/^(\(?[0-9]*[-#\*\s]*[0-9]+\)?)+$/))
			return false;
		return true
	}
	//End Function



	/**
	*	COOKIE SET AND GET
	*	@added by : Alok Kumar
	*	@date : 07/May/2007
	*/
	
	//  Following functions written by:  Bill Dortch, hIdaho Design <bdortch@hidaho.com>
	//  The following functions are released to the public domain.
	
	function FixCookieDate (date) {
	  var base = new Date(0);
	  var skew = base.getTime(); // dawn of (Unix) time - should be 0
	  if (skew > 0)  // Except on the Mac - ahead of its time
		date.setTime (date.getTime() - skew);
	}
	
	function getCookieVal (offset) {
	  var endstr = document.cookie.indexOf (";", offset);
	  if (endstr == -1)
		endstr = document.cookie.length;
	  return unescape(document.cookie.substring(offset, endstr));
	}
	
	function GetCookie (name) {
	  var arg = name + "=";
	  var alen = arg.length;
	  var clen = document.cookie.length;
	  var i = 0;
	  while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		  return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
	  }
	  return null;
	}
	
	function SetCookie (name, value) {
	  var argv = SetCookie.arguments;
	  var argc = SetCookie.arguments.length;
	  var expires = (argc > 2) ? argv[2] : null;
	  var path = (argc > 3) ? argv[3] : null;
	  var domain = (argc > 4) ? argv[4] : null;
	  var secure = (argc > 5) ? argv[5] : false;
	  if (expires!=null) FixCookieDate(expires); //*** Uncomment this line for automatic date correction (see above)
	  document.cookie = name + "=" + escape (value) +
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
	}
	
	//  Following functions written by:  Martin Beaudoin, University of Alberta <mbeaudoi@gpu.srv.ualberta.ca>
	//  The following functions are released to the public domain.
	
	
	function MakeCookieLastFileVisited (){        //records the location of last file visited in site
		var expdate = new Date ();
		addr = document.location;
		expdate.setTime (expdate.getTime() + (1000 * 24 * 60 * 60 * 1000)); // 1000 days from now (mod Mac bug)
		SetCookie ("derniere", addr, expdate, "/");
	}
	// end script -->
	
	/**
	*	Open Pop-up Window
	*	url : page name
	*	properties : no toolbar : no menu bar
	*/
	function popupwin(url,height,width) {
		testwindow= window.open(url,"mywindow",   "height="+height+",width="+width+",status=no,scrollbars=yes,toolbar=no,menubar=no,location=no");
	}
	
	
	function redirectpage(pagelink){
	 setTimeout('getredirect()',5000);	
	}


function getredirect(){
	
	var pagelink=document.getElementById("pgurl").value;
	window.location.href=pagelink;
	
	}
	
