/*variable naming conventions in js file
prefix js_ with each variable and functions, this indicates javascript variable and functions
prefix int with variable of integer type
prefix flt with variable of float type
prefix str with variable of string type
prefix obj with variable of object type
prefix chr with variable of character type
prefix bol with variable of bool type
prefix dat with variable of datetime
prefix arr with variable of array type
functions naming conventins in js file
prefix fn with each function
*/
//function to format the number for two decimal number
function js_fnFormat(strText)
{
	//parameter description
	//strText->text needs to be format
	
	var js_arrNum
	js_arrNum=strText.split(".")
	if(js_arrNum.length==1)
		js_arrNum[0]=js_arrNum[0] + "." + "00"
	else
	{
		if(js_arrNum[1].length==1)
			js_arrNum[0]=js_arrNum[0] + "." + js_arrNum[1] + "0"
		else if(js_arrNum[1].length==2)
			js_arrNum[0]=js_arrNum[0] + "." + js_arrNum[1]
	}	
	return js_arrNum[0]
}

//function used to trim the trialing and leading spaces and 
function js_fnTrim(strText)
{
	//parameter description
	//strText -> text which needs to be trim the spaces
	
	var js_intIndex,js_strLen;
	js_intIndex=0
	strText += "";
	if(strText== "undefined" || strText == null)
		return null;
	else if(strText.length == 0)
		strText = "";
	else
	{
		js_strLen= strText.length;
		//this loop will trim the left side spaces
		while ((js_intIndex <= js_strLen) && (strText.charAt(js_intIndex) == " "))
			js_intIndex++;
		strText = strText.substring(js_intIndex, js_strLen);
		if(strText.length>0)
		{
			//this loop will trim the right side spaces
			js_intIndex= strText.length - 1;
			while ((js_intIndex >= 0) && (strText.charAt(js_intIndex) == " "))
				js_intIndex--;
			strText = strText.substring(0, js_intIndex + 1);
		}
	}
	return strText
}
//function to select or deselect the check boxes
function js_fnSelDesel(objMainobject,objSubobject)
{
	//objMainobject->Main check box object name passsed it as object
	//objSubobject->name of the sub check boxes passed it as string 
	//eg.,  ->  js_fnSelDesel(document.forms[0].chkAll,'chkAdd')
	
	for (intIndex=0;intIndex<document.forms[0].elements.length;intIndex++)
	{
		if(document.forms[0].elements[intIndex].type=="checkbox" && document.forms[0].elements[intIndex].name==objSubobject)
			document.forms[0].elements[intIndex].checked=objMainobject.checked
	}
}

//function to trim the form objects(textboxes,textarea)
function js_fnTrimFormObjects()
{
	//This function will list all the objects in the form
	//if the objects are of type textbox and textarea then it will be trimmed
	for (intIndex=0;intIndex<document.forms[0].elements.length;intIndex++)
	{
		if(document.forms[0].elements[intIndex].type=="text" || document.forms[0].elements[intIndex].type=="textarea")
			document.forms[0].elements[intIndex].value=js_fnTrim(document.forms[0].elements[intIndex].value)
	}
}
//function user to validate the number
function js_fnValidateNum(objName,strMessage,intStrLen,intZeroYesNo,intNegYesNo,intDecYesNo,intManYesNo)
{
	//parameter description
	//objName->name of the object
	//strMessage->short message
	//intStrLen->minimum characters to be enter
	//intZeroYesNo->value zero is allowed to not
	//if intZeroYesNo=0 -> we can allw value of zero 
	//if intZeroYesNo=1 -> value should be greater than zero
	//intNegYesNo->negative numbers allowed or not
	//if intNegYesNo=0 -> negative numbers are allowed
	//if intNegYesNo=1 -> negative numbers are not allowed
	//intDecYesNo->decimal numbers allowed or not
	//intDecYesNo=0 -> decimal numbers are allowed
	//intDecYesNo=1 -> decimal numbers are allowed not allwed
	//intManYesNo->mandatory 
	//if intManYesNo=0 then it is mandatory
	//if intManYesNo=1 then it is optional
	if(objName.value=="" && intManYesNo==1)
		return true;
	else if(objName.value.length<intStrLen)
	{
		alert(strMessage+ " cannot be less than "+ intStrLen+ " characters");
		objName.focus();
		return false;
	}
	else if(isNaN(objName.value)==true)
	{
		alert(strMessage+"  is not a valid number");
		objName.focus();
		return false;
	}
	else if(intZeroYesNo==1 && parseFloat(objName.value)==0)
	{
		alert(strMessage+" cannot be zero");
		objName.focus();
		return false;
	}
	else if(intDecYesNo==1 && objName.value.indexOf(".")>-1)
	{
		alert("Decimal numbers not allowed");
		objName.focus();
		return false;
	}
	else if(intNegYesNo==1 && parseFloat(objName.value)<0)
	{
		alert("Negative numbers not allowed");
		objName.focus();
		return false;		
	}
	else if(objName.value.indexOf("+")>-1)
	{
		alert("+ sign is not allowed");
		objName.focus();
		return false;			
	}
	else if(objName.value.indexOf("e")>-1)
	{
		alert("e (exponential) is not allowed");
		objName.focus();
		return false;			
	}
	return true;
}
//function to validate the decimal numbers
//before calling this function call the fnValidateNum to validate the number
function js_fnDecimalNum(objName,strMessage,intIntPart,intDelpart)
{
	var ps_arrNumb
	ps_arrNumb=objName.value.split(".")
	if(ps_arrNumb[0].length>intIntPart)
	{
		alert("Integer part of " + strMessage + " cannot be more than " + intIntPart)
		objName.focus()
		return false
	}
	else if(ps_arrNumb.length>1 && ps_arrNumb[1].length>intDelpart)
	{
		alert("Decimal part of " + strMessage + " cannot be more than " + intDelpart)
		objName.focus()
		return false
	}
	return true;
}


//function to validate the alpha numeric
function js_fnValidateString(objName,strMessage,intManYesNo,intSplYesNo)
{
	//parameter description
	//objName->Name of the object
	//intManYesNo-> mandatory or optional
	//if intManYesNo=0-> mandatory
	//if intManYesNo=1->optional
	//intSplYesNo->special characters allowed or not
	//if intSplYesNo=0 -> special characters allowed
	//if intSplYesNo=1 -> special characters not allowed
	
	var js_strText,js_intIndex
	js_strText=objName.value
	js_strText=js_strText + ""
	if (js_strText == "undefined" || js_strText+"" == "null")
		return false;
	if(intManYesNo==1 && js_strText=="")
		return true;
	else if(intManYesNo==0 && js_strText=="")
	{
		alert(strMessage + " cannot be blank")
		objName.focus();
		return false;
	}
    else
	{
		for (js_intIndex = 0; js_intIndex < js_strText.length; js_intIndex++)
		{
			if(intSplYesNo==1)
			{
				if (!( ((js_strText.charAt(js_intIndex) >= "0") && (js_strText.charAt(js_intIndex) <= "9")) || (js_strText.charAt(js_intIndex) == "_") ||
						((js_strText.charAt(js_intIndex) >= "a") && (js_strText.charAt(js_intIndex) <= "z")) ||
						((js_strText.charAt(js_intIndex) >= "A") && (js_strText.charAt(js_intIndex) <= "Z"))
						) )
					{
						alert("Only alphanumeric characters are allowed")
						objName.focus();
						return false;
					}
			}
			else
			{
				if(js_strText.charAt(js_intIndex)=="'" || js_strText.charAt(js_intIndex)=="\"")
				{
					alert("Single and double quotes are not allowed")
					objName.focus();
					return false;
				}
			}
		}
	}
	 return true;
}


//function to validate the email address
function js_fnEmail(objName,intManYesNo)
{
	//parameter description
	//objName -> name of the object
	//if intManYesNo=0-> mandatory
	//if intManYesNo=1->optional

	if(objName.value=="" && intManYesNo==1)
		return true;
	else if(objName.value=="" && intManYesNo==0)
	{
		alert("Enter a valid email")
		objName.focus()
		return false;
	}
	else
	{
		var js_intIndex,js_chrText,js_bolDot,js_bolAt,js_intAtPos,js_intDotPos
		js_bolDot = "false";
		js_bolAt = "false";
		js_intAtPos=0;
		js_intDotPos=0;
		for(js_intIndex=0;js_intIndex<objName.value.length; js_intIndex++)
		{
			js_chrText=objName.value.charAt(js_intIndex)
			if(js_chrText==" ")
			{
				alert("Spaces not allowed")
				objName.focus()
				return false;
			}
			else if(js_chrText=="'" || js_chrText=="\"")
			{
				alert("Single and Double quotes are not allowed")
				objName.focus()
				return false;
			}
			else if(js_intIndex==0 && (js_chrText == "@" || js_chrText == "."))
			{
				alert("Invalid email")
				objName.focus()
				return false;
			}
			else if (js_intIndex!=0 && js_chrText == "@")
			{
				js_intAtPos=js_intIndex
				js_bolAt="true"
			}
			else if (js_intIndex!=0 && js_chrText == ".")
			{
				js_intDotPos=js_intIndex
				js_bolDot="true"
			}

		}
		if(objName.value.length<8 || js_bolAt!="true" || js_bolDot!="true" || (parseFloat(js_intDotPos)-parseFloat(js_intAtPos+1))<3 || (parseFloat(objName.value.length)-parseFloat(js_intDotPos+1))<1)
		{
			alert("Invalid email")
			objName.focus()
			return false;
		}	
		return true;
	}
}


//function to replace space with plus sign
function js_fnReplaceSpace(strText)
{
	var js_intIndex=0;
	var js_charText,strText1
	strText1=""
	if(strText.length==0 || strText =="null")
		return "";
	else
	{
		for(js_intIndex=0;js_intIndex<strText.length;js_intIndex++)
		{
			js_charText = strText.substring(js_intIndex,js_intIndex+1)
			if(js_charText==" ")
				js_charText = "+"
			strText1 += js_charText
		}
		return strText1;
	}
}


//this function validates the input date against the current date and it should be less than the current date
function js_fnCompareCurrentDate1(objMonth,objDay,objYear,datCurDate,strMessage)
{
	//parameter description
	//objMonth->Object name of month
	//objDay->object name of the day
	//objYear->object name of the year
	//strMessage-> message to be displayed

	var js_datInput,js_datCurDate
	js_datInput=objMonth.options[objMonth.selectedIndex].text + "/" + objDay.options[objDay.selectedIndex].text + "/" + objYear.options[objYear.selectedIndex].text
	js_datInput=new Date(js_datInput)
	js_datCurDate=new Date(datCurDate)
	if(js_datInput.getTime()>js_datCurDate.getTime())
	{
		alert(strMessage + " Should be less than current date")
		objMonth.focus()
		return false
	}
	return true
}

//this function validates the input date against the current date and it should not be less than the current date
function js_fnCompareCurrentDate(objMonth,objDay,objYear,datCurDate,strMessage)
{
	//parameter description
	//objMonth->Object name of month
	//objDay->object name of the day
	//objYear->object name of the year
	//strMessage-> message to be displayed

	var js_datInput,js_datCurDate
	js_datInput=objMonth.options[objMonth.selectedIndex].text + "/" + objDay.options[objDay.selectedIndex].text + "/" + objYear.options[objYear.selectedIndex].text
	js_datInput=new Date(js_datInput)
	js_datCurDate=new Date(datCurDate)
	/*if(js_datInput.getMonth()<js_datCurDate.getMonth())
	{		
		alert(strMessage + " Should not be less than current date(month)")
		objMonth.focus()
		return false
	}
	else if(js_datInput.getDate()<js_datCurDate.getDate())
	{		
		alert(strMessage + " Should not be less than current date(day)")
		objDay.focus()
		return false
	}
	if(js_datInput.getYear()<js_datCurDate.getYear())
	{		
		alert(strMessage + " Should not be less than current date(year)")
		objYear.focus()
		return false
	}*/
	if(js_datInput.getTime()<js_datCurDate.getTime())
	{
		alert(strMessage + " Should be greater than current date")
		objMonth.focus()
		return false
	}
	return true
}

//this function will compare two dates
//if first date is greater than second date than it will return false other wise true
function js_fnCompareDates(objMonth1,objDay1,objYear1,objMonth2,objDay2,objYear2)
{
	//parameter description
	//objMonth1->Object name of month for the first date
	//objDay1->object name of the day for the first date
	//objYear1->object name of the year for the first date
	//objMonth2->Object name of month for the second date
	//objDay2->object name of the day for the second date
	//objYear2->object name of the year for the second date
	var js_datInput1,js_datInput2
	js_datInput1=new Date(objMonth1.options[objMonth1.selectedIndex].text + " /" + objDay1.options[objDay1.selectedIndex].text + "/" + objYear1.options[objYear1.selectedIndex].text)
	js_datInput2=new Date(objMonth2.options[objMonth2.selectedIndex].text + " /" + objDay2.options[objDay2.selectedIndex].text + "/" + objYear2.options[objYear2.selectedIndex].text)

	if(js_datInput1.getTime()>js_datInput2.getTime())
	{
		alert("From date must be less than or equal to current date")
		objMonth1.focus()
		return false
	}
	return true
}

//this function will compare two values for the combo box if they match then 
//it will return index which need to be selected
function js_fnSelected(objName,strComstring)
{
	//parameter description
	//objName->Name of the object which need to checked
	//strComstring->the string which is to be compare with the combo value
	var js_intIndex=new String()
	for(js_intIndex=0;js_intIndex<objName.length;js_intIndex++)
	{
		if(objName.options[js_intIndex].value==strComstring)
			return js_intIndex
	}
	return -1
}
function js_fnSelected1(objName,strComstring)
{
	//parameter description
	//objName->Name of the object which need to checked
	//strComstring->the string which is to be compare with the combo value
	var js_intIndex=new String()
	for(js_intIndex=0;js_intIndex<objName.length;js_intIndex++)
	{
		if(objName.options[js_intIndex].text==strComstring)
			return js_intIndex
	}
	return -1
}
function js_fnSelectedInt(objName,intComstring)
{
	//parameter description
	//objName->Name of the object which need to checked
	//strComstring->the string which is to be compare with the combo value
	var js_intIndex;
	for(js_intIndex=0;js_intIndex<objName.length;js_intIndex++)
	{
		if(objName.options[js_intIndex].value==intComstring)
			return js_intIndex
	}
	return -1
}

//function to show and hide the layers
function MM_showHideLayers()
{
	//v3.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null)
	{
		v=args[i+2];
		if (obj.style)
			obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v;
		obj.visibility=v;
	}
}

//function to show current date on the listbox
function js_fnCurrentDate(objMonth,iMonth,objDay,iDay,objYear,iYear)
	{
		//parameter description
		//objMonth->month lstbox
		//objDay->day lstbox
		//objYear->year lstbox
		//iMonth->current server month
		//iDay->current server day
		//iYear->current server year

		objMonth.selectedIndex=parseInt(iMonth)-1
		objDay.selectedIndex=parseInt(iDay)-1
		objYear.selectedIndex=parseInt(iYear)-1
	}

//function to navigate
function js_fnNavigate(sUrl)
	{
		document.forms[0].method = "post";
		document.forms[0].action = sUrl;	
		document.forms[0].submit();
	}	

function fnOpenWindow()
	{
		var openWin
		openWin=window.open("vcs_Profile.pdf","","top=0,left=0,location=1,scollbars=1,toolbar=1,menubar=1,height=520,width=790")
	}
	
function fnOpenWindow1()
	{
		var openWin
		openWin=window.open("ECommerce.pdf","","top=0,left=0,location=1,scollbars=1,toolbar=1,menubar=1,height=520,width=790")
	}

function openwin(winUrl)
		{
	my_window = window.open(winUrl,"",config="toolbar=1,location=1,top="+parseInt(window.screen.height)* (1/100)+",left="+parseInt(window.screen.width)* (1/100)+",menubar=1,scrollbars=1,width=770,height=400,resizable=1")
		}
		
function sopenwin(winUrl)
		{
	my_window = window.open(winUrl,"",config="toolbar=0,location=0,top="+parseInt(window.screen.height)* (1/100)+",left="+parseInt(window.screen.width)* (1/100)+",menubar=0,scrollbars=0,resizable=0")
		}
function fn1()
{
document.location.href="Main_Index.htm"
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//-----------------------------TRIM Functions -----------------------
function Trim(str)
	{
		var resultStr = "";
		resultStr = TrimLeft(str);
		resultStr = TrimRight(resultStr);
		return resultStr;
	}

function TrimLeft( str )
	{
		var resultStr = "";
		var i = len = 0;
		if (str+"" == "undefined" || str == null)
		return null;
		str += "";

	if (str.length == 0)
		resultStr = "";

	else {
	  	len = str.length - 1;
		len = str.length;

  		while ((i <= len) && (str.charAt(i) == " "))
			i++;
	 		resultStr = str.substring(i, len);
	  	}
	  	return resultStr;
}

function TrimRight( str ) {
	var resultStr = "";
	var i = 0;
	if (str+"" == "undefined" || str == null)
		return null;
	str += "";

	if (str.length == 0)
		resultStr = "";
	else {
  		i = str.length - 1;
  		while ((i >= 0) && (str.charAt(i) == " "))
 		i--;
  		resultStr = str.substring(0, i + 1);
  		}
  	return resultStr;
}

function validateString(txtObj,txtName)
{
var obj1 = txtObj;
if(Trim(obj1.value)=="")
	{
	alert("Enter a valid "+txtName);
	obj1.focus();
	return false;
	}
return true;

}
function isEmailAddress(WsCheck)
{
	var i, c;
	var at = dot = 0;
	var str = WsCheck;
	var sl  = str.length;
	var dx_at = dx_dot = -1;

	for (i = 0; i < sl; i++)
	{
		c = str.charAt(i);
		if (c == "@") {++at;  dx_at=i; }
		else if (c == ".") {++dot; dx_dot=i;}
		else if (c == " ")
		return false;
	}
	if ((sl < 8) || (dx_dot < 1) || (at != 1)
	|| (dx_at < 1) || (dx_dot-1 <= dx_at)
	|| (sl-3 < dx_dot))
	return false;
	else
	return true;
}
function echeck(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");  <!-- "@" symbol is not first or last -->
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID");  <!-- "." symbol is not first or last -->
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){   <!-- jason@@ is prevented -->
		    alert("Invalid E-mail ID");
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){<!-- check if jason.@ or jason@y. doesnt happen --> 
		    alert("Invalid E-mail ID"); 
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID"); <!-- if "." is not found after jason@y -->
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){ <!-- no spaces exists -->
		    alert("Invalid E-mail ID");
		    return false;
		 }

 		 return true;					
	}
function ValidateForm(formname){
	var emailID=formname.email;
	var chk1 = 0;
	var chk2 = 0;
	if (document.forms[0].name.value=="")
	{
		alert("Please Enter your name");
		document.forms[0].name.focus();
		return false;
	}
	if (echeck(emailID.value)==false){
		emailID.value="";
		emailID.focus();
		return false;
	}
	if ((formname.chk_respimd.checked==false) &&  (formname.chk_subscribe.checked==false))
	    {alert("Please select any one of the option");
	    formname.chk_respimd.focus();
	    return false;}
	if(formname.chk_respimd.checked)
		chk1 = 1
	if(formname.chk_subscribe.checked)
		chk2 = 1		
	window.open("Confirmation_page.asp?email="+emailID.value+"&name="+formname.name.value+"&chkBox="+chk1+"-"+chk2,"","top=202,left=160,location=0,scollbars=0,toolbar=0,menubar=0,height=373,width=500")
	document.forms[0].name.value=""
	emailID.value=""
	formname.chk_respimd.checked = false
	formname.chk_subscribe.checked= false
	
	/*formname.action="Confirmation_page.asp"
	formname.method="post"
	formname.submit()*/
	return false;		
 }
 function IsDateValid(strDate, chrFormat)
{	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
	var matchArray = strDate.match(datePat);
	var intMonth;
	var intDay;
	var intYear;
	if (matchArray == null)
	{return(false);}
	// If the format is "m" then validate for "mm/dd/yyyy" format
	if ((chrFormat == 'm') || (chrFormat == 'M'))
	{
		intMonth = matchArray[1];
		intDay = matchArray[3];
		intYear = matchArray[4];
	}
	else
	// else validate for "dd/mm/yyyy" format
	{intMonth = matchArray[3];
	 intDay = matchArray[1];
	 intYear = matchArray[4];}

	if ((intMonth < 1 || intMonth > 12) || (intDay < 1 || intDay > 31) ||
		((intMonth==4 || intMonth==6 || intMonth==9 || intMonth==11) && intDay==31))
	{return(false);}
	if (intMonth == 2)
	{// check for february 29th
	 var blnIsLeap = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
	 if (intDay > 29 || (intDay == 29 && !blnIsLeap))
	   {return(false);}
	}
	return(true);
}
