//Used by project for illegal character 
//var badchars = '/\@:?%!£$#~><^*+=";(){}[]';
var badchars ='';

// function to show image according to its hight and width

	var secs = 1;
	var popupWindow = '';

	function closeWindowClock( )
	{
		secs++;
		if(secs==60)
			popupWindow.close();
	}	
	
    String.prototype.trim = function ()
    {
			    return this.replace(/^\s*/, "").replace(/\s*$/, "");
    }
    
    //pass button object name
function fnEnterKey(buttonToClick) 
{ 
if (event.keyCode == 13) 
{ 
event.cancelBubble = true; 

event.returnValue = false; 

Form1[buttonToClick].click(); 
} 
} 

	function showImage(url)
	{
		var imageWindow = window.open("","","scrollbars=no,resizable=yes");
	
		secs = 0;
		imageWindow.document.writeln("<html><head><title> R E G A L I </title>\n");
		imageWindow.document.writeln("<SCRIPT LANGUAGE=\"JavaScript\">");
		imageWindow.document.writeln("<!-- Begin\nfunction fitWindowSize() { var isNav4, isIE4; if (parseInt(navigator.appVersion.charAt(0)) >= 4) {");
		imageWindow.document.writeln("isNav4 = (navigator.appName == \"Netscape\") ? 1 : 0;");
		imageWindow.document.writeln("isIE4 = (navigator.appName.indexOf(\"Microsoft\") != -1) ? 1 : 0;}");
		imageWindow.document.writeln("if (isNav4) {window.innerWidth = document.layers[0].document.images[0].width;");
		imageWindow.document.writeln("window.innerHeight = document.layers[0].document.images[0].height;}");
		imageWindow.document.writeln("if (isIE4) {window.resizeTo(800, 600);");
		imageWindow.document.writeln("width = 800 - (document.body.clientWidth -  document.images[0].width);");
		imageWindow.document.writeln("height = 600 - (document.body.clientHeight -  document.images[0].height);");
		imageWindow.document.writeln("window.resizeTo(width, height);   } } \/\/  End -->");
		imageWindow.document.writeln("<\/script>");

		imageWindow.document.writeln("<body onLoad=\"fitWindowSize()\">");
		imageWindow.document.writeln("<div style=\"position:absolute; left:0px; top:0px\">");
		imageWindow.document.writeln("<img src=\""+url+"\" onload=\"fitWindowSize()\">");
		imageWindow.document.writeln("<br><\/div><\/body><\/html>");

		popupWindow = imageWindow;

		setInterval('closeWindowClock()',1000);
	}


// function to create preference list as per the requirement 
	function module(objPassed)
	{
		module_selection= new String;
		module_selection="";
		for(i=0;i<objPassed.length;i++)
		{ 
			if(objPassed.options[i].selected!=0)
			{ 
			module_selection+=objPassed.options[i].value+"#";
			} 
		}
		module_selection=module_selection.substring(0,(module_selection.length-1))
		return module_selection;
	}
// end of creation preference list 

	function ValidateDDL(objDDL, defaultVal, errorMSG)
	{
		if(objDDL.options[objDDL.options.selectedIndex].value == defaultVal)
		{
			alert(errorMSG);
			objDDL. focus();
			return false;
		}
		return true;
	}

	function ValidateText(obj, errMsg){
		if(!checkblank(obj.value))
		{
			alert(errMsg);
			return false;
		}
		return true;
	}
//function to check if all the characters are spaces
	function checkblank(textval)
	{
		isblank= new String
		isblank="";
		isblank1= new String
		isblank1="";
		for(j=0; j<textval.length; j++)
		{
			if(textval.substring(j,j+1)==' ') { isblank=isblank+'1'; }
			else { isblank=isblank+'0'; }
			isblank1=isblank1+'1';
		}
//		alert(isblank +'  '+ isblank1);
		if(isblank == isblank1) { textval=""; return false; }
		else { return true; }
	}
// end of function checkblank


	
//function to check if the text field is null or only spaces
	function checktext(textvalue,message)
	{
		var str="";
		var str=textvalue.value;
		if (message==null) message="";


		if(!(checkblank(str)))
		{
			if ( message != ""  )
			alert(message);

			textvalue.focus()
			return false
		}
		else
		{
			return true
		}
	}
// end of function checktext

// function to check  textarea value null or spaces or maximum limit crosses
	function checktextarea(textvalue,message,limit)
	{
		var str="";
		var str=textvalue.value;
		if((str.length > limit || str.length < 3) || (!(checkblank(str))))
		{
			alert('Error : '+message + limit + ' characters\n'+ '          You entered text with Length '+str.length);
			textvalue.focus();
			return false;
		}
		else
		{
			return true;
		}

	}
// end of function checktextarea

//function to check email
	function checkemail(textval,message)
	{
		var str="";
		var atrate=0;
		var str = textval.value;
		
		if (str=="")
		{
			alert(message)
			textval.select()
			return false;
		}
		else 
		{
			var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/;
			if(!(emailFilter.test(str))){
				alert(message)
				textval.select()
				return false;
			}
		}
	return true
	}
//end of function checkemail


//FUNCTION TO ALLOW SPECIAL CHARACTER IN TELEPHONE NO
    function checktelephonewithsplchar1(textval)
    {
        //alert(event.keyCode);
        //debugger;
        
        var str ="";
        var str = textval.value;
        //IN ONCHANGE EVENT IT HAVE KEYCODE 0 AS IT CONTAINS ALL ENTERED CHARACTERS
        if(event.keyCode == 0)
        {
            return true;
        }
        
        if(event.keyCode < 48 || event.keyCode > 57 ) 
        {
            if(event.keyCode == 45)
            {
                return true;
            }
            else
            {
                event.returnValue = false;
                return false;
            }
        }
        else
        {
            return true;
        }
        return true
    }


//function to check for numeric data only
	function checknumval(numval,message)
	{
		var str="";
		var str=numval.value;
		if(checkblank(str))
		{
			if (str != "") 
			{
				if (String((str)*1)=="NaN")
				{
					if(message)
						alert(message);
					else
						alert('Error : The entry is not a number')
					numval.select()
					return false
				}
				
			}
			else // if it is null
			{
			
				alert('Error : '+ message)
				numval.select()
				return false 
			}

		}
		else
		{
			alert('Error : The entry is not a number')
			numval.select()
			return false
		}
	return true
	}

//end of function checknumval

//function to check for drop down selection
	function checkdropdown(objPassed,message)
	{
		if(objPassed.value =="") 
		{
			alert ("Error : "+message)
			objPassed.focus()
			return false
		}
		else
		{
			return true
		}
	}
	
//end of function


//function to check the date & return date format
function checkDates(strdd,strmm,stryy,Adate) 
{
	var dd_index = strdd.selectedIndex;
	var mm_index = strmm.selectedIndex;
	if(strdd.options[dd_index].value == "DD" || strmm.options[mm_index].value =="MM" || String((stryy.value)*1)=="NaN")
	{
		alert("Please fill the Date ");
		strdd.focus();
		return false
	}
	else 
	{
		var new_dob = new String()
		new_dob=strmm.options[mm_index].value+'/'+strdd.options[dd_index].value+'/'+stryy.value.substring(2,stryy.value.length)
		var indate=new_dob;
		
		if (indate.indexOf("-")!=-1) { var sdate = indate.split("-") }
		else if (indate.indexOf("/")!=-1) { var sdate = indate.split("/") }

		var chkDate=new Date(Date.parse(indate))
		var cmpDate=(chkDate.getMonth()+1)+"/"+(chkDate.getDate())+"/"+(chkDate.getYear())
		var indate2=(Math.abs(sdate[0]))+"/"+(Math.abs(sdate[1]))+"/"+(Math.abs(sdate[2]))    
		
		if (indate2!=cmpDate)
		{
			alert("Invalid Date Format (DD-MON-YYYY)");
			strdd.focus();
			return false;
		}
		else
		{
			Adate.value = new_dob;
				return true;
		}
	}

}
//end of function checkdate

//new window open disclaimer

  function descc(name){
  game=window.open (name,"","height=300,width=450,resizable=1,navigationbar=0,status=0,menubar=0,location=0,scrollbars=yes")
  }
  
  //use the function
 //<a href="javascript:descc('disclaimer.htm')">Disclaimer</a> 

//end

// function to calculate time difference
// return no of days.
	function timeDifference( earlierdate, laterdate )
	{
		

		var earlierdate_array = earlierdate.value.split("-");
		var laterdate_array = laterdate.value.split("-");

		// incomming format mm/dd/yyyy

		// creating date object of format yyyy,mm,dd
		// month january = 0 , february = 1, and so on.

		var e_yy =  earlierdate_array[2];
		var e_mm =  earlierdate_array[0]-1;
		var e_dd =  earlierdate_array[1];

		var l_yy =  laterdate_array[2];
		var l_mm =  laterdate_array[0]-1;
		var l_dd =  laterdate_array[1];


		//alert  ( 'earlier date :'+earlierdate +', later date '+laterdate ) ;
		//alert ( 'earlier date yy '+e_yy+' mm '+e_mm+' dd '+e_dd+ ' later date yy '+l_yy+' mm '+l_mm+' dd '+l_dd );

		// new date format (yy,mm,dd)
		var earlier_date = new Date( e_yy, e_mm, e_dd );
		var later_date = new Date( l_yy, l_mm, l_dd );

		var difference = later_date.getTime() - earlier_date.getTime();
		var daysDifference = Math.floor(difference/1000/60/60/24);
		
		return (daysDifference+1);
	}

//--by OM 08-02-3  12:32:5----------------------------------//
//-function to add/sub(depending on the action value) no of days/month/year from the startDate
//-returns the result date
	function DateAdd(startDate, numDays, numMonths, numYears,action)
	{
		//alert("Hello");
		//alert(startDate);
		var returnDate = new Date(startDate.getTime());
		//alert(returnDate);
		var yearsToAdd = numYears;
		
		var month = returnDate.getMonth()	+ numMonths;

		if (month > 11)
		{
			alert("in month cond");
			yearsToAdd = Math.floor((month+1)/12);
			month -= 12*yearsToAdd;
			yearsToAdd += numYears;
		}

		returnDate.setMonth(month);
		returnDate.setFullYear(returnDate.getFullYear()	+ yearsToAdd);

		if(action=="add"){
			//alert("added");
			returnDate.setTime(returnDate.getTime()+60000*60*24*numDays);
		}else if(action=="sub"){
			returnDate.setTime(returnDate.getTime()-60000*60*24*numDays);
		}

		return returnDate;

	}

	function YearAdd(startDate, numYears,action)
	{
			return DateAdd(startDate,0,0,numYears,action);
	}

	function MonthAdd(startDate, numMonths,action)
	{
			return DateAdd(startDate,0,numMonths,0,action);
	}

	function DayAdd(startDate, numDays,action)
	{
	//alert(startDate);
	//alert(numDays);
	//alert(action);
			return DateAdd(startDate,numDays,0,0,action);
	}

	function validateDate(earlierdate,laterdate)
	{

//		alert ("earlierdate ["+earlierdate+"]laterdate ["+laterdate+']' );

		if(earlierdate=='' && laterdate==''){return true;}

		var earlierdate_array = earlierdate.split("/");
		var laterdate_array = laterdate.split("/");

		// incomming format mm/dd/yyyy

		// creating date object of format yyyy,mm,dd
		// month january = 0 , february = 1, and so on.

		var e_yy =  earlierdate_array[2];
		var e_mm =  earlierdate_array[0]-1;
		var e_dd =  earlierdate_array[1];

		var l_yy =  laterdate_array[2];
		var l_mm =  laterdate_array[0]-1;
		var l_dd =  laterdate_array[1];

		// new date format (yy,mm,dd)
		var earlier_date = new Date( e_yy, e_mm, e_dd );
		var later_date = new Date( l_yy, l_mm, l_dd );

		var difference = later_date.getTime() - earlier_date.getTime();
		
		if(difference<0){
			return false;
		}else{
			return true;
		}
		
	}
	
	function validateDate_DMY(earlierdate,laterdate)
	{


		if(earlierdate=='' && laterdate==''){return true;}

		var earlierdate_array = earlierdate.split("/");
		var laterdate_array = laterdate.split("/");

		// incomming format dd/mm/yyyy

		// creating date object of format yyyy,mm,dd
		// month january = 0 , february = 1, and so on.

		var e_yy =  earlierdate_array[2];
		var e_dd=  earlierdate_array[0];
		var e_mm =  earlierdate_array[1]-1;

		var l_yy =  laterdate_array[2];
		var l_dd =  laterdate_array[0];
		var l_mm =  laterdate_array[1]-1;

		// new date format (yy,mm,dd)
		var earlier_date = new Date( e_yy, e_mm, e_dd );
		var later_date = new Date( l_yy, l_mm, l_dd );

		var difference = later_date.getTime() - earlier_date.getTime();
		
		if(difference<0){
			return false;
		}else{
			return true;
		}
		
	}
	
	// return current date in dd/mm/yyyy format
	function getCurrentDate() {
		var td =	new Date();
		var d = td.getDate();
		var m = td.getMonth();
		m++;
		var y = td.getFullYear();
		var tdate = d+'/'+m+'/'+y;//dd/mm/yyyy
		return tdate;
	}
	
	function addItems(addText,addValue,toCtrl) {
		var i;
		var j;
		var itemexists;
		var nextitem;

		// step through all items in fromItem
		//for (i = 0; i < fromItem.options.length; i++) {
			//if (fromItem.options[i].selected) {
				// search toCtrl to see if duplicate
				j = 0;
				itemexists = false;
				while ((j < toCtrl.options.length) && (!(itemexists))) {
					if (toCtrl.options[j].value == addValue) {
						itemexists = true;
						alert(addText + " found!");
					}
					j++;
				}

				if (!(itemexists)) {
					// add the item
					nextitem = toCtrl.options.length;
					toCtrl.options[nextitem] = new Option(addText,addValue,true);
					toCtrl.options[nextitem].selected=true
				}
			//}
		//}
	}


//function to check for whole number data only
	function checkWholeNumber(Obj,msg)
	{
		if(!checkblank(Obj.value)){alert("Error: Please enter a numeric value");return false;}
		
		if ((Obj.value*1) != parseInt(Obj.value*1) ) // || (parseInt(Obj.value*1) <= 0)
		{
			if(msg == "")
			{alert("Error: Please enter a whole numeric value");}
			else
			{ alert(msg);  }
			Obj.select();
			return false;
		}

		var str="";
		var str=Obj.value;

		where_is_dot = str.indexOf(".");
				
		// check the value after the decimal point if its nothing give an alert
		if (str.charAt([where_is_dot+1]) =='')
		{
				if(msg == "") 
				{  alert("Error : Please Enter a numeric Value");  }
				else
				{ alert(msg);  }
				Obj.select()
				return false ;

		}


		return true;
	}
	
	function checkWholeNumberNODOT(Obj,msg)
	{
		if(!checkblank(Obj.value)){alert("Error: Please enter a numeric value");return false;}
		
		if ((Obj.value*1) != parseInt(Obj.value*1) ) // || (parseInt(Obj.value*1) <= 0)
		{
			if(msg == "")
			{alert("Error: Please enter a whole numeric value");}
			else
			{ alert(msg);  }
			Obj.select();
			return false;
		}

		var str="";
		var str=Obj.value;
		where_is_dot = str.indexOf(".");
				
		// check the value after the decimal point if its nothing give an alert
		if (str.indexOf(".") != -1)
		{
				if(msg == "") 
				{  alert("Error : Please Enter a numeric Value");  }
				else
				{ alert(msg);  }
				Obj.select()
				return false ;

		}


		return true;
	}
	
	function chkTelFormat(tel1,tel2,tel3,req,msg){
		error=0;

		if(trim(tel1.value)!='' || trim(tel2.value)!='' || trim(tel3.value)!='' ){

			if(tel1.value==''){error=1;}
			else if(tel2.value==''){error=2;}
			else if(tel3.value==''){error=3;}

			if(error>0){
				alert(msg);
				eval("tel"+error+".focus()");
				return false;
			}

		}else if(tel1.value=='' && tel2.value=='' && tel3.value=='' && req==1){
				alert("Please enter tel no");
				tel1.focus();
				return false;
		}
		
		return true;

	}

 // Removes trailing spaces from the passed string. Also removes
function ltrim(inputString) {
   if (typeof inputString != "string") { return inputString; }

   var retValue = inputString;

	var ch = retValue.substring(0, 1);
	   
   while (ch == " ") { // Check for spaces at the beginning of the string
	  retValue = retValue.substring(1, retValue.length);
	  ch = retValue.substring(0, 1);
   }

   return retValue; // Return the trimmed string back to the user

}

// Removes leading spaces from the passed string. Also removes
function rtrim(inputString) {
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;

	//---for right trim-------------
	   ch = retValue.substring(retValue.length-1, retValue.length);
	   while (ch == " ") { // Check for spaces at the end of the string
		  retValue = retValue.substring(0, retValue.length-1);
		  ch = retValue.substring(retValue.length-1, retValue.length);
	   }

   return retValue; // Return the trimmed string back to the user

}

// Removes leading and trailing spaces from the passed string. Also removes
// consecutive spaces and replaces it with one space. If something besides
// a string is passed in (null, custom object, etc.) then return the input.
function trim(inputString) {
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;

	//----for left trim-------
	   var ch = retValue.substring(0, 1);
	   
	   while (ch == " ") { // Check for spaces at the beginning of the string
		  retValue = retValue.substring(1, retValue.length);
		  ch = retValue.substring(0, 1);
	   }
	//--------------------

	//---for right trim-------------
	   ch = retValue.substring(retValue.length-1, retValue.length);
	   while (ch == " ") { // Check for spaces at the end of the string
		  retValue = retValue.substring(0, retValue.length-1);
		  ch = retValue.substring(retValue.length-1, retValue.length);
	   }

   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }

   return retValue; // Return the trimmed string back to the user

}

function openCenteredWindow(url, height, width, name, parms) {
   var left = Math.floor( (screen.width - width) / 2);
   var top = Math.floor( (screen.height - height) / 2);
   var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
   if (parms) { winParms += "," + parms; }
   var win = window.open(url, name, winParms);
   if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
   return win;
}

//function added by prathesh for highlight tr
var previoueTr='';
function changeColor(tr_id,object)
{
	//statements
	if(object.type=='radio')
	{
		if(previoueTr!='' )
			document.getElementById(previoueTr).bgColor = 'white';
	
		document.getElementById(tr_id).bgColor = '#FFF3DC';
		previoueTr=tr_id;
	}
	else
	{
		if(object.checked==false)
			document.getElementById(tr_id).bgColor = 'white';
		else
			document.getElementById(tr_id).bgColor = '#FFF3DC';
	}

	return;
}

	//function to automate the tel no and fax no change position
	function changeTelIndex( selfObj,nextObj )
	{
		//statements
		if(selfObj.value.length==3)
			nextObj.focus();	

		return;
	}


//Sample usage- This will round 23.3353 to 2 decimals and then alert result:
//roundit(23.3353, 2)
/*
e.g:
num=1234.5678 > output is 1234.57

roundit(1234.5678,2)

if("number of digits before decimals" > (places +1)"i.e 3") then

rounder=Math.pow(10, Places); 10 to the power of 2=100

Math.round(1234.5678 * 100)/100=123457/100=1234.57

if still not understand then go recursive...

*/
function roundit(Num, Places) {
   
   if (Places > 0) {
      
	  if ((Num.toString().length - Num.toString().lastIndexOf('.')) > (Places + 1)) {
         var Rounder = Math.pow(10, Places);
         return Math.round(Num * Rounder) / Rounder;
      }
   
	  else return Num;
   }

   else return Math.round(Num);
}

//function to check if any of the radio button is checked
	function checkRadio( objRadioButton, message)
	{
		var is_selected = false;
		for ( var i = 0 ; i < objRadioButton.length ; i++ )
		{
			if ( objRadioButton[i].checked == true )
			{
				is_selected = true;
				break;
			}
		}

		if ( message != "" && is_selected == false )
		{
			alert('Error: '+message);
			objRadioButton[0].focus()
			return is_selected;
		}
		return is_selected;
	}
	
// end of function checktext

	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) {
	
		  var value_string = rounded_value.toString()
			var decimal_location = value_string.indexOf(".")
		if (decimal_location == -1) {
		
			  decimal_part_length = 0
      
				value_string += decimal_places > 0 ? "." : ""
		}
		else {

			 decimal_part_length = value_string.length - decimal_location - 1
		}
    
		var pad_total = decimal_places - decimal_part_length
    
		if (pad_total > 0) {
			for (var counter = 1; counter <= pad_total; counter++) 
				value_string += "0"
		}
		return value_string
	} //pad_with_zeros

// this function is to show the balance character when user is typing
//textObj=textbox object ,allowLength=max character (50) , balShowName = name of the DIV object where it shuold display
function checkLength(textObj,allowLength,balShowName)
{
	var balText=0;
	balText = parseInt(parseInt(allowLength)-parseInt(textObj.value.length));
	var divInfo = document.getElementById(balShowName);
	divInfo.innerHTML='Character Left '+balText;
}

function compareDate(objFromDate,objToDate,errMess){
	var fromdate_array = objFromDate.value.split("/");
	var todate_array = objToDate.value.split("/");
	var fromdate=eval(fromdate_array[2]+fromdate_array[1]+fromdate_array[0]);
	var todate=eval(todate_array[2]+todate_array[1]+todate_array[0]);
	if(todate<fromdate){
		if(errMess!=''){
			alert(errMess);
		}
		objToDate.focus();
		return false;
	}
	return true;
}



	//checking only  number field
	function allowOnlyNumber(val)
	{
	//	var pflag = true;
	//	if (val == "")
	//	{
	//		pflag = true
	//	}
//		if((event.keyCode < 48 || event.keyCode > 57) && ((event.keyCode != 46)||!(pflag)))
		if(event.keyCode < 48 || event.keyCode > 57) 
		{
			event.returnValue = false;
		//	alert("pls enter number only");
		}
	//	if ((event.keyCode == 46))
	//	{
	//		pflag = false
	//	}
		
	}
	
	function allowOnlyNumberForphone()
	{
	    
	
	    if(event.keyCode < 48 || event.keyCode > 57) 
		{
			event.returnValue = false;
		//	alert("pls enter number only");
		}
	
	}
	
//checking only  number field WITH 9 DIGIT AND TWO DECIMAL
	function allowOnlyNumberWithDec(val)
	{
		//	alert(event.keyCode);
		
		if(event.keyCode < 46 || event.keyCode > 57 || event.keyCode == 47)
		{
			event.returnValue = false;
		//	alert("pls enter number only");
		}
			var val2 = val.value
		
			
			if(val2.length >=9 && val2.indexOf(".") == -1 && event.keyCode != 46)
			{
				event.returnValue = false;
			}
		if (event.keyCode == 46)
		{
			var val1 = val.value
			for(i=0;i<val1.length;i++)
			{
				
				if(val1.charAt(i) == ".")
				{
					event.returnValue = false;
				}
			}
			if( event.keyCode == 46 && val1.length == 0)
			{
				val.value = '0';
			}
			
		}
		//event.returnValue = true;
		//alert(val.value );
		//val.setAttribute("onKeyUp","alert('val')");
		//alert(val.getAttribute("onKeyUp"));
		//idval.setAttribute("onKeyUp","javascript: alert('hi');");
	}
	
	
	//allow to decimal only
	function allowTwodecimal(obj)
	{
	    var val = obj.value;
	    if(val.indexOf(".") != -1)
	    {
	       var arrval =val.split('.');
	       if(arrval[1].length > 1 )
	       {
	       	    event.returnValue = false;
	       }
	    }
	}
