/*
	This file will have all the common scripts
*/
<!--
/*
Windows open functions
*/

/* 20 minutes */
var homeURL;
var timeoutMessage;
function setClientTimeout(secureTimeout, url, message, timeout) {
	
	if (secureTimeout == "True") {
		window.setTimeout("homeRedirect()", timeout);
	}
	else {
		homeURL = url;
		timeoutMessage = message;
		window.setTimeout("alertHomeRedirectDrv()", timeout); 
	} 
}

function setMessage(msg, msec)
{
window.status = msg
}

function checkdate(objName) {
	var datefield = objName;
	if (chkdate(objName) == false) {
		datefield.select();
		alert("That date is invalid.  Please try again.");
		datefield.focus();
		return false;
	}
	else {
		return true;
   }
}
function chkdate(objName) {
	var strDatestyle = "US"; //United States date style
	//var strDatestyle = "EU";  //European date style
	var fmtDate = false;
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var datefield = objName;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var err = 0;
	var strMonthArray = new Array(12);
	strMonthArray[0] = "Jan";
	strMonthArray[1] = "Feb";
	strMonthArray[2] = "Mar";
	strMonthArray[3] = "Apr";
	strMonthArray[4] = "May";
	strMonthArray[5] = "Jun";
	strMonthArray[6] = "Jul";
	strMonthArray[7] = "Aug";
	strMonthArray[8] = "Sep";
	strMonthArray[9] = "Oct";
	strMonthArray[10] = "Nov";
	strMonthArray[11] = "Dec";
	strDate = datefield.value;
	if (strDate.length < 1) {
		return true;
	}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) {
				err = 1;
				return false;
			}
			else {
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
		}
	}
	if (booFound == false) {
		if (strDate.length>5) {
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
		}
	}
	if (strYear.length == 2) {
		strYear = '20' + strYear;
	}
	// US style
	if (strDatestyle == "US") {
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}
	intday = parseInt(strDay, 10);
	if (isNaN(intday)) {
		err = 2;
		return false;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) {
		for (i = 0;i<12;i++) {
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
			}
		}
		if (isNaN(intMonth)) {
			err = 3;
			return false;
		}
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) {
		err = 4;
		return false;
	}
	if (intMonth>12 || intMonth<1) {
		err = 5;
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
		err = 6;
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
		err = 7;
		return false;
	}
	if (intMonth == 2) {
		if (intday < 1) {
			err = 8;
			return false;
		}
		if (LeapYear(intYear) == true) {
			if (intday > 29) {
				err = 9;
				return false;
			}
		}
		else {
			if (intday > 28) {
				err = 10;
				return false;
			}
		}
	}
	if(fmtDate) {
		if (strDatestyle == "US") {
			datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
		}
		else {
			datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
		}
	}
	return true;
}

function LeapYear(intYear) {
	if (intYear % 100 == 0) {
		if (intYear % 400 == 0) { return true; }
	}
	else {
		if ((intYear % 4) == 0) { return true; }
	}
	return false;
}

function doDateCheck(from, to) {
	if (Date.parse(from.value) <= Date.parse(to.value)) {
		alert("The dates are valid.");
	}
	else {
		if (from.value == "" || to.value == "") 
			alert("Both dates must be entered.");
		else 
			alert("To date must occur after the from date.");
	}
}

var scrollLock = false;
function homeRedirect()
{
	var toUrl = "Redirect.aspx?rt=sto"
	window.location= toUrl; //"SessionTimeout.htm";
}
function openExcelWindow(url)
{
	window.open(url,"_blank","top=1,left=1,width=" + eval(screen.width)+ ",height=" + eval(screen.height)  + ",scrollbars=yes,resizable=yes,location=no,directories=no,status=yes,menubar=yes,copyhistory=no,toolbar=yes,channelmode=yes");
}
function openReportWindow(url)
{
	newwindow=window.open(url,'name',"resizable=yes,top=1,left=1,width=" + eval(screen.width-50)+ ",height=" + eval(screen.height-150)  + ",scrollbars=yes,location=no,directories=no,status=yes,menubar=yes,copyhistory=no");
	if (window.focus) {newwindow.focus()}
	return false;
}
function openMaxWindow(url)
{
	window.open(url,"popwin","resizable=yes,top=1,left=1,width=" + eval(screen.width-50)+ ",height=" + eval(screen.height-100)  + ",scrollbars=yes,location=no,directories=no,status=yes,menubar=no,copyhistory=no");
}
function openwindow(url)
{
	var pWnd = null;
	pWnd = window.open(url,"popwin","status=no,menubar=yes,resizable=yes,scrollbars=yes,width=600,height=600");
}
function openHelpWindow(url)
{
	var pWnd = null;
	pWnd = window.open(url,"popwin","status=no,menubar=yes,resizable=yes,scrollbars=yes,width=600,height=600");
	return false;
}
	
function goToPage(url)
{
 	if (url != "")
	{
	window.navigate(url);
	}
}

function alertHomeRedirectDrv(){
	alertHomeRedirect(homeURL, timeoutMessage);
}

function alertHomeRedirect(url, message){

	alert(message);
	 
	if (url != ""){
		window.navigate(url);
	}
}
//-->

<!--
/*
	numeric filter and auto tab functions
*/
function filterDigits() 	
{

	if (window.event.keyCode == 13 ) {
		//
	}
	else {
		if (window.event.keyCode<48 || window.event.keyCode >57) {
			window.event.keyCode = 0
		} 
	}
	//alert(window.event.keyCode);
}
 
 
function filterDecimals() 	
{
	if (window.event.keyCode == 13) {
		//
	}
	else {
		if (window.event.keyCode == 45 || window.event.keyCode == 46 ) {
			/*
			if(obj.value.length > 0){
				var ar = new Array();
				ar = obj.value.split('.');
				if(ar.length == 1)
					window.event.keyCode = 0;
			}	
			*/
		}		
		else {
			if (window.event.keyCode<48 || window.event.keyCode >57) {
				window.event.keyCode = 0
			} 
		}
	}
	
}


var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input, len, e, tab_ok) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
		
	if ( keyCode == 13 ) {
		return true
	}
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);		
		
		if ( tab_ok ) {
			if (input.form[(getIndex(input)+1) % input.form.length]) {		
				input.form[(getIndex(input)+1) % input.form.length].focus();
				input.form[(getIndex(input)+1) % input.form.length].select();
			}
		}
	}
	
	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
			if(arr[index] == ele)
				found = true;
			else
				index++;
		return found;
	}
	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
			if (input.form[i] == input)index = i;
			else i++;
			return index;
		}
		return true;
}

/*
Progress bar scripts starts here

// var xyz = createBar(
// total_width,
// total_height,
// background_color,
// border_width,
// border_color,
// block_color,
// scroll_speed,
// block_count,
// scroll_count,
// action_to_perform_after_scrolled_n_times
// )
*/
var w3c=(document.getElementById)?true:false;
var ie=(document.all)?true:false;
var N=-1;

function createBar(w,h,bgc,brdW,brdC,blkC,speed,blocks,count,action){
	if(ie||w3c){
		var t='<div id="_xpbar'+(++N)+'" style="visibility:visible; position:relative; overflow:hidden; width:'+w+'px; height:'+h+'px; background-color:'+bgc+'; border-color:'+brdC+'; border-width:'+brdW+'px; border-style:solid; font-size:1px;">';
		t+='<span id="blocks'+N+'" style="left:-'+(h*2+1)+'px; position:absolute; font-size:1px">';
		for(i=0;i<blocks;i++){
			t+='<span style="background-color:'+blkC+'; left:-'+ ((h*i)+i)+'px; font-size:1px; position:absolute; width:'+h+'px; height:'+h+'px; ';
			t+=(ie)?'filter:alpha(opacity='+(100-i*(100/blocks))+')':'-Moz-opacity:'+((100-i*(100/blocks))/100);
			t+='"></span>';
		}
		t+='</span></div>';
		document.write(t);
		var bA=(ie)?document.all['blocks'+N]:document.getElementById('blocks'+N);
		bA.bar=(ie)?document.all['_xpbar'+N]:document.getElementById('_xpbar'+N);
		bA.blocks=blocks;
		bA.N=N;
		bA.w=w;
		bA.h=h;
		bA.speed=speed;
		bA.ctr=0;
		bA.count=count;
		bA.action=action;
		bA.togglePause=togglePause;
		bA.showBar=function(){
			this.bar.style.visibility="visible";
		}
		bA.hideBar=function(){
		this.bar.style.visibility="hidden";
		}
		bA.tid=setInterval('startBar('+N+')',speed);
		return bA;
	}
}

function startBar(bn){
	var t=(ie)?document.all['blocks'+bn]:document.getElementById('blocks'+bn);
	if(parseInt(t.style.left)+t.h+1-(t.blocks*t.h+t.blocks)>t.w){
		t.style.left=-(t.h*2+1)+'px';
		t.ctr++;
		if(t.ctr>=t.count){
			eval(t.action);
			t.ctr=0;
		}
	}
	else t.style.left=(parseInt(t.style.left)+t.h+1)+'px';
}

function togglePause(){
	if(this.tid==0){
		this.tid=setInterval('startBar('+this.N+')',this.speed);
	}
	else{
		clearInterval(this.tid);
		this.tid=0;
	}
}


/*
Progress bar scripts ends here
*/

clr=new Array('FFDA45','ffffff','silver');

function highlight(state) {
	return "";
	element=event.srcElement;
	if (element.tagName=='INPUT') {
	etype=element.type;
	if ((etype=='submit' || etype=='reset') && state==1)
	state=2;
	element.style.backgroundColor=clr[state];
	}
	if (element.tagName=='TEXTAREA') {
	etype=element.type;
	if ((etype=='submit' || etype=='reset') && state==1)
	state=2;
	element.style.backgroundColor=clr[state];
	}
}


function init(){};
//-->