
// varable for the form. Inilized at the onload event.

// To set focus on passed control.
function setFocusObj(obj)
{
	//obj.focus();   
}


// To close the window
function CloseWindow(vWin)
{
	if(vWin)
	{	
		if(!vWin.closed)
		{
			vWin.close();
				
		}
	}
}

// Set focus if child window is opened.
function CheckModalWindow()
{
	if(win)
	{	
		if(!win.closed)
		{
			win.focus();
		}
	}
}			


function setTop()
{
	self.location='#top';	 
}
		
//Enable the textboxs
function EnableTextboxes(oFrm)
{
	setDisablePropTextboxes(oFrm,false);
}

//disable the textboxs
function DisableTextboxes(oFrm)
{
	setDisablePropTextboxes(oFrm,true);
}


// Set the disabled property
function setDisablePropTextboxes(oFrm,value) 
{ 
	var i=0; 
	while (oTxt = oFrm.elements.item(i++)) 
	{ 
		if (oTxt.type=="text") oTxt.disabled = value; 
	} 
} 

 
//Clear the form
function clearForm(oFrm) 
{ 
	clearTextboxes(oFrm);
	clearCheckboxes(oFrm);
	clearCMB(oFrm);
} 

// Claer all textboxs in form
function clearTextboxes(oFrm) 
{ 
	var i=0; 
	while (oTxt = oFrm.elements.item(i++)) 
	{ 
		if (oTxt.type=="text") oTxt.value=""; 
	} 
} 

// clear the check boxes
function clearCheckboxes(oFrm) 
{ 
		var i=0; 
		while (oTxt = oFrm.elements.item(i++)) 
		{ 
			if (oTxt.type=="checkbox" && oTxt.id != "chkInwardNo") oTxt.checked=false; 
		}
} 

// ini the select
function clearCMB(oFrm) 
{ 
	var i=0; 
	while (oCtl = oFrm.elements.item(i++)) 
	{ 
		if (oCtl.type=="select-one") oCtl.selectedIndex= 0; 
	} 
} 


function Validate(Texts)
{
	var i= new String();
	var str=new String();
	str=Texts.value;				
	i=str.substring(str.length-1,str.length );
	if(isNaN(i))
	{
		if (i==".")
		{
			return;
		}
		//alert("Please Enter Valid Number");
		var str=str.substring (0,str.length -1);
		Texts.value=str;
	}				
}

function ValidateNumber(Texts)
{
	var i= new String();
	var str=new String();
	str=Texts.value;				
	i=str.substring(str.length-1,str.length );
	if(isNaN(i))
	{
		alert("Please Enter Valid Number");
		var str=str.substring (0,str.length -1);
		Texts.value=str;
	}				
}

function ValidateCurrency(Texts)
{
	var i= new String();
	var str=new String();
	str=Texts.value;				
	i=str.substring(str.length-1,str.length );
	if(isNaN(i))
	{
		if (i==".")
		{
			return;
		}
		//alert("Please Enter Valid amount");
		var str=str.substring (0,str.length -1);
		Texts.value=str;
	}				
}
/*
//called onblur evevnt
function ValidateCurrencyBlur(Texts)
{	
	if(isNaN(Texts.value))
	{
		alert("Please Enter Valid Number");
		Texts.value="";
		Texts.focus();
		return false;
	}				
}
*/

function ValidatePhoneNo(Texts)
{
	var i= new String();
	var str=new String();
	str=Texts.value;
	
	i=str.substring(str.length-1,str.length );
	
	if(isNaN(i))
	{
		if (i=="-" || i=="+"   )
		{
			return;
		}
		//alert("Please Enter Valid Format +99-99-99999999");
		var str=str.substring (0,str.length -1);
		Texts.value=str;
	}				
}

//TO CLOSE THE WINDOW
    function closewindow() {
    self.opener = this;
    self.close();
}

//This procedure is called to round off the numeric variable
//and also to format it e.g. to display the number in 2 digit decimal format.
//There is an in-built round function in Math object but that fully rounds off the number.
//This function uses the Math.round function with the logic of Rounder to do the rounding to the decimal places. 0.00000000000003 added to fix the rounding error when the last digit is 5 E.g. 2.175*100 yields 217.499999999999997
//Parameters:
//1) Number to be rounded
//2) Places after decimal
function UsrRound(Num,Places)
{
  //convert the parameter in float
  Num=parseFloat(Num);
  //when no. of places are more than 0
  if(Places > 0) 
  {
     //when the actual decimal places are more than requested decimal places
     //rounding is required
     if((Num.toString().length - Num.toString().lastIndexOf('.')) > (Places + 1)) 
     {
        //rounder
        var Rounder = Math.pow(10, Places);
        //format the Math.round
        return UsrFormat(Math.round((Num * Rounder)+0.00000000000003) / Rounder,Places);
     } 
     else return UsrFormat(Num,Places);
  }
  else return UsrFormat(Math.round(Num),Places);
}

//This procedure is called from the OnLoad procedure of all the forms to determine whether the current browser is IE or netscape?
//It returns true if the browser is netscape, false otherwise.
function isBrowserNetscape()
{
  return(navigator.appName=="Netscape" ? true : false);
}



//This function is called from the ValidateData function of the pages having email address field to validate whether the email id entered is ok? It trims the leading and trailing spaces in the control, alerts the user of the failure of email validation if alert is requested, set the focus to the control and returns false for failure, true for success.
//Parameters:
//1) Control supporting the value property
//2) Whether to display the alert in case of failure
function CheckEMail(item,bAlert) 
{
  //form the error message
  var strErrorMsg = "Enter a valid Email ID.";
  //trim the spaces in the control
	item.value=item.value.trim();
	//check if the email id is valid
	if(!(echeck(item.value))) 
	{
	  //set the focus to the control
		item.focus();
		//alert for failure if requested
		if(bAlert)
		  alert(strErrorMsg);
		//return the failure code  
		return(false);
	}
	//return the success code
	return(true);
}

//This function is called from CheckEMail function to check if the string contains the valid email address.
function echeck(str) 
{
  //@ symbol
	var at="@"
	//. symbol
	var dot="."
	//find out the position where @ symbol is found
	var lat=str.indexOf(at)
	//length of the string
	var lstr=str.length
	//position of the dot
	var ldot=str.indexOf(dot)
	
	//if @ symbol not found or found at the start or end,validation fails
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
   return false;
  
  //if . symbol not found or found at the start or end,validation fails 
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
	   return false;
	
	//if @ symbol is found more than once,validation fails	
	 if (str.indexOf(at,(lat+1))!=-1)
	   return false;
	
	 //if . symbol is found just before @  or just after @ symbol,validation fails
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	    return false;

  //if @ symbol not found after the dot symbol,validation fails		 
	 if (str.indexOf(dot,(lat+2))==-1)
	    return false;
	
	//if any space is encounted in email address,validation fails	 
	 if (str.indexOf(" ")!=-1)
	   return false;
	
	//return the success value   
	 return true;

}

function CallPrint(strid,caption,cmbid)
{
 var Content = document.getElementById(caption);
 var prtContent = document.getElementById(strid);
 var cmbContent = cmbid;
var strOldOne=prtContent.innerHTML;
var cap=Content.innerHTML;
 var WinPrint = window.open('','','letf=0,top=0,width=100,height=100,toolbar=0,scrollbars=1,status=0');
 
if (typeof title !='undefined'){
	WinPrint.document.write('<TITLE>'+title+'</TITLE>');
	
}


 WinPrint.document.write(Content.innerHTML);
 WinPrint.document.write('</B></CENTER><br>');
  WinPrint.document.write(cmbContent);
 WinPrint.document.write(prtContent.innerHTML);
 WinPrint.document.close();
 WinPrint.focus();
 WinPrint.print();
 WinPrint.close();
 prtContent.innerHTML=strOldOne;
 Content.innerHTML=cap;
}


var varAcceptKey,varResetKey,varLogoutKey;
//var varResetKey
function EnterKeyValidation(ctrl) {
  if (window.event && window.event.keyCode == 13)
    if ( ctrl == "Accept")
		{
		varAcceptKey = "True";
		return true;
		}
	else if ( ctrl == "Reset")
		{
		varResetKey = "True";
		return true;
		}
		else if ( ctrl == "Logout")
		{
		varLogoutKey = "True";
		return true;
		}
    else
		if (varAcceptKey == "True")
		{
			varAcceptKey = "False";
			varResetKey = "False";
			varLogoutKey = "False";
			return true;
		}
		else if (varResetKey == "True")
		{
			varAcceptKey = "False";
			varResetKey = "False";
			varLogoutKey = "False";
			return true;
		}
	else if (varLogoutKey == "True")
		{
			varAcceptKey = "False";
			varResetKey = "False";
			varLogoutKey = "False";
			return true;
		}
		else
			return false;
  else
    return true;}
    
    /*<S> Manoj 31-Aug-2007*/
    /*Purpose: function to convert text to uppercase*/
    function fnToUpper(ctrl){
		//ctrl.value=ctrl.value.toUpperCase();
		return false;
    }
    /*<E> Manoj 31-Aug-2007*/
