/* READ ME!
 
 -- DO NOT USE THIS FILE for site specific code -- 

This file is for general functions which can be used in any website.
 
 */


//#######################################################################################'
//---------------------------------------------------------------------------------------'
//eventTarget:: Provide a single interface for the event source element reference that triggered an event, namely eventTarget
//eventKeyPress:: Provide a single interface for the event response for keypress because NS is shit
//This is becuase of browser incompatability issues
//variables
var is = new Is();
var eventTarget = null;
var eventKeyCode = null;
//capture target events
(is.nav)?window.onmousedown=getEventTarget:document.onmousedown=getEventTarget;
(is.nav)?window.captureEvents(Event.MOUSEDOWN):0;
//capture keydown events
(is.nav)?window.onkeydown=getEventKeyCode:document.onkeydown=getEventKeyCode;
(is.nav)?window.captureEvents(Event.KEYPRESS):0;
//functions
//---------------------------------------------------------------------------------------'
//This function detects what type of browser is in use...
function Is ()
{
var agt=navigator.userAgent.toLowerCase();
this.major = parseInt(navigator.appVersion);
this.nav = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1)));
this.nav4 = (this.nav && (this.major == 4));
this.nav4up = this.nav && (this.major >= 4);
this.ie = (agt.indexOf("msie") != -1);
this.ie4 = (this.ie && (this.major == 4));
this.ie4up = this.ie && (this.major >= 4);
this.opera = (agt.indexOf("opera") != -1);
this.ff = (agt.indexOf("firefox") != -1);
}
//---------------------------------------------------------------------------------------'
//This function returns the event source element reference
function getEventTarget(e){
	eventTarget=is.nav ? e.target:window.event.srcElement;
}
//---------------------------------------------------------------------------------------'
//This function returns the event source element reference
function getEventKeyCode(e){
	eventKeyCode=is.nav ? e.which:window.event.keyCode;
}
//---------------------------------------------------------------------------------------'
var ymouse;
var xmouse;
function Mouse(evnt){
	if (is.ie) {
		ymouse = window.event.y;
		xmouse = window.event.x;
	} else {
		ymouse = evnt.pageY;
		xmouse = evnt.pageX;
	};
}
//---------------------------------------------------------------------------------------'
function iniMouse() {
	var browser = navigator.appName;
	if (is.ie) {
		document.onmousemove=Mouse;
	} else {
		window.onmousemove=Mouse;
		window.captureEvents(Event.MOUSEMOVE);
	};
}
//---------------------------------------------------------------------------------------'
//#######################################################################################'



//---------------------------------------------------------------------------------------'
//open the popup window...
function fncGL_PopWin(strPage, strName) {
	//window.name = "a name for the current window...";
	var windowprops = "height=600,width=760,location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes";
	var myPopup = window.open(strPage, strName, windowprops);
    if (!myPopup.opener) 
		myPopup.opener = window.self; 
}
//---------------------------------------------------------------------------------------'
//To find an element of a form...
function fnc_FormElm(strName) {
	var browser = navigator.appName;
	if (is.ie) {
		//Opera and MSIE both work as per W3C DOM...
		//note: Opera also comes out as == "Microsoft Internet Explorer"
		return document.all(strName);
	} else {
		//I hate Netscape
		var icFrm = window.document.forms.length;
		var icElm = 0;
		for (iFrm = 0; iFrm < icFrm; iFrm++) {
			icElm = window.document.forms[iFrm].elements.length;
			for (iElm = 0; iElm < icElm; iElm++) {
				if (window.document.forms[iFrm].elements[iElm].id == strName) {
					return window.document.forms[iFrm].elements[iElm];
				} else if (window.document.forms[iFrm].elements[iElm].name == strName) {
					return window.document.forms[iFrm].elements[iElm];
				};
			};
		};
		return window.document.getElementById(strName);
	};
}
//---------------------------------------------------------------------------------------'
//To submit a button on a form...
function btnSubmit(strName) {
	fnc_FormElm(strName).click();
	fnc_displayPleaseWait();
	window.event.returnValue = false;
	return false;
}
//---------------------------------------------------------------------------------------'
//To submit a button with a value
function btnSubmitV(strName, strValue) {
	fnc_FormElm(strName).value = strValue;
	fnc_FormElm(strName).click();
	fnc_displayPleaseWait();
	window.event.returnValue = false;
	return false;
}
//---------------------------------------------------------------------------------------'
//To submit a button with a value asp work around for
function btnSubmitT(strName, strIndex) {
	
	fnc_FormElm("txt" + strName + "Change").value = strIndex;
	fnc_FormElm("txt" + strName + "New").value = fnc_FormElm("txt" + strName + "_" + strIndex).value;
	fnc_FormElm("btn" + strName + "Change").click();
	fnc_displayPleaseWait();
	window.event.returnValue = false;
	return false;
}
//---------------------------------------------------------------------------------------'
//To submit a button with a value asp work around for
function btnSubmitL(strName, strIndex) {
	fnc_FormElm("txt" + strName + "Click").value = strIndex;
	fnc_FormElm("btn" + strName + "Click").click();
	fnc_displayPleaseWait();
	window.event.returnValue = false;
	return false;
}
//---------------------------------------------------------------------------------------'
//To test whether a tag with the name/id exists in the current document
function jsObjectExists(strName) {
	
	try {
		var oObject = document.all.namedItem(strName);
	}
	catch(er) {
		var oObject = document.all(strName);
	}
	
	if (oObject != null){
		return 1;
	}else{
		return 0;
	}
}
//---------------------------------------------------------------------------------------'
function IsNumeric(strString)
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;
   if (strString.length == 0) return false;
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}
//---------------------------------------------------------------------------------------'
//for dd/mm/yyyy
function IsDate(strDate) {
	var year, month, day, arrDate;
	var tempDate;
	if (strDate.length != 10) return false;
	
	//get the parts of the date
	arrDate = strDate.split("/");
	if (arrDate.length != 3) return false;
	day = arrDate[0];
	month = arrDate[1];
	year = arrDate[2];
	
	//Check the parts of the date
	if(IsNumeric(day) == false) return false;
	if(IsNumeric(month) == false) return false;
	if(IsNumeric(year) == false) return false;
	
	// month argument must be in the range 1 - 12
	month = month - 1; // javascript month range : 0- 11
	
	tempDate = new Date(year,month,day);
	if ( (year == tempDate.getFullYear()) && (month == tempDate.getMonth()) &&	(day == tempDate.getDate()) )
		return true;
	else
		return false;
}
//---------------------------------------------------------------------------------------'
//for dd/mm/yyyy
function CDate(strDate, dtmDate) {
	var year, month, day, arrDate;
	if (strDate.length != 10) return false;
	
	//get the parts of the date
	arrDate = strDate.split("/");
	if (arrDate.length != 3) return false;
	day = arrDate[0];
	month = arrDate[1];
	year = arrDate[2];
	
	//Check the parts of the date
	if(IsNumeric(day) == false) return false;
	if(IsNumeric(month) == false) return false;
	if(IsNumeric(year) == false) return false;
	
	// month argument must be in the range 1 - 12
	month = month - 1; // javascript month range : 0- 11
	dtmDate = new Date(year,month,day);
	return dtmDate;
}
//---------------------------------------------------------------------------------------'
//for dd/mm/yyyy
function DateDiff(strDate1, strDate2) {
	var dtmDate1, dtmDate2;
	dtmDate1 = CDate(strDate1);
	dtmDate2 = CDate(strDate2);
	if (dtmDate1.getFullYear() < dtmDate2.getFullYear()) {
		return 1;
	} else if (dtmDate1.getFullYear() > dtmDate2.getFullYear()) {
		return -1;
	} else if (dtmDate1.getMonth() < dtmDate2.getMonth()) {
		return 1;
	} else if (dtmDate1.getMonth() > dtmDate2.getMonth()) {
		return -1;
	} else if (dtmDate1.getDate() < dtmDate2.getDate()) {
		return 1;
	} else if (dtmDate1.getDate() > dtmDate2.getDate()) {
		return -1;
	} else {
		return 0;
	}
}
//---------------------------------------------------------------------------------------'
//A generic funciton to hide the page whilst doing a submit
function fnc_displayPleaseWait() {
	//Do what you want to do....
}
//---------------------------------------------------------------------------------------'
