﻿// JScript File



var mousex, mousey, algor

  

function Trim(TrimString)

{	var tempObj;

	if(TrimString){tempObj = TrimString;TrimString = tempObj.value;}

	if(TrimString == "undefined" || TrimString == null) return null;

	if(TrimString.length == 0)TrimString="";

	else

	{	var Lcont=0,TempStrArray=TrimString.split(" "),Rcont=TempStrArray.length-1;

		while(TempStrArray[Lcont] == "")Lcont++;while(TempStrArray[Rcont] == "")Rcont--;

		if(Rcont<Lcont)TrimString="";else

		for(TrimString = TempStrArray[Lcont], Lcont++ ; Lcont <= Rcont ; Lcont++) TrimString += " " + TempStrArray[Lcont];

		var re = /\'/g;

		TrimString = TrimString.replace(re,"''");

	}

	if(tempObj && TrimString != "undefined" && TrimString != null) 

	{	tempObj.value = TrimString;	return tempObj	  }

	else return TrimString;

}



function FormTrim(oForm)

{

	for (i=0; i<=oForm.length-1; i++)

	{	if (oForm[i].type == "text" || oForm[i].type == "textarea" || oForm[i].type == "password" )		

			Trim(oForm[i])

	}

}   

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 isValidEmail(strEmail)

 {

	var lat=strEmail.indexOf("@")

	var lstr=strEmail.length



	if(strEmail.lastIndexOf("'") != -1)// if ' present return false

		return false

	else if (strEmail.indexOf("@")==-1) //if @ not present return false

		return false

	//if @ not found or found in the begining or found at the last return false

	else if (strEmail.indexOf("@")==-1 || strEmail.indexOf("@")==0 || strEmail.indexOf("@")==lstr)

		return false

	//if . not found or found in the begining or found at the last return false

	else if (strEmail.indexOf(".")==-1 || strEmail.indexOf(".")==0 || strEmail.indexOf(".")==lstr)

		return false

	//if two @ are found in the string return false

	else if (strEmail.indexOf("@",(lat+1))!=-1)

		return false

	//if . found in the last return false

	else if (strEmail.substring(lat-1,lat)=="." || strEmail.substring(lat+1,lat+2)==".")

		return false

	//if two . found in the string return false

	else if (strEmail.indexOf(".",(lat+2))==-1)

		return false

	//if space is found return false

	else if (strEmail.indexOf(" ")!=-1)

		return false

	else	return true

}

function Fn_ZipValidation(Cmbstate, txtZip)

{

    

	var range = document.forms[0].elements[Cmbstate].value

	var zipcode = document.forms[0].elements[txtZip].value

	var zipval = document.forms[0].elements[txtZip].value.substring(0,3)

	/*var range = document.getElementById("Cmbstate").value

	var zipcode = document.getElementById("txtZip").value

	var zipval = document..getElementById("txtZip").value.substring(0,3)*/	

	/*var lblerror=document.getElementById("lblzip")*/

	/* ########## If country is Used ############ */

	if(range == 0)

	{

		//lblerror.innerHTML =""		

		return true

	}

	else if(zipcode.length < 5)

	{

		return false

	}

	else if(zipcode.length > 5)

	{

		//lblerror.innerHTML ="Invalid zip"

		return false

	}

	/* ########## End ############ */

	var arr =new Number()

	arr = range.split("-")	

	if (arr.length == 0)

	{

			//lblerror.innerHTML ="Enter zip"

			return false 

	}

	if (arr.length == 1)

	{

		if (range != zipval) 

		{

			//lblerror.innerHTML ="Invalid zip"

			return false 

		}	

	}

	else if (arr.length == 2)

	{

		var min = arr[0]

		var max = arr[1]

		if (zipval >= min && zipval <= max){}

		else

		{

			//lblerror.innerHTML ="Invalid zip"

			return false

		}

	}

	else if (arr.length == 3)

	{

		var min = arr[0]

		var max = arr[1]

		var Equal = arr[2]

		if ((zipval >= min && zipval <= max) || (Equal == zipval)){}

		else

			{

				//lblerror.innerHTML ="Invalid zip"

				return false

			}

		

	}

	//lblerror.innerHTML =""

	return true;

}

function getQueryVariable(variable)

{

	var query = window.location.search.substring(1);

	var vars = query.split("&");

	for (var i=0;i<vars.length;i++)

	{

			var pair = vars[i].split("=");

		    if (pair[0] == variable)

			{

				return pair[1];

			}

	}

	return null;

}

function isFutureDate(drpMon,drpDay,drpYear,currMonth,currDay,currYear)

     {

		drpMon = parseInt(drpMon)

		drpDay = parseInt(drpDay)

		drpYear = parseInt(drpYear)

		currMonth = parseInt(currMonth)

		currDay = parseInt(currDay)

		currYear = parseInt(currYear)

		

		if(drpYear > currYear)

		{

			return true;

		}

		else if(drpYear == currYear)

		{

			if(drpMon > currMonth)

			{

				return true;

			}

			else if(drpMon == currMonth)

			{

				if(drpDay > currDay)

				{

					return true;

				}

				else

				{

					return false;

				}

			}

			else

			{

				return false;

			}							

		}

		else

		{

			return false;

		}

     }

     



    function IsValidDateMandatory(ObjMM, ObjDD, ObjYY)

    {	

        

        if (ObjDD.value == "")

        {

            alert("Select Date");

            ObjDD.focus(); 

            return false;

        }

        if (ObjMM.value == "")

        {

            alert("Select Month")

            ObjMM.focus(); 

            return false;

        }

        if (ObjYY.value == "")

        {

            alert("Select Year")

            ObjYY.focus(); 

            return false;

        }

        if(ObjMM.value == "4" || ObjMM.value == "6" || ObjMM.value == "9" || ObjMM.value == "11")

        {	

            if(ObjDD.value > 30)

            {	alert("Date Cannot be greater than 30"); ObjDD.focus(); return false; }

        }

        if(ObjMM.value == "2")

        {	

            var modval

            modval = parseInt(ObjYY.value)%4

            if(modval == 0)

            {	

                if(parseInt(ObjDD.value) > 29)

                {	alert("Date cannot be greater than 29");	ObjDD.focus();	return false; }

            }

            else

            {	

                if(parseInt(ObjDD.value) > 28)

                {	alert("Date cannot be greater than 28"); ObjDD.focus(); return false; }

            }

        }

    }

    function IsValidDate(ObjMM, ObjDD, ObjYY,DateSrc)

    {	

	    if(ObjMM.value == "4" || ObjMM.value == "6" || ObjMM.value == "9" || ObjMM.value == "11")

	    {	

		    if(ObjDD.value > 30)

		    {	alert("Date Cannot be greater than 30 in '"+DateSrc+"' Date"); ObjDD.focus(); return false; }

	    }

	    if(ObjMM.value == "2")

	    {	

		    var modval

		    modval = parseInt(ObjYY.value)%4

		    if(modval == 0)

		    {	

			    if(parseInt(ObjDD.value) > 29)

			    {	alert("Date cannot be greater than 29 in '"+DateSrc+"' Date");	ObjDD.focus();	return false; }

		    }

		    else

		    {	

			    if(parseInt(ObjDD.value) > 28)

			    {	alert("Date cannot be greater than 28 in '"+DateSrc+"' Date"); ObjDD.focus(); return false; }

		    }

	    }

    }



     function isPreviousDate(drpMon,drpDay,drpYear,currMonth,currDay,currYear)

     {

		drpMon = parseInt(drpMon)

		drpDay = parseInt(drpDay)

		drpYear = parseInt(drpYear)

		currMonth = parseInt(currMonth)

		currDay = parseInt(currDay)

		currYear = parseInt(currYear)

		

		if(drpYear < currYear)

		{

			return true;

		}

		else if(drpYear == currYear)

		{

			if(drpMon < currMonth)

			{    

				return true;

			}

			else if(drpMon == currMonth)

			{

				if(drpDay < currDay)

				{   

					return true;

				}

				else

				{

					return false;

				}

			}

			else

			{

				return false;

			}							

		}

		else

		{

			return false;

		}

     }

     function CompareFromToDate(yyFrom,mmFrom,ddFrom,yyTo,mmTo,ddTo)

     {

		if(eval(yyFrom) > eval(yyTo))

		{

			return false;

		}

		else if (eval(yyFrom) == eval(yyTo))

		{		

			if(eval(mmFrom) > eval(mmTo))

			{					

				return false;

			}

			else if (eval(mmFrom) == eval(mmTo))

			{

				if(eval(ddFrom) > eval(ddTo))

				{					

					return false;

				}

			}		

		}

     }

     

     function IsValid_DateRange(FromMM, FromDD, FromYY,ToMM, ToDD, ToYY,objError)

     {

        yyFrom = FromYY.value

        mmFrom = FromMM.value

        ddFrom = FromDD.value

        yyTo = ToYY.value

        mmTo = ToMM.value

        ddTo = ToDD.value

        

        

        if(eval(yyFrom) > eval(yyTo))

		{

			return FnSearchMSG(ToYY, "From Date Cannot be greater than To Date ",objError) 

		}

		else if (eval(yyFrom) == eval(yyTo))

		{		

			if(eval(mmFrom) > eval(mmTo))

			{					

				return FnSearchMSG(ToMM, "From Date Cannot be greater than To Date ",objError) 

			}

			else if (eval(mmFrom) == eval(mmTo))

			{

				if(eval(ddFrom) > eval(ddTo))

				{					

					return FnSearchMSG(ToDD, "From Date Cannot be greater than To Date ",objError) 

				}

			}		

		}

    	

        if(ToDD.selectedIndex != 0 && ToMM.selectedIndex != 0 && ToYY.selectedIndex != 0)

        {

	        if(FromDD.selectedIndex == 0 || FromMM.selectedIndex == 0 || FromYY.selectedIndex == 0)

	        {

		        FnSearchMSG(FromMM, "From Month Cannot be blank")

		        return false;

	        }

        }

    }

    function FnSearchMSG(Obj, Msg,objError)	

    {	

        objError.innerHTML = Msg

        if (Obj) Obj.focus()

        return false;

    }

     function getMonthName(ind)

	{ 

		var Arr = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec") 

		if(ind != 0)

		return Arr[ind-1]

	}

//------------------ Creating,Reading Cookies ---------------------------------------

function createCookie(name,value,days) 

{

	if (days) 

	{

		var date = new Date();

		date.setTime(date.getTime()+(days*24*60*60*1000));

		var expires = "; expires="+date.toGMTString();

	}

	else var expires = "";

	document.cookie = name+"="+value+expires+"; path=/";

}



function readCookie(name) 

{

	var nameEQ = name + "=";

	var ca = document.cookie.split(';');

	

	for(var i=1;i < ca.length;i++) 

	{			

		var c = ca[i];

		while (c.charAt(0)==' ') c = c.substring(1,c.length);

		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);

	}

	return null;

}



function eraseCookie(name) 

{

	createCookie(name,"",-1);

}





function GetGridID(id)

{

    

    var GridAndTextboxID = new String()

    var GridID,StartingNo

    var TextBoxID = new String()

    var CtlIndex = new Number()

    var Char = new Number()	    

          			

    GridAndTextboxID = id

	

    CtlIndex = GridAndTextboxID.indexOf("ctl")

    //alert(CtlIndex)							

    if(GridAndTextboxID.indexOf("ctl") > 0) //i.e Control is inside the Grid

    {

	    GridID = GridAndTextboxID.substring(0,CtlIndex+3) //OUTPUT : DataGrid_ctl

	    //alert(GridID)

	    TextBoxID = GridAndTextboxID.substring(CtlIndex,GridAndTextboxID.length) //OUTPUT : ctl2_TxtDrug (if grid item starts from 2)

	    //alert(TextBoxID)			

	    Char = TextBoxID.indexOf("_")								

	    //alert(Char)

	    StartingNo = TextBoxID.substring(3,Char) //OUTPUT : 2

	   //alert(StartingNo)	

	    return GridID+StartingNo

    } 

}



/*  New 17 07 07  */

    function filtergridval(str) 

	 {

          re = /\$|,|#|~|`|\%|\@|\.|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|/g;

    	  var tmp = str.replace(re, "");

		  return tmp

     }

     

   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

    }

 /*  End of 17 07 07 */    

 

 /*  Date of Birth Add on 04 09 2007 */

 

 function FnCheckGreaterCurdate(todaydate, mont, dat, yea, lbl)

{

	

	var iFocus = new Boolean()

	iFocus = true

	//alert(todaydate  +'-'+  mont +'-'+ dat +'-'+ yea +'-'+ lbl)

	var mon = document.forms[0].elements[mont].value

	var day = document.forms[0].elements[dat].value

	var year = document.forms[0].elements[yea].value

	var Jslblerror = document.getElementById(lbl)



//	alert(mon +'-'+ day  +'-'+ year  +'-'+ Jslblerror)



	var splittodaydate = todaydate.split("/")

	var currentyr = splittodaydate[2]

	var currentmon = splittodaydate[0]

	var currentdd = splittodaydate[1]

	//alert(splittodaydate[2] +'-'+ splittodaydate[0]  +'-'+ splittodaydate[1])

	

	if (document.forms[0].elements[mont].selectedIndex != "" ||  document.forms[0].elements[dat].selectedIndex != "" || document.forms[0].elements[yea].selectedIndex != "")

	{

		if (document.forms[0].elements[mont].selectedIndex == "")

		{

			Jslblerror.innerHTML ="Month cannnot be blank"

			document.getElementById(mont).focus()

			return false

		}

		if (document.forms[0].elements[dat].selectedIndex == "")

		{

			Jslblerror.innerHTML ="Date cannnot be blank"

			document.getElementById(dat).focus()

			return false

		}

		if (document.forms[0].elements[yea].selectedIndex == "")

		{

			Jslblerror.innerHTML ="Year cannnot be blank"

			document.getElementById(yea).focus()

			return false

		}

	}

	

	if(parseInt(year) > parseInt(currentyr))

		{

		

			Jslblerror.innerHTML = "Date cannot be greater than current date"

			document.getElementById(yea).focus()

			iFocus = false

		}

		else if(parseInt(year) == parseInt(currentyr))

		{

			

		//alert(parseInt(mon) +" // "+ parseInt(currentmon))

		if(parseInt(mon) > currentmon)

			{

				Jslblerror.innerHTML = "Date cannot be greater than current date"

				document.getElementById(mont).focus()

				iFocus = false

			}

			

	 else if(parseInt(mon) == parseInt(currentmon))

			{

				//alert(parseInt(day) +" // "+ parseInt(currentdd))

			if(parseInt(day)> eval(currentdd))

				{

					Jslblerror.innerHTML = "Date cannot be greater than current date"

					document.getElementById(dat).focus()

					iFocus = false

				}

			}

		}

		

		if(iFocus==false)

		return false

		 else

		 return true

} 



/*      Add customer Po in Get Date Format in String Value    */



     function addDays(myDate,days)

        {

            return new Date(myDate.getTime() + days*24*60*60*1000);

        }

    function GetDateFormat(strDate)

    {

		var d = new Date(strDate)	

		var MonthName = ""

		var Hour = ""

		var Minutes = ""

		var AMORPM = ""

		

		MonthName = getMonthName(parseInt(d.getMonth())+1)

		Hour = d.getHours()

		Minutes = d.getMinutes()

		return MonthName + " " + d.getDate() + " " + d.getFullYear()  

	}

	

	function IsNumeric(strString)

		//  check for valid numeric strings	

	{

	var strValidChars = "0123456789";

	var strChar;

	var blnResult = true;

	

	if (strString.length == 0) return false;

	

	//  test strString consists of valid characters listed above

	for (i = 0; i < strString.length && blnResult == true; i++)

	  {

	  strChar = strString.charAt(i);

	  if (strValidChars.indexOf(strChar) == -1)

		 {

		 blnResult = false;

		 }

	  }

	return blnResult;

	}

	

/*                   End of Get Date Format in String Value  */	



 

 	
