function Open_Window(PageName,Win_Name, Win_Height, Win_Width)
{
	var winParam = "screenX=10,screenY=10,alwaysRaised,height=" + Win_Height + ",width=" + Win_Width + ",dependent=yes,resizable=yes,scrollbars=yes,directories=no,hotkeys=no,location=no,menubar=no,personalbar=no,status=no,titlebar=no,toolbar=no";		
	var win
	win = window.open(PageName,Win_Name,winParam)
	return false;
}

function setFocus()
{
	var val_count
	val_count = Page_Validators.length;
	for (i=0;i<=val_count;i++)
	{
		if(Page_Validators[i].style.visibility == "visible")
		{
			eval("document.forms[0]." + Page_Validators[i].controltovalidate + ".focus()");
			break;
		}
	}
}

function clickIE() {
	if (document.all) {
	return false;
	}
} 
function clickNS(e) 
{
	if (document.layers||(document.getElementById&&!document.all)) 
	{
		if (e.which==2||e.which==3) 
		{
			return false;
		}
	}
}

if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS;
} 
else{
document.onmouseup=clickNS;
document.oncontextmenu=clickIE;
} 
document.oncontextmenu=new Function("return false")

//end of disabling right click
 
function precision(value, fixpoint){
	return Math.round(value * Math.pow(10,fixpoint)) / Math.pow(10,fixpoint);
}

function y2k(number){return (number < 100) ? number + Math.round((new Date).getYear() /100)*100 : number; }

function PopUpWindow(theight, twidth){
	var winParam = "screenX=10,screenY=10,alwaysRaised,height="+theight+",width="+twidth+",dependent=yes,resizable=yes,scrollbars=yes,directories=no,hotkeys=no,location=no,menubar=no,personalbar=no,status=no,titlebar=no,toolbar=no";
	var hwindow = open("","", winParam);
	hwindow.resizeTo(twidth,theight);
	return hwindow;	
}

function Str2URL(inputval){
	var Rstval="";
	var tmpChar;
	for (var i=0; i<inputval.length; i++){
		tmpChar=inputval.charAt(i);
		if ( (tmpChar>="A" && tmpChar<="Z") || (tmpChar>="a" && tmpChar<="z") || (tmpChar>="0" && tmpChar<="9") ) 
			Rstval = Rstval + tmpChar;
		else
			Rstval = Rstval + "%" + char2hex( inputval.charCodeAt(i) );
	}
	return Rstval;
}

function char2hex(inputval){
	var tmpMap = new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");
	if (inputval==0)
		return "";
	else
		return char2hex(inputval>>8) + "" + tmpMap[((inputval)>>4)%16] + "" + tmpMap[inputval%16];
}

function JSStr2PostData(inputval){
	var Rstval ="" + inputval;
	if (Rstval != "") 
		Rstval = Rstval.replace(/\"/g, "&#34;");
	return Rstval;
}		

function TidyDate(inputday, inputmonth, inputyear){
	var CMonth=["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
	return ((inputday<10)?("0"+inputday):(""+inputday)) + " " + CMonth[inputmonth-1] + " " + inputyear;
}

function TidyTime(inputhour, inputminutes){
	return ((inputhour<10)?("0"+inputhour):(""+inputhour)) + ":" + ((inputminutes<10)?("0"+inputminutes):(""+inputminutes));
}

function CheckDate(inputday, inputmonth, inputyear){
	var test = new Date(inputyear,(inputmonth - 1),inputday);

	if ( inputyear >=100 && inputyear <= 999 ) return false;
	if ( (inputyear < (new Date).getYear()-50) || (inputyear > (new Date).getYear()+49) ) return false;
	if ( (y2k(test.getYear()) == inputyear) && (inputmonth - 1  == test.getMonth()) && (inputday == test.getDate()) )
		return true;
	else
		return false;
}

function CheckTime(inputhour, inputminutes){
	if ((inputhour>=0 && inputhour<=23) && (inputminutes>=0 && inputminutes<=59))
		return true;
	else
		return false;
}

function SaveTime(InputFieldObject){
	var thetime = new Array();
// Check if empty	
	if (InputFieldObject.value == ""){
		//JobFieldFunction("");
		InputFieldObject.defaultValue = InputFieldObject.value;
		return true;
	}
// Data conversion
	if (InputFieldObject.value.search(":") != -1){
		var tmptime = InputFieldObject.value.replace(" ", "");
		thetime = tmptime.split(":");
		thetime[0] = parseInt(thetime[0]);
		thetime[1] = parseInt(thetime[1]);
	}
	else{
		thetime[0] = parseInt(InputFieldObject.value.substr(0,2),10);
		thetime[1] = parseInt(InputFieldObject.value.substr(2,2),10);
	}
// Check Date format	
	if (CheckTime(thetime[0], thetime[1])){
		InputFieldObject.value = TidyTime(thetime[0], thetime[1]);
		//JobFieldFunction( InputFieldObject.value );
		InputFieldObject.defaultValue = InputFieldObject.value;
		return true;
	}
	else{
		if (confirm("Time Syntax Incorrect!\nDo you want to continue without updating?")){
			InputFieldObject.value = InputFieldObject.defaultValue;	
			return true;
		}
		else{
			InputFieldObject.focus();
			return false;
		}
	}
}


function SaveDate(InputFieldObject){

// Check if empty	
	if (InputFieldObject.value == ""){
		//JobFieldFunction("");
		InputFieldObject.defaultValue = InputFieldObject.value;
		return true;
	}
// Data conversion
	var tStr = InputFieldObject.value;
	tStr =tStr.replace("/","");
	tStr =tStr.replace("/","");
	tStr =tStr.replace("/","");
	tStr =tStr.replace("-","");
	tStr =tStr.replace("-","");
	tStr =tStr.replace("-","");

	var day   = parseInt(tStr.substr(0,2),10);
	var month = parseInt(tStr.substr(2,2),10);
	var year  = y2k(parseInt(tStr.substr(4,4),10));

	if ( CheckDate(day, month, year) ){
		InputFieldObject.value = TidyDate(day, month, year);
		InputFieldObject.defaultValue = InputFieldObject.value;
	}
	else{
		tStr = InputFieldObject.value.toUpperCase();
		tStr =tStr.replace("/"," ");
		tStr =tStr.replace("/"," ");
		tStr =tStr.replace("/"," ");
		tStr =tStr.replace("-"," ");
		tStr =tStr.replace("-"," ");
		tStr =tStr.replace("-"," ");

		var NMonth=new Array();
		NMonth['JAN']=1;NMonth['FEB']=2;NMonth['MAR']=3;NMonth['APR']=4;NMonth['MAY']=5;NMonth['JUN']=6;
		NMonth['JUL']=7;NMonth['AUG']=8;NMonth['SEP']=9;NMonth['OCT']=10;NMonth['NOV']=11;NMonth['DEC']=12;
	
		var tmpday = tStr.split(/ /);
		day   = parseInt(tmpday[0],10);
		month = NMonth[tmpday[1]];
		year  = y2k(parseInt(tmpday[2],10));

		if (CheckDate(day, month, year)){
			InputFieldObject.value = TidyDate(day, month, year);
			InputFieldObject.defaultValue = InputFieldObject.value;
		}
		else{
			if (confirm("Date Syntax Incorrect!\nDo you want to continue with original value?")){
				InputFieldObject.value = InputFieldObject.defaultValue;	
				return true;
			}
			else{
				InputFieldObject.focus();
				return false;
			}
		}
	}
	return true;
}


var oldLink = null;
		
function setActiveStyleSheet(link, title) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
	if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
	a.disabled = true;
	if(a.getAttribute("title") == title) a.disabled = false;
	}
}
		if (oldLink) oldLink.style.fontWeight = 'normal';
		oldLink = link;
		link.style.fontWeight = 'bold';
		return false;
		}

		

		// This function gets called when the end-user clicks on some date.
		function selected(cal, date) {
		//alert('Selected');
		cal.sel.value = date; // just update the date in the input field.
//		if (cal.dateClicked && (cal.sel.id == "sel1" || cal.sel.id == "sel2"))
if (cal.dateClicked)
			// if we add this call we close the calendar on single-click.
			// just to exemplify both cases, we are using this only for the 1st
			// and the 3rd field, while 2nd and 4th will still require double-click.
			cal.callCloseHandler();
			//cal.hide();
			
		}
		// And this gets called when the end-user clicks on the _selected_ date,
		// or clicks on the "Close" button.  It just hides the calendar without
		// destroying it.
		function closeHandler(cal) {
		//alert('Rajesh');
		cal.hide();                        // hide the calendar
		cal.destroy();
		calendar = null;
		}

		// This function shows the calendar under the element having the given id.
		// It takes care of catching "mousedown" signals on document and hiding the
		// calendar if the click was outside.
		function showCalendar(id, format, showsTime, showsOtherMonths) {
		var el = document.getElementById(id);
		if(el ==null) el = id;
		if(el ==null) return false;
		
		blResize=1
		if (calendar != null) {
			// we already have some calendar created
			calendar.hide();                 // so we hide it first.
		} else {
			// first-time call, create the calendar.
			var cal = new Calendar(true, null, selected, closeHandler);
			cal.weekNumbers = false;
			// uncomment the following line to hide the week numbers
			// cal.weekNumbers = false;
			if (typeof showsTime == "string") {
			cal.showsTime = true;
			cal.time24 = (showsTime == "24");
			}
			if (showsOtherMonths) {
			cal.showsOtherMonths = true;
			}			
			calendar = cal;    		// remember it in the global var
			cal.setRange(1900, 2070);        // min/max year allowed.
			cal.create();
			
		}
		
		calendar.setDateFormat(format);    // set the specified date format
		calendar.parseDate(el.value);      // try to parse the text in field
		calendar.sel = el;                 // inform it what input field we use
		
		// the reference element that we pass to showAtElement is the button that
		// triggers the calendar.  In this example we align the calendar bottom-right
		// to the button.		
		calendar.showAtElement(el, "Br");        // show the calendar

		return false;
		}

		var MINUTE = 60 * 1000;
		var HOUR = 60 * MINUTE;
		var DAY = 24 * HOUR;
		var WEEK = 7 * DAY;

		function isDisabled(date) {
		var today = new Date();

		return (Math.abs(date.getTime() - today.getTime()) / DAY) > 10;
		}

		function dateStatusHandler(date, y, m, d) {
			//if (dateIsSpecial(y, m, d)) return "special";
			//else return false;
			if (typeof ShowCalendar!=undefined && ShowCalendar==true)
			return false;
			else return true;
			// return true above if you want to disable other dates
		}

		function flatSelected(cal, date) {		
		if(cal.dateClicked==true)		
		window.document.location.href="";
		//document.bw .cursor = "hand";
		//alert(document.body.style.cursor );
		}

		function showFlatCalendar() {
		var parent = document.getElementById("display");

		// construct a calendar giving only the "selected" handler.
		var cal = new Calendar(true, null, flatSelected);
		//cal.setDisabledHandler()
		// hide week numbers
		cal.weekNumbers = false;
		cal.setDateStatusHandler(dateStatusHandler);
		// We want some dates to be disabled; see function isDisabled above
		//cal.setDisabledHandler(isDisabled);
		cal.setDateFormat("%e %B %Y");

		// this call must be the last as it might use data initialized above; if
		// we specify a parent, as opposite to the "showCalendar" function above,
		// then we create a flat calendar -- not popup.  Hidden, though, but...
		cal.create(parent);

		// ... we can show it here.
		cal.show();
		}


