// JavaScript Document

function trim(inputString) 
{
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   
   while (ch == " ") { 
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { 
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { 
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); 
   }
   return retValue;
}

function doSomething(e)
{
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		posx = e.clientX + document.body.scrollLeft;
		posy = e.clientY + document.body.scrollTop;
	}
	alert(posx)
	alert(posy)
}



// Remove leading spaces and carriage returns AND Remove trailing spaces and carriage returns
function PreTrim(s) 
{
  // Remove leading spaces and carriage returns
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns
  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}
		
//check name
function checkname(sText)
{
    var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ. ";
    var IsNumber=true;
    var Char;
	if(sText.length==0)	
	{
	  return 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 checdetails(sText)
{
    var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890(). ";
    var IsNumber=true;
    var Char;
	if(sText.length==0)	
	{
	  return false;
	}
	else
	{
    for (i = 0; i < sText.length && IsNumber == true; i++) 
    { 
        Char = sText.charAt(i); 
        if (ValidChars.indexOf(Char) == -1) 
        {
            IsNumber = false;
        }
    }  
    return IsNumber;
   }	
}

//check filename
function checkFilename(sText)
{
    var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-1234567890.'`() ";
    var IsNumber=true;
    var Char;
	if(sText.length==0)	
	{
	  return false;
	}
	else
	{
    for (i = 0; i < sText.length && IsNumber == true; i++) 
    { 
        Char = sText.charAt(i); 
        if (ValidChars.indexOf(Char) == -1) 
        {
            IsNumber = false;
        }
    }  
    return IsNumber;
   }	
}

//check date
function checkdate(sText)
{
    var ValidChars = "0123456789/";
    var IsNumber=true;
    var Char;
	if(sText.length==0)	
	{
	  return false;
	}
	else
	{
    for (i = 0; i < sText.length && IsNumber == true; i++) 
    { 
        Char = sText.charAt(i); 
        if (ValidChars.indexOf(Char) == -1) 
        {
            IsNumber = false;
        }
    }  
    return IsNumber;
   }	
}
//check name
function checkcity(sText)
{
    var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ() ";
	
    var IsNumber=true;
    var Char;
	if(sText.length==0)	
	{
	  return 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 checksalutation(sText)
{
    var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    var IsNumber=true;
    var Char;
	if(sText.length==0)	
	{
	  return 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 checknormal(sText)
{
    var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    var IsNumber=true;
    var Char;
	if(sText.length==0)	
	{
	  return 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 checkbloodgroup(sText)
{
    var ValidChars = "aborhAHBOR+- ";
    var IsNumber=true;
    var Char;
	if(sText.length==0)	
	{
	  return 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 checkExtension(sText)
{
 arr=sText.split(".");
  
 if(arr[arr.length-1]=="doc" || arr[arr.length-1]=="pdf")
  return true;
  else
  return false;
  
}	
//check imageExtension

function checkimageExtension(sText)
{
 arr=sText.split(".");
  
 if(arr[arr.length-1]=="jpg" || arr[arr.length-1]=="jpeg" || arr[arr.length-1]=="gif" || arr[arr.length-1]=="png" || arr[arr.length-1]=="JPEG" || arr[arr.length-1]=="JPG")
  return true;
  else
  return false;
  
}	

//check Address
function checkadd(sText)
{
    var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789.#@-,;:/*_%$!&()'`+";
	return inValidCharSet(sText,ValidChars)
}
//check URL

function checkurl(sText)
{
    var ValidChars = ":abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789.\\/_-";
	return inValidCharSet(sText,ValidChars);	
}
function allDigits(str)
{
	return inValidCharSet(str,"0123456789");
}

function inValidCharSet(str,charset)
{
	var result = true;
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0){
			result = false;
			break;
		}
	return result;
}


function inValidCharZip(str)
{
	charset="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
	
		return inValidCharSet(str,charset);
	
}

function checktechskills(str)
{
	charset="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+-_.# "
	
		return inValidCharSet(str,charset);
	
}
function checkPwd(str)
{
	charset="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,._-()~!@#$%^&*_+\|?/><:;"
	
		return inValidCharSet(str,charset);
}

// Validate Username and password
function checkAuthentication(str)
{

	charset="0123456789@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"
	//charset="0123456789@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,._-()¡¢¤¦§¨ª«¬®¯°±²³µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñóõö÷øúûüýþ:;|<>"
	return inValidCharSet(str,charset);
}


function checkAlphaNum(str)
{
	charset="0123456789 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,._-()"
	
		return inValidCharSet(str,charset);
	
}
function checkcategory(str)
{
	charset="0123456789 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,._-()\|?/&:'`~%"
	return inValidCharSet(str,charset);
}
function checkSalutation(str)
{
	charset="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ."
	
		return inValidCharSet(str,charset);
	
}

function isValidExpDate(formField,fieldLabel,required)
{
	var result = true;
	var formValue = formField;

 	if (result && (formField.length>0))
 	{
 		var elems = formValue.split("/");
 		
 		result = (elems.length == 2); // should be two components
 		var expired = false;
 		
 		if (result)
 		{
 			var month = parseInt(elems[0],10);
 			var year = parseInt(elems[1],10);
 			
 			if (elems[1].length == 2)
 				year += 2000;
 			
 			var now = new Date();
 			
 			var nowMonth = now.getMonth() + 1;
 			var nowYear = now.getFullYear();
 			
 			expired = (nowYear > year) || ((nowYear == year ) && (nowMonth > month));
 			
			result = allDigits(elems[0]) && (month > 0) && (month < 13) &&
					 allDigits(elems[1]) && ((elems[1].length == 2) || (elems[1].length == 4));
 		}
 		
  		if (!result)
 		{
 			alert('Enter The "' + fieldLabel +'" field.');
			document.mycart.expmonth.focus();
			result = false;
		}
		else if (expired)
		{
 			result = false;
 			alert('The Date For "' + fieldLabel +'" Has Expired');
			document.mycart.expmonth.focus();
		}
	} 
	return result;
}

function checkCC(s) {
  var i, n, c, r, t;
  // First, reverse the string and remove any non-numeric characters.
  r = "";
  for (i = 0; i < s.length; i++) {
    c = parseInt(s.charAt(i), 10);
    if (c >= 0 && c <= 9)
     {
      r = c + r;
     }
    else
	 {
	   return false;
	 }	  
  }
  // Check for a bad string.
  if (r.length <= 1)
    return false;

  // Now run through each single digit to create a new string. Even digits
  // are multiplied by two, odd digits are left alone.
  t = "";
  for (i = 0; i < r.length; i++) {
    c = parseInt(r.charAt(i), 10);
    if (i % 2 != 0)
      c *= 2;
    t = t + c;
  }
  // Finally, add up all the single digits in this string.
  n = 0;
  for (i = 0; i < t.length; i++) {
    c = parseInt(t.charAt(i), 10);
    n = n + c;
  }
  // If the resulting sum is an even multiple of ten (but not zero), the
  // card number is good.
  if (n != 0 && n % 10 == 0)
    return true;
  else
    return false;
}
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 isChar(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 true;
    }
    // All characters are numbers.
    return false;
}

function isFloat(s)
{
	var i;
	var cnt;
	cnt=0;
	if (s.length==0) return false;
    for (i = 0; i <= s.length; i++)
    {   
        // Check if current character is '.' and count its occurances
        var c = s.charAt(i);
        if (c==".") cnt++;
		if (cnt > 1) return false;
		//break;
    }
    return inValidCharSet(s,"0123456789.");
}

function stripCharsInBag(s, bag)
{
    var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}




function middletrim(inputString)
{
	Spacing=true
	for(i=0;i<inputString.length;i++)
	{
		if(i>0)
		{
		if(i!=inputString.length-1)
		{
			if(inputString.charAt(i)==" ") 
			{
				Spacing=false;
				i=inputString.length
			}
		}
		}

	}
	
	return Spacing;
}




function checkInternationalPhone(strPhone)
{
	var digits = "0123456789";
	var phoneNumberDelimiters = "-";
	var validWorldPhoneChars = phoneNumberDelimiters;
	// Minimum no of digits in an international phone no.
	var minDigitsInIPhoneNumber = 10;
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length == minDigitsInIPhoneNumber);
}

function checkPhone(strPhone)
{
	var digits = "0123456789-,/+EXTextnaNAsioSIO(). ";
	var phoneNumberDelimiters = "-";
	var phoneNumberDelimiters1 = "+";
	var validPhoneChars = phoneNumberDelimiters;
	var validPhoneChars1 = phoneNumberDelimiters1;
	s=stripCharsInBag(strPhone,validPhoneChars);
	s=stripCharsInBag(s,validPhoneChars1);
	//return (isInteger(s));
	return inValidCharSet(strPhone,digits)
}
function checkMobile(strPhone)
{
/*	var digits = "0123456789+-()";
	var phoneNumberDelimiters1 = "+";
	var validPhoneChars1 = phoneNumberDelimiters1;
	s=stripCharsInBag(strPhone,validPhoneChars1);
	return (isInteger(s));
*/	
	var digits = "0123456789-,+()";
	var phoneNumberDelimiters = "-";
	var phoneNumberDelimiters1 = "+";
	var validPhoneChars = phoneNumberDelimiters;
	var validPhoneChars1 = phoneNumberDelimiters1;
	s=stripCharsInBag(strPhone,validPhoneChars);
	s=stripCharsInBag(s,validPhoneChars1);
	//return (isInteger(s));
	return inValidCharSet(strPhone,digits)

}

function checkEmailAddress(strEmail)
{
	var atcnt, dotcnt;
	atcnt=0;
	dotcnt=0;
	//alert(strEmail);
	if (strEmail.length==0) return false;
    for (i = 0; i < strEmail.length; i++)
	    {   
	        // Check if current character is '@' and count its occurances
	        var c = strEmail.charAt(i);
	        if (c=="@") atcnt++;
			if (c==".") dotcnt++;
			if (atcnt > 1) return false;
	    }
	if (atcnt == 0) return false;
	if (dotcnt == 0) return false;
	if ((strEmail.indexOf("@")==0) || (strEmail.indexOf(".")==0)) return false;
	if ((strEmail.indexOf("@")==strEmail.length-1) || (strEmail.indexOf(".")==strEmail.length-1)) return false;
	if ((strEmail.indexOf("@.")>=0) || (strEmail.indexOf(".@")>=0)) return false;
	return inValidCharSet(strEmail,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@.0123456789_-");
}
function validatePassword(strpwd){
	for (i = 0; i < strpwd.length; i++)
	    {   
	        // Check the current character
	        var c = strpwd.charAt(i);
	        if ((c=="\"")||(c=="-")||(c=="/")||(c=="\"")||(c=="'")||(c==" ")||(c=="=")) return false;
	    }
	return true;
}
function checkprojname(projName){
	return inValidCharSet(projName,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789_-");
}
function isfutureDate(strDate)
{
	var d = new Date();
	var dateStr;
	dateStr = d.getDate() + "/" + (d.getMonth() + 1) + "/" + d.getFullYear()
	tempArr = strDate.split("/")
	strDate = tempArr[1] + "/" + tempArr[0] + "/" + tempArr[2]
	dtArr = strDate.split("/");
	if (dtArr[1].length<2) dtArr[1]="0"+dtArr[1];
	if (dtArr[0].length<2) dtArr[0]="0"+dtArr[0];
	if (d.getFullYear()>dtArr[2]) return false;
	else if (d.getFullYear()==dtArr[2]){
		 if ((d.getMonth()+1)>dtArr[1]) return false;
		 else if ((d.getMonth()+1)==dtArr[1]){	
		 	if (d.getDate()>=dtArr[0]) return false;
		}
	}
	return true;
}
function isfutureDateA(strDate)
{
	var d = new Date();
	var dateStr;
	dateStr = d.getDate() + "/" + (d.getMonth() + 1) + "/" + d.getFullYear()
	tempArr = strDate.split("/")
	strDate = tempArr[1] + "/" + tempArr[0] + "/" + tempArr[2]
	dtArr = strDate.split("/");
	if (dtArr[1].length<2) dtArr[1]="0"+dtArr[1];
	if (dtArr[0].length<2) dtArr[0]="0"+dtArr[0];
	if (d.getFullYear()>dtArr[2]) return false;
	else if (d.getFullYear()==dtArr[2]){
		 if ((d.getMonth()+1)>dtArr[1]) return false;
		 else if ((d.getMonth()+1)==dtArr[1]){	
		 	if (d.getDate()<dtArr[0]) return false;
		}
	}
	return true;
}
function isgreaterDate(strDate1,strDate2)
{
	var dateStrArr;
	dateStrArr = strDate1.split("/");
	dtArr = strDate2.split("/");
	if (parseInt(dateStrArr[2])>parseInt(dtArr[2])) {return false;}
	else if (parseInt(dateStrArr[2])==parseInt(dtArr[2])){
		if (dateStrArr[0]=="08") dateStrArr[0]="8"
		if (dtArr[0]=="09") dtArr[0]="9"
		 if ((parseInt(dateStrArr[0])>parseInt(dtArr[0]))) {return false;}
		 else if (parseInt(dateStrArr[0])==parseInt(dtArr[0])){
		 	//if (dateStrArr[1]=="08") dateStrArr[1]="8"
			//if (dtArr[1]=="09") dtArr[1]="9"
		 	if (parseInt(dateStrArr[1])>parseInt(dtArr[1])) {return false;}
		}
	}
	return true;
}
function islessDate(strDate1,strDate2)
{

	var dateStrArr,tempArr;
	dateStrArr = strDate1.split("/");
	dtArr = strDate2.split("/");
	if (parseFloat(dateStrArr[2])<parseFloat(dtArr[2])) return false;
	else if (parseFloat(dateStrArr[2])==parseFloat(dtArr[2])){
		 if (parseFloat(dateStrArr[1])<parseFloat(dtArr[1])) return false;
		 else if (parseFloat(dateStrArr[1])==parseFloat(dtArr[1])){
		 	//alert(parseFloat(dateStrArr[0]));
		 	if (parseFloat(dateStrArr[0])<parseFloat(dtArr[0])) return false;
		}
	}
	return true;
}
function isLeapYear(myYearStr){
	var isleap = false;
	if (myYearStr%4==0 && (myYearStr%100!=0 || myYearStr%400==0)){
		isleap = true;
	}
	return isleap;
}

function checkDate(dd,mm,yyyy) {
	if (dd.length<2) dd= "0"+dd;
	if (mm.length<2) mm= "0"+mm;
	if (dd=="08") dd="8"
	if (dd=="09") dd="9"
	var monthDays = 0;
	
	if (mm=="Jan") mm="01";
	else if (mm=="Feb") mm="02";
	else if (mm=="Mar") mm="03";
	else if (mm=="Apr") mm="04";
	else if (mm=="May") mm="05";
	else if (mm=="Jun") mm="06";
	else if (mm=="Jul") mm="07";
	else if (mm=="Aug") mm="08";
	else if (mm=="Sep") mm="09";
	else if (mm=="Oct") mm="10";
	else if (mm=="Nov") mm="11";
	else if (mm=="Dec") mm="12";
	
	if (((mm%2)==0) && (parseInt(mm)<8))	monthDays = 30;
	if (((mm%2)==1) && (parseInt(mm)<8)) monthDays = 31;
	if (((mm%2)==0) && (parseInt(mm)>=8)) monthDays = 31;
	if (((mm%2)==1) && (parseInt(mm)>=8)) monthDays = 30;

	if (monthDays<dd) return false;
	
	if (mm=="01") mm="Jan";
	else if (mm=="02") mm="Feb";
	else if (mm=="03") mm="Mar";
	else if (mm=="04") mm="Apr";
	else if (mm=="05") mm="May";
	else if (mm=="06") mm="Jun";
	else if (mm=="07") mm="Jul";
	else if (mm=="08") mm="Aug";
	else if (mm=="09") mm="Sep";
	else if (mm=="10") mm="Oct";
	else if (mm=="11") mm="Nov";
	else if (mm=="12") mm="Dec";
	
	var myDayStr = parseInt(dd)+1;
	var myMonthStr = mm;
	var myYearStr = yyyy;
	var myDateStr = myDayStr + ' ' + myMonthStr + ' ' + myYearStr;
	//alert(myDateStr)
	//Check for leap Year
	if (myMonthStr=="Feb"){
		if (((parseInt(myDayStr)-1)>29) ||((parseInt(myDayStr)-1)==29 && !isLeapYear(myYearStr))){
			//alert("This Month Does not have " + (myDayStr-1) + " Days.");
			return false;
		}
	}

	/* Using form values, create a new date object
	which looks like "Wed Jan 1 00:00:00 EST 1975". */

	var myDate = new Date( myDateStr );
	//alert(myDate)
	// Convert the date to a string so we can parse it.
	var myDate_string = myDate.toGMTString();
	/* Split the string at every space and put the values into an array so,
	using the previous example, the first element in the array is "Wed", the
	second element is "Jan", the third element is "1", etc. */
	//alert(myDate_string)
	var myDate_array = myDate_string.split( ' ' );
	
	/* If we entered "Feb 31, 1975" in the form, the "new Date()" function
	converts the value to "Mar 3, 1975". Therefore, we compare the month
	in the array with the month we entered into the form. If they match,
	then the date is valid, otherwise, the date is NOT valid. */
	//alert("myDate_array[2] = " + myDate_array[2]);
	//alert("myMonthStr = " + myMonthStr);
	if ( myDate_array[2] != myMonthStr ) {
	  return false;
	} 
	else {
	  return true;
	}	 
}
function checkfldrname(sText)
{
    var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789#@-;_.%$!&()+";
	return inValidCharSet(sText,ValidChars)
}
/*function isName(string) 
{
  if (string.search(/^(?:[ -~]{10,25}(?:$|(?:[\w!?.])\s))/) != -1)
	return true;
  else
	return false;
}*/
// Is Quote Involved
function isQuot(string)
{
	if (string.search(/^[^']*$/) != -1)
    	return true;
	else
	    return false;
}
function isDQuot(string)
{
	if (string.search(/^[^"]*$/) != -1)
    	return true;
	else
	    return false;
}
function isMonth(str)
{
  var MonthArr= new Array("January","February","March","April","May","June","July","August","September","October","November","December","january","february","march","april","may","june","july","august","september","october","november","december") 
  j=0
  for (i=0;i<24;i++)  
  {
    if (trim(str)==trim(MonthArr[i]))
	{
	  j=i+1
	  if (j>12)
	      j=j-12
	  if (j<10)
	     j="0"+j
	  return j;
	}
  }
  return j;
}

function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}

// Email Validation
function isEmail(string) 
{
  if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
	return true;
  else
	return false;
}
function iswebsite(string) 
{
  if (string.search(/^\w+((-\w+)|(\.\w+))+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
	return true;
  else
	return false;
}
function isExtension(string) 
{
  if (string.search(/^\w+((-\w+)|(\.\w+))+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
	return true;
  else
	return false;
}
//check date
function checkdate(sText)
{
	var ValidChars = "0123456789/";
    var IsNumber=true;
    var Char;
	if(sText.length==0)	
	{
	  return false;
	}
	else
	{
    for (i = 0; i < sText.length && IsNumber == true; i++) 
    { 
        Char = sText.charAt(i); 
        if (ValidChars.indexOf(Char) == -1) 
        {
            IsNumber = false;
        }
    }  
    return IsNumber;
   }	
}

// Validate Date
function datevalidate(day,month,year)
 	   {
	          if(year<1900)  
			  {
			   return false
			  }
			 
	          if(parseInt(month)>12 || parseInt(month)<1)
			  {
			    return false;
			  }
	     	  if(month=="02"|| month=="2"||month=="04" || month=="4"||month=="06" || month=="6"||month=="09" || month=="9"||month=="11")
			  {   
			      if(month=="02" || month=="2")
			      {
				  
			          if(year%4==0)
				       {  
				             if(day<=29 && day>0)
					          {} 
					    	  else
							  {
								return false;
									
							   }
					   }			
  					   else
					   {
					         if(day<=28 && day>0)
					   		 {}    
					         else
				              {
								return false;
									
							   }
				       }
					 
		   		  }
				  else
				       if(day<=30 && day>0)
					   {}   
					   else
						{   
									return false;
									
							   }
				    
		 	   }
			   else
			   {
		           if(day<=31 && day>0)
				   {}   
			       else
					 		{  
									return false;
									
							   }
				  	      
			    } 
			    return true
           } 
		   
		   
//Function to Validate Fields & Email in the Form.

/*
function validateText(type)
{
	// Only Alphabets 
	if (type=="A")
	{
		// If the keycode of the pressed key is not in the required range then return false.
		if ((event.keyCode < 65 || event.keyCode > 90) &&(event.keyCode < 97 || event.keyCode > 122))
		event.returnValue = false;
	}
	// Only Alphabets along with . and /
	if (type=="AL")
	{
		// If the keycode of the pressed key is not in the required range then return false.
		if ((event.keyCode < 65 || event.keyCode > 90)&&(event.keyCode < 97 || event.keyCode > 122)&&(event.keyCode!=46)&&(event.keyCode!=32)&&(event.keyCode!=47)) 
		event.returnValue = false;
	}
	// Only Alphabets along with . and / and @
	else if (type=="WEB")
	{
		// If the keycode of the pressed key is not in the required range then return false.
		if ((event.keyCode < 65 || event.keyCode > 90)&&(event.keyCode < 97 || event.keyCode > 122)&&(event.keyCode!=46)&&(event.keyCode!=32)&&(event.keyCode!=47)&&(event.keyCode!=64)) 
		event.returnValue = false;
	}

	// Only numbers
	else if(type=="N")
	{
		// If the keycode of the pressed key is not in the required range then return false.
		if (event.keyCode < 48 || event.keyCode > 57)
		event.returnValue = false;
	}
	// All the characters without " and '
	else if(type=="AN")
	{
		// If the keycode of the pressed key is not in the required range then return false.
		if (event.keyCode==34 || event.keyCode==39) 
		event.returnValue = false;
	}
		// Only Alphabets 
	if (type=="NAME")
	{
		// If the keycode of the pressed key is not in the required range then return false.
		if ((event.keyCode < 65 || event.keyCode > 90) &&(event.keyCode < 97 || event.keyCode > 122) && 
			(event.keyCode != 32 ) && (event.keyCode != 46 ))
		event.returnValue = false;
	}

	// It allows numbers and -
	else if(type=="PHNO")
	{			
		// If the keycode of the pressed key is not in the required range then return false.
		if ((event.keyCode < 48 || event.keyCode >57 )&& (event.keyCode != 45 ))
			event.returnValue = false;			
	}	

	// Only Alphabets ,Numbers, @ and .
	if (type=="EMAIL")
	{
		// If the keycode of the pressed key is not in the required range then return false.
		if ((event.keyCode < 65 || event.keyCode > 90) && (event.keyCode < 97 || event.keyCode > 122) && 
			(event.keyCode < 48 || event.keyCode > 57) && (event.keyCode != 64 ) && (event.keyCode != 46 ))
		event.returnValue = false;
	}

	// Only Alphabets ,Numbers, @ and .
	if (type=="URL")
	{
		// If the keycode of the pressed key is not in the required range then return false.
		if ((event.keyCode < 65 || event.keyCode > 90) && (event.keyCode < 97 || event.keyCode > 122) && 
			(event.keyCode < 48 || event.keyCode > 57) && (event.keyCode != 46 ) && (event.keyCode != 58 ) && (event.keyCode != 47 ))
		event.returnValue = false;
	}
				
	// It allows numbers and .
	else if(type=="MONEY")
	{			
		// If the keycode of the pressed key is not in the required range then return false.
		if ((event.keyCode < 48 || event.keyCode > 57) && (event.keyCode != 46 ) && (event.keyCode != 44))
			event.returnValue = false;			
	}				
	// It allows numbers and /
	else if(type=="DATE")
	{			
		// If the keycode of the pressed key is not in the required range then return false.
		if ((event.keyCode < 48 || event.keyCode > 57 ) && (event.keyCode != 47 ))
			event.returnValue = false;			
	}
	// It allows numbers and :
	else if(type=="TIME")
	{			
		// If the keycode of the pressed key is not in the required range then return false.
		if ((event.keyCode < 48 || event.keyCode > 57 ) && (event.keyCode != 58 ))
			event.returnValue = false;
	}

	// It allows albhbets and numbers				
	else if (type=="PAN")
	{
		// If the keycode of the pressed key is not in the required range then return false.
		if ((event.keyCode < 65 || event.keyCode > 90)&&(event.keyCode < 97 || event.keyCode > 122)&&(event.keyCode < 48 || event.keyCode > 57))
		event.returnValue = false;
	}
	// It allows all the characers without < and >
	else if (type=="PROFILE")
	{
		// If the keycode of the pressed key is not in the required range then return false.
		if ((event.keyCode == 62 )||( event.keyCode == 60)||(event.keyCode==34) ||( event.keyCode==39))
		event.returnValue = false;
	}	
// acepts only letters numbers or .
	else if (type=="RESULT")
	{
		if ((event.keyCode < 65 || event.keyCode > 90) && (event.keyCode < 97 || event.keyCode > 122) && 
		(event.keyCode < 48 || event.keyCode > 57) && (event.keyCode != 46 )&& (event.keyCode != 32 ))
//		&& (event.keyCode != 64 ) 
		event.returnValue = false;
	}	
// Aplphabets and numbers.... e.g. Exam numbers which includes aplhabets and numbers
	else if(type=="ALPHANM")   // or PAN
	{
		if ((event.keyCode < 65 || event.keyCode > 90) && (event.keyCode < 97 || event.keyCode > 122) && 
			(event.keyCode < 48 || event.keyCode > 57)) 
			event.returnValue = false;
	}
// Accepts only aplphabets , numbers and spaces. _-,
	else if (type=="TITLE")
	{
		// If the keycode of the pressed key is not in the required range then return false.
		if ((event.keyCode < 65 || event.keyCode > 90)&&(event.keyCode < 97 || event.keyCode > 122)&&
		(event.keyCode < 48 || event.keyCode > 57)&& (event.keyCode != 32) && (event.keyCode != 95) && (event.keyCode != 45) && (event.keyCode != 44))
		event.returnValue = false;
	}
	else if (type=="CHARS")
	{
		// If the keycode of the pressed key is not in the required range then return false.
		if ((event.keyCode < 65 || event.keyCode > 90)&&(event.keyCode < 97 || event.keyCode > 122))
		event.returnValue = false;
	}
	
	
}
*/


function checkDOB(startDate)
{
  form=document.entryFrm
  //alert("vijay")
  endarr=endDate.split("/")
  endDate=endarr[1]+"/"+endarr[0]+"/"+endarr[2] 
  var sDate = new Date(startDate);
  var eDate = new Date(endDate);
  //alert(sDate)
  if (sDate >eDate)
  {
   alert(" Start Date Should Not Less Than  Current Date.")
    return false
  }
 }
 
function DateCompare(startDate,endDate)
{
  form=document.entryFrm
  var sDate = new Date(startDate);
  var eDate = new Date(endDate);
  if (sDate >eDate)
  {
    return false
  }
  return true
 }


function  valueadd()
{
    form=document.candidateFrm
	form.incTxt.value= Number(form.psalTxt.value) + Number(form.incbyTxt.value)
    form.dateTxt.focus()
}

function checkName1(sText)//Crested By : Balwant Raj . Date : 21-01-2009
{
    var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&-_. ";
    var IsNumber=true;
    var Char;
	if(sText.length==0)	
	{
	  return false;
	}
	else
	{
    for (i = 0; i < sText.length && IsNumber == true; i++) 
    { 
        Char = sText.charAt(i); 
        if (ValidChars.indexOf(Char) == -1) 
        {
            IsNumber = false;
        }
    }  
    return IsNumber;
   }	
}

