//************************* Useful Functions ******************************************
	
	function OpenWin(url)
	{	
		window.open(url,'win','scrollbars=0,status=0,resizable=0,width=200,height=265');	
	}

	function DecodeHTML(strIN)
	{
		var strDecoded = strIN
		if(strDecoded != ""){
			strDecoded = strDecoded.replace(/&nbsp;/gi, " ")
			strDecoded = strDecoded.replace(/&amp;/gi, String.fromCharCode(38))
			strDecoded = strDecoded.replace(/&quot;/gi, String.fromCharCode(34))
			strDecoded = strDecoded.replace(/&lt;/g, String.fromCharCode(60))
			strDecoded = strDecoded.replace(/&gt;/gi, String.fromCharCode(62))
			strDecoded = strDecoded.replace(/&euro;/gi, String.fromCharCode(128))	
			strDecoded = strDecoded.replace(/&lsquo;/gi, String.fromCharCode(145))
			strDecoded = strDecoded.replace(/&rsquo;/gi, String.fromCharCode(146))
			strDecoded = strDecoded.replace(/&ldquo;/gi, String.fromCharCode(147))
			strDecoded = strDecoded.replace(/&rdquo;/gi, String.fromCharCode(148))
			strDecoded = strDecoded.replace(/&pound;/gi, String.fromCharCode(163))	
			strDecoded = strDecoded.replace(/&frac14;/gi, String.fromCharCode(188))	
			strDecoded = strDecoded.replace(/&frac12;/gi, String.fromCharCode(189))
			strDecoded = strDecoded.replace(/&frac34;/gi, String.fromCharCode(190))	
				
			arr=strDecoded.match(/&#[0-9]{1,5};/g)
		
			if(arr!=null){
				for(var x=0;x<arr.length;x++){
					sMatch = arr[x]
					intChr = sMatch.substring(2,sMatch.length-1)
				
					if(intChr >= -32768 && intChr <= 65535){
						strDecoded = strDecoded.replace(sMatch, String.fromCharCode(intChr))
					}else{
						strDecoded = strDecoded.replace(sMatch, "")
					}
				}			
			}	
		}else{
			strDecoded = "";
		}
				
		return strDecoded;
	}
	
	function getDate(bShowTime){
		var dtDate, dtTime
		var currentTime = new Date()
		var month = currentTime.getMonth() + 1
		var day = currentTime.getDate()
		var year = currentTime.getFullYear()
		
		dtDate = day + "/" + month + "/" + year

		if (bShowTime)
		{
		
			var hours = currentTime.getHours()
			var minutes = currentTime.getMinutes()
			if (minutes < 10)
				minutes = "0" + minutes
			dtTime = hours + ":" + minutes + " "	
			if(hours > 11){
				dtTime += "PM"
			} else {
				dtTime +="AM"	
			}

			dtDate +=  " " + dtTime
		}

		return dtDate
	}
	
	
	function getElementStyle(elemID, IEStyleProp, CSSStyleProp) {
		var elem = document.getElementById(elemID);
		if (elem.currentStyle) {
			return elem.currentStyle[IEStyleProp];
		}else if (window.getComputedStyle) {
			var compStyle = window.getComputedStyle(elem, "");
			return compStyle.getPropertyValue(CSSStyleProp);
		}
		return "";
	}

	
	function RemoveMSWord(strHTML){

		var strCleanHTML = strHTML

		strCleanHTML = strCleanHTML.replace(/\<xml[\s\S]+?\<\/xml\>/gi, "")		
		strCleanHTML = strCleanHTML.replace(/<[/]?(font|span|xml|del|ins|[ovwxp]:\w+)[^>]*?>/gi,"")
		strCleanHTML = strCleanHTML.replace(/<([^>]*)(?:class|lang|style|size|face|[ovwxp]:\w+)=(?:'[^']*'|""[^""]*""|[^>]+)([^>]*)>/gi,"<$1$2>")
		strCleanHTML = strCleanHTML.replace(/<([^>]*)(?:class|lang|style|size|face|[ovwxp]:\w+)=(?:'[^']*'|""[^""]*""|[^>]+)([^>]*)>/gi,"<$1$2>")
		strCleanHTML = strCleanHTML.replace(/\<style[\s\S]+?\<\/style\>/gi, "")
		//remove MS conditionals	
		strCleanHTML = strCleanHTML.replace(/<!\[if !supportEmptyParas\]>/gi,"")
		strCleanHTML = strCleanHTML.replace(/<!\[endif\]>/gi,"")		
		strCleanHTML = strCleanHTML.replace(/<!--\[if gte mso 9\]>/gi,"")
		strCleanHTML = strCleanHTML.replace(/<!\[endif\]-->/gi,"")				
		//Sort out spaces before > tags eg <p >
		strCleanHTML = strCleanHTML.replace(/ >/gi,">")
		//sort out empty lines
		strCleanHTML = strCleanHTML.replace(/[\r\n][\r\n\t]*[\r\n]/gi,"\r\n")			

		return strCleanHTML
	}



	function GetEndNumerics(strIN){
		
		var strOut = strIN.match(/\d*$/)

		return strOut

	}

	function ReplaceEndNumerics(strIN){
		
		var strOut = strIN.replace(/\d*$/, "")

		return strOut

	}


	
	//loop through all elements on form giving name/id/type
	function FormInfo(f, bInOneMsg){
		var e, strMsg, elInfo;
		
		for(var x=0;x<f.elements.length;x++){
			e = f.elements[x];
	
				var id = e.id	
				
				elInfo = "name= " + e.name + " id= " + e.id + " type= " + e.type + " value=" + e.value

				if(bInOneMsg){
					strMsg += elInfo + '\n'
				}else{
					alert(elInfo)			
					}
	
		}
		
		if(bInOneMsg){
			alert(strMsg);
		}
		return false;
	}

	//will return the number of options selected in a multiple select list box
	function NoSelected(obj){
		alert("in NoSelected")
		var nSel = 0;

		if (obj!=null && obj.options!=null){
			for (var i=0; i<obj.options.length; i++) {
				if(obj.options[i].selected == true){
					nSel ++
				}
			}
		}
		alert("return " + nSel)
		return nSel;
	}
	
	// Will deselct all other options in a list if the Any/All selection is chosen
	function selChk(me){
		//alert("in selChk")
		
		var x;
		var bAny = false;
		//if no Any selection then function not needed
		if(me.options[0].value!=""){		
			return
		}
		//option[0] is Any
		//if Any selected then deselect everything else
		if(me.options[0].value=="" && me.options[0].selected==true){
			for(x=1;x<me.length;x++){
				me.options[x].selected=false;
			}	
		}
	}
	
	function checkNumber( e )
	{	//allows 0123456789
		var key = (window.event) ? event.keyCode : e.which;
		if ((key<48)||(key>57))
		{
			if (window.event) //IE
				window.event.returnValue = null;
			else //Firefox
				e.preventDefault();
		}
	}



	function NumCharMask()
	{
		var i = window.event.keyCode;
		//alert("key " + i + " hit")
		var bOK = false;
		if (!window.event.ctrlKey && !window.event.shiftKey)
		{

			if ( i == 9 ||					// TAB key
				i == 8 ||					// Backspace key
				i == 36 ||					// Home key
				i == 35 ||					// End key
				i == 39 ||					// Right Arrow
				i == 37 ||					// Left Arrow
				i == 189 ||					// minus key
				i == 46 ||					// Delete Key
				//i == 190 ||					// Period
				(i >= 48 && i <= 57) ||		// Top row 0 to 9
				(i >= 96 && i <= 105))		// Number pad 0 to 9
				bOK = true;
		}else{
			bOK = false;	
		}

		if (!bOK)
			window.event.returnValue = false;     // Cancel keystroke
	}

	function SalCharMask(e, v)
	{
		
		var key = (window.event) ? event.keyCode : e.which;

		var evtobj	= window.event? event : e

		//alert("key " + key + " hit")
		var bOK = false;
		/*if (!window.event.ctrlKey && !window.event.shiftKey)
		{	*/		
		if(!evtobj.ctrlKey && !evtobj.shiftKey)
		{
		
			/*
			if ( i == 9 ||					// TAB key
				i == 8 ||					// Backspace key
				i == 36 ||					// Home key
				i == 35 ||					// End key
				i == 39 ||					// Right Arrow
				i == 37 ||					// Left Arrow
				i == 189 ||					// minus key
				i == 46 ||					// Delete Key
				(i == 190 && v.indexOf('.')==-1 )
				)|| // Period
				(v <=10000000 && 
					(
						(i >= 48 && i <= 57) ||		// Top row 0 to 9
						(i >= 96 && i <= 105)		// Number pad 0 to 9	
					)
				)				
			*/
			if( (	key == 9 || 
					key == 8 || 
					key == 36 ||
					key == 35 || 
					key == 39 || 
					key == 37 || 
					key == 189 || 
					key == 46 || 
					((key == 190 || key == 110) && v.indexOf('.')==-1 ) 
				) || 
					(v <9999999 && 
						(
							(key >= 48 && key <= 57) ||	
							(key >= 96 && key <= 105)
						)
					)   
				)
				bOK = true;
			
		}else{
			bOK = false;	
		}

		if (!bOK){
			if (window.event){ 
				window.event.returnValue = null;				
			}else{ 
				e.preventDefault();				
			}
		}
		
	}

	function Len(str){ 
		
		return String(str).length; 
	
	}

	function Trim(str){
		
		var x;
		x = LTrim(RTrim(str));
		return x;
    
    	}

	
	function LTrim(v){

		while(''+v.charAt(0)==' '){
			v=v.substring(1,v.length);
		}
		
		return v;

	}

	function RTrim(v){
		
		while(''+v.charAt(v.length-1)==' ')
		{
			v= v.substring(0,v.length-1);
		}

		return v;

	}

	function MTrim(v){
	
		//remove all spaces between characters
		string = v;
		var mySeparator = " ";
		var x  = string.split(mySeparator);
		if(x == null){//if no parts then error
			err = 1;
		}
		//regroup no into one string
		tempstring = "";
		for(var i=0; i<x.length; i++){
			if(x[i]!=" ")
				tempstring = tempstring + x[i]
		}
	
		return tempstring;

	}

	function Left(str, n) {
		
		if (n <= 0)    
			return "";
        	else if (n > String(str).length)   
            		return str;               
        	else 
           		return String(str).substring(0,n);
        }

	function Right(str, n) {
		if (n <= 0)    
            		return "";
        	else if (n > String(str).length)  
            		return str;                    
        	else { 
	       		var iLen = String(str).length;
            		return String(str).substring(iLen, iLen - n);
        	}
    	}

	function Mid(str, start, len){
   
		if (start < 0 || len < 0) return "";

       		var iEnd, iLen = String(str).length;
	        if (start + len > iLen)
            	iEnd = iLen;
	        else
				iEnd = start + len;

        	return String(str).substring(start,iEnd);
    	}

	function InStr(strSearch, charSearchFor){
		//searchs for a character within a string
		
		for (x=0; x < Len(strSearch); x++)
		{
		    if (charSearchFor == Mid(strSearch, x, 1))
		    {
				return x;
		    }
		}
		
		return -1;
	
	}


function Find(strSearch, charSearchFor, x){
		//searches for a word within a string
		//x is length of string to find 
		//alert("passed in SearchString=" + strSearch + " SearchFor=" + charSearchFor + " Length=" + x)
		
		for (i=0; i < Len(strSearch); i++)
		{
		    if (charSearchFor == Mid(strSearch, i, x))
		    {				
				return i;				
		    }
		}
	
		return -1;
	
	}
	
	
function Find_Block(strSearch, Block, Block_len)
{
	
	for(i=0;i<Len(strSearch);i++)
	{
		
		result = Mid(strSearch, i, Block_len)
	
		if(result==Block)
		{
			
			var pos = i
			
			if(strSearch.substring((pos-1,pos)==",")||(strSearch.substring(pos-1,pos)==""))
			{
				if(strSearch.substring(pos+Block_len, (pos+Block_len+1))==","||strSearch.substring(pos+Block_len, (pos+Block_len+1))=="")
				return i;			
			}
						
		}
				
	}		
	//could not find block
	return -1;
}



//********************************************************************************************

function Remove(v, r){
	
		//remove all passed in chars from string
		string = v;
		var mySeparator = r;
		var x  = string.split(mySeparator);
		if(x == null){//if no parts then error
			err = 1;
		}
		//regroup no into one string
		tempstring = "";
		for(var i=0; i<x.length; i++){
			if(x[i]!=" ")
				tempstring = tempstring + x[i]
		}
	
		return tempstring;
	
	}

//********************************************************************************************


	function CountNoOf(s, v){
		//counts no of times a char appears in a string
		
		string = s;
		count = 0;
		var a;
		for (var i=0; i< string.length; i++) {
			a = string.substring(i, i+1);
			if(a == v) count ++;
		}
		
		return count;
	
	}

function CheckNumeric(No){

	//checks to see if string is made up from valid numeric characters
		
		var err=0;
		var valid = "0123456789";
		var temp;		
		for (var i=0; i<No.length; i++) {
			temp = "" + No.substring(i, i+1);
			if (valid.indexOf(temp) == "-1") err = 1;
		}
		
		if (err==1) {		
			return false;
		}
		else {
			return true;
			}
}

function CheckText(str){

	//checks to see if string is made up from valid numeric characters
		
		var err=0;
		var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ -";
		var temp;		
		for (var i=0; i<str.length; i++) {
			temp = "" + str.substring(i, i+1);
			if (valid.indexOf(temp) == "-1") err = 1;
		}
		
		if (err==1) {		
			return false;
		}
		else {
			return true;
			}
}
//************************ End of Useful Functions *************************************

function highlight(c){	
	eval('document.all.'+c+'.bgColor="LightSteelBlue"');
	//eval('document.all.'+c+'.style.color="blue"');		
}
function highlightoff(c){
	eval('document.all.'+c+'.bgColor="SteelBlue"');	
}
function select(page){
	parent.Main.location.href = page;
}