// JavaScript Document

	function ValImage(fname)
	{
	   var filename = fname;
	   var ext = getExt(filename);
	   if(ext == "jpg")
		  return true;
	   alert("Please upload JPG files only.");
	   return false;
	}
	
	function getExt(filename)
	{
	   var dot_pos = filename.lastIndexOf(".");
	   if(dot_pos == -1)
		  return "";
	   return filename.substr(dot_pos+1).toLowerCase();
	}

	function listboxItemSelected(oList1,oList2)
	{
		id="";
		if (oList2 != null)
		{	
			clearComboOrList(oList2);
			if (oList1.selectedIndex == -1)
			{	
				oList2.options[oList2.options.length] = new Option('All', '');
			} 
			else
			{
				//alert(oList1.name + '=' + oList1.options[oList1.selectedIndex].value)
				fillListbox(oList2, oList1.name + '=' + oList1.options[oList1.selectedIndex].value);
				//alert(getvalue(oList1,k));
			}
		}
	}
		
	function clearComboOrList(oList)
	{	
		for (var i = oList.options.length - 1; i >= 0; i--)
		{
			oList.options[i] = null;
		}
		oList.selectedIndex = -1;
		if (oList.onchange)	
			oList.onchange();
	}
		
	function fillListbox(oList, vValue)
	{
		if (vValue != '') {
			if (assocArray[vValue]){
			var arrX = assocArray[vValue];
			for (var i = 0; i < arrX.length; i = i + 2){
				if (arrX[i] != 'EOF') 
				{
					s1=arrX[i + 1];
					oList.options[oList.options.length] = new Option(s1.replace("&#39","'"), arrX[i]);
				}
			}
			//alert (oList.options.length)
			if (oList.options.length == 1){
			//oList.selectedIndex=0;
			if (oList.onchange)	oList.onchange();
			}
		} else {
			oList.options[0] = new Option('All', '');
		}
		}
	}


function formatDate(date,format) {

	format=format+"";
	var result="";
	var i_format=0;
	var c="";
	var token="";
	var y=date.getYear()+"";
	var M=date.getMonth()+1;
	var d=date.getDate();
	var E=date.getDay();
	var H=date.getHours();
	var m=date.getMinutes();
	var s=date.getSeconds();
	var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
	// Convert real date parts into formatted versions
	var value=new Object();
	if (y.length < 4) {y=""+(y-0+1900);}
	value["y"]=""+y;
	value["yyyy"]=y;
	value["yy"]=y.substring(2,4);
	value["M"]=M;
	value["MM"]=LZ(M);
	value["MMM"]=MONTH_NAMES[M-1];
	value["NNN"]=MONTH_NAMES[M+11];
	value["d"]=d;
	value["dd"]=LZ(d);
	value["E"]=DAY_NAMES[E+7];
	value["EE"]=DAY_NAMES[E];
	value["H"]=H;
	value["HH"]=LZ(H);
	if (H==0){value["h"]=12;}
	else if (H>12){value["h"]=H-12;}
	else {value["h"]=H;}
	value["hh"]=LZ(value["h"]);
	if (H>11){value["K"]=H-12;} else {value["K"]=H;}
	value["k"]=H+1;
	value["KK"]=LZ(value["K"]);
	value["kk"]=LZ(value["k"]);
	if (H > 11) { value["a"]="PM"; }
	else { value["a"]="AM"; }
	value["m"]=m;
	value["mm"]=LZ(m);
	value["s"]=s;
	value["ss"]=LZ(s);
	while (i_format < format.length) {
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		if (value[token] != null) { result=result + value[token]; }
		else { result=result + token; }
		}
	return result;
	}

function LTrim(str)
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

function RTrim(str)
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...
     var i = s.length - 1;       // Get length of string
      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}


function trim(str)
{
   return RTrim(LTrim(str));
}

function checkEmail(str) 
     {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

/*function checkEmail(oObject)
{	var emailStr=oObject;
		
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];

if (user.match(userPat)==null) {
   // alert("The username doesn't seem to be valid. Please check or register fresh");
    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 domainArray=domain.match(domainPat);
if (domainArray==null) {
	//alert("The domain name doesn't seem to be valid.");
    return false;
}
var atomPat=new RegExp(atom,"g");
var domArr=domain.match(atomPat);
var len=domArr.length;
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
  // alert("The address must end in a three-letter domain, or two letter country.");
   return false;
}

if (len<2) {
  // var errStr="This address is missing a hostname!";
   alert(errStr);
   return false;
}
return true;
} */
//end of email validation

function checkNum(str) 
{

	 for(i=0;i<str.length;i++) { 

		 c=str.charAt(i);

		  b=(((c >= "0") && (c <= "9")) || (c==" ") || (c=="(")|| (c==")")|| (c=="-") || (c=="/")|| (c==",")) 

		  if(b==true) 

		  continue; 

		  else 

		  return false; 

	  } 

	  return true; 

}

function DiffYD(S1, S2) {

//alert("in here")
  var D1 = ReadISO8601date(S1) ; 
  var D2 = ReadISO8601date(S2) ; 
  var DY = D1[0]-D2[0]
  if ( (D1[1]<D2[1]) || ( (D1[1]==D2[1]) && (D1[2]<D2[2] ) ) ) 
  		DY--
  D2[0] += DY
  return [ DY ] 
  }

//////////////////////////////////////////

//to find if the field contains alphabets only
function CheckAlpha(Text)
{
	var i=0;
	var ValidData="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._- ";
	
	var Data=Text.value;
	for(i=0;i<Data.length;i++)
	{
		if(ValidData.indexOf(Data.charAt(i))==-1)
		{
			//alert("Please enter Non-Numeric Data Only");
			Text.focus();
			return false;
		}
	}
   	return true;
}
	
//to check if the field contains both alphabets and numbers 
function CheckAlphaNumeric(Text)
{
	var i=0;
	var ValidData=". ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890/_- ";
	var Data=Text.value;
	
	for(i=0;i<Data.length;i++)
	{
		if(ValidData.indexOf(Data.charAt(i))==-1)
		{
			//alert("Invalid entry.\t\t");
			Text.focus();
			return false;
		}
	}
	return true;
}

function ToggleCheck(oChildCheck, sCtrlName, oMainCheck, oForm)
{
	if(!oChildCheck.checked) { // if un checked ONE
		oMainCheck.checked = false;
		return true;
	}		
				
	// CHECK TRUE 
	var IsCheckAll = true;			
	var len = oForm.elements.length;
	for (var i = 0; i < len; i++) {
		var e = oForm.elements[i];
		var sName = e.name;							
		if (sName.indexOf(sCtrlName, 0) != -1) {			
			if(!e.checked){
				IsCheckAll= false;
				break;
			}
		}
	}									
	oMainCheck.checked = IsCheckAll;			
}
	
function CheckAll(oForm, bCheck) // oFrom - Form object , bCheck - true or false
{
	var len = oForm.elements.length;
	for (var i = 0; i < len; i++) {
		var e = oForm.elements[i];
		var sName = e.name;		
		if (sName.indexOf("ChkOne",0) != -1) {			
			e.checked = bCheck;
		}
	}	
}	

function isPhoneNumber(field,fieldname)
 {
	var i=0;
	var ValidData="1234567890-( )+";
	var Data= field.value;
	
	for(i=0;i<Data.length;i++)
	{
		if(ValidData.indexOf(Data.charAt(i))==-1)
		{
			alert("Invalid Entry,Please Enter Only Valid Values For " + fieldname);
			field.focus();
			return false;
		 }
	}
	return false;
}

//URL Validataion
function check_weburl(fld) 
{
	var re = /^(?:(?:ftp|https?):\/\/)?(?:[a-z0-9](?:[-a-z0-9]*[a-z0-9])?\.)+(?:com|edu|biz|org|gov|int|info|mil|net|name|museum|coop|aero|[a-z][a-z])\b(?:\d+)?(?:\/[^;"'<>()\[\]{}\s\x7f-\xff]*(?:[.,?]+[^;'"<>()\[\]{}\s\x7f-\xff]+)*)?/;
	if (re.test(fld.value)){
		return true;
	}else{
		//alert ("Invalid Website - Please enter a valid Website");
		fld.focus();
		fld.select();
		return false;
	}
}