// window.onerror = handleError;

// -- Toggle to true or false, if you want to change what is checked in the password
var bCheckNumbers = true;
var bCheckUpperCase = true;
var bCheckLowerCase = true;
var bCheckPunctuation = true;
var nPasswordLifetime = 30;

var validNums = '0123456789.';
var validInt = '0123456789';
var validScaling = '0123456789-.';
var validLetters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
var blnIsStartEnabled=true;
var blnIsEndEnabled=true;
var blnDoEnableRadio=false;

var strLastCeilingFloor = '';
var lastCeilingValue='';
var lastFloorValue='';

var units = new Array ("Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen");
var tens = new Array ("Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety");

// regular expressions
var lc = /[a-z]{1}/; // lowercase letters
var uc = /[A-Z]{1}/; // uppercase letters
var nm = /[0-9]{1}/; // numbers
var un = /[^A-Za-z0-9]{1}/; // upper- and lower-case letters and numbers

function SetSelectToAnOption(passedSelect, passedOption) {
	var SelectChoice = document.getElementById(passedSelect);
	for (var i=0;i<SelectChoice.options.length;i++) {
	    if (SelectChoice.options[i].value == passedOption)
	    {
	        SelectChoice.options[i].selected = true;
	        return true;
	    }
	}
	return false;
}
		
function checkStrength() {
	var pwd = document.getElementById("PasswordCheck").value;
	var fnm = new RegExp(document.getElementById("Username").value,'gi');
	var eml = new RegExp(document.getElementById("EmailAddress").value,'gi');
	var score = 0;
	if (pwd.length < 6) return score;
	score += pwd.length - 6;
	if (pwd.match(lc) && pwd.match(uc)) score++;
	if (pwd.match(nm) && (pwd.match(lc) || pwd.match(uc))) score++;
	if (pwd.match(un)) score++;
	if (pwd.match(fnm)) score = 0;
	if (pwd.match(eml)) score = 0;
	return score;
}

function showScore() {
	
	var score =  checkStrength();
	
	 // Get controls
    	var ctlBar = document.getElementById("PasswordCheck_bar"); 
    	var ctlText = document.getElementById("PasswordCheck_text");
    	if (!ctlBar || !ctlText)
    		return;

	if (score > 10)
	 	score = 10;
    	ctlBar.style.width = (score * 10) + "%";

 	// Color and text
 	if (score > 6)
 	{
 		strText = "Very Secure";
 		strColor = "#3bce08";
 	}
 	else if (score > 4)
 	{
 		strText = "Secure";
 		strColor = "orange";
	}
 	else if (score > 2)
 	{
 		strText = "Mediocre";
 		strColor = "#ffd801";
 	}
 	else
 	{
 		strColor = "red";
 		strText = "Insecure";
 	}
	ctlBar.style.backgroundColor = strColor;
	ctlText.innerHTML = "<span style='color: " + strColor + ";'>" + strText + "</span>";
}

function NumberToWord(it) {
	var theword = "";
	var started;
	if (it>999) return "Lots";
	if (it==0) return units[0];
	for (var i = 9; i >= 1; i--) {
		if (it>=i*100) {
			theword += units[i];
			started = 1;
			theword += " hundred";
			if (it!=i*100) theword += " and ";
				it -= i*100;
				i=0;
		}
	};

	for (var i = 9; i >= 2; i--) {
		if (it>=i*10) {
			theword += (started?tens[i-2].toLowerCase():tens[i-2]);
			started = 1;
			if (it!=i*10) theword += "-";
				it -= i*10;
				i=0
		}
	};

	for (var i=1; i < 20; i++)  {
		if (it==i) 	{
			theword += (started?units[i].toLowerCase():units[i]);
		}
	};
	return theword;
}

function FindSameNameInAll ()
{
	var tmpMessage = "";
	var blnResult = true;
	for (var i=0;i <= 100;i++)
	{
		if (blnResult == true) {
	  		fldObj = document.getElementById('Field'+i+'Name');
	  		if (fldObj != null) {
				for (var z=0;z <= 100;z++)
				{
					fldObjInner = document.getElementById('Field'+z+'Name');
					if (fldObjInner != null) {
						if (i != z) {
							if ((fldObj.value == fldObjInner.value) && fldObj.value == '') {
							}
							else
							{
								if (fldObj.value == fldObjInner.value) {
									alert('Sorry, but the Name in;\n\n        Field '+NumberToWord(i)+';\n\n.... is the same as the Name in;\n\n        Field '+NumberToWord(z)+'\n\n.... so your attempt to update the configuration has been cancelled as two fields cannot have the same name.');
									blnResult = false;
									break;
								}
							}
						}
					}
				}
	  		}
	  		else {
	  			break;
	  		}
	  	}
	  	else {
	  		break;
	  	}
	  	
	}
	return blnResult;
}

function FindAllVariationMonitoring ()
{
	// First - save the default selected on each select
	fldObj = document.getElementById('VMDOne');
	var intFirstSelected = fldObj.options[fldObj.selectedIndex].value;
	fldObj = document.getElementById('VMDTwo');
	var intSecondSelected = fldObj.options[fldObj.selectedIndex].value;	
	// Clear each select
	fldObj = document.getElementById('VMDOne');
	fldObj.length = 0;
	fldObj = document.getElementById('VMDTwo');
	fldObj.length = 0;	
	// Build each select
	var tmpStringVariationMonitoring = "";
	var intCount = 0;
	var tmpStringFieldName = "";
	for (var i=0;i <= 100;i++)
	{
  		fldObj = document.getElementById('Field'+i+'String');
  		if (fldObj != null) {
  			if (fldObj.value == 'Variation Monitoring')
  			{
		  		fldObj = document.getElementById('Field'+i+'Name');
		  		if (fldObj != null) {
  					tmpStringVariationMonitoring += i+','+fldObj.value+'|';
  					tmpStringFieldName = fldObj.value;
  					if (tmpStringFieldName != "")
  					{
						fldObj = document.getElementById('VMDOne');
  						fldObj.options[intCount] = new Option(tmpStringFieldName,i);
						fldObj = document.getElementById('VMDTwo');
  						fldObj.options[intCount] = new Option(tmpStringFieldName,i);
  						intCount++;
  					}		  			
		  		}
  			}
  		}
	}
    	var ctlText = document.getElementById("CurrentVariationMonitoring_Text");
    	if ( !ctlText )
    		return;
    	if (intCount >= 2)
    	{
    	   document.getElementById('VariationMonitoring').style.display = "block";
    	}
    	else
    	{
    	   document.getElementById('VariationMonitoring').style.display = "none";
    	}
	strColor = "#000000";
	ctlText.innerHTML = "<span style='color: " + strColor + ";'>" + tmpStringVariationMonitoring + "</span>";
	
	if ( SetSelectToAnOption( 'VMDOne' , intFirstSelected ) == false )
	{
		SetSelectToAnOption( 'VMDOne' , 0 )
		alert('Be aware! You must have deleted the input that you were using as the first feed so it has been set to the first input.\r\This might NOT be right so make sure that you go back and select the, new, correct first feed.\r\r\rFailure to do as suggested could result in invalid alerts being sent!');
	}
	if ( SetSelectToAnOption( 'VMDTwo' , intSecondSelected ) == false )
	{
		SetSelectToAnOption( 'VMDTwo' , 0 )
		alert('Be aware! You must have deleted the input that you were using as the second feed so it has been set to the first input.\r\This might NOT be right so make sure that you go back and select the, new, correct second feed.\r\r\rFailure to do as suggested could result in invalid alerts being sent!');
	}
}

function pauseJava(millis) 
{
	var date = new Date();
	var curDate = null;

	do 
	{
		curDate = new Date(); 
	} 
	while(curDate-date < millis);
} 

function selectAll (isType)
{
	var tmpMessage;
		tmpMessage = "Started..";
	for (var i=0;i < document.display.elements.length;i++) 
	{
  		fldObj = document.display.elements[i];
  		if (fldObj.type.indexOf("select") != -1) 
  		{
  			if (fldObj.name.indexOf("alert") == -1) 
  			{
     			if (isType == -1) 
     			{
     				if (fldObj.value == "False")
     				{
     					if (document.display.elements[i].selectedIndex == 1) {
     						fldObj.selectedIndex = 0;
     						}
     					else {
     						fldObj.selectedIndex = 1;     						
     						}
        			}
        		}
	     		else 
	     		{
     				if (fldObj.value == "True")
     				{
     					if (fldObj.selectedIndex == 1) 
     					{
     						fldObj.selectedIndex = 0;
     					}
     					else 
     					{
     						fldObj.selectedIndex = 1;     						
     					}
        			}
     			}
     		}
		}
	}
	if (isType == -1) {
		alert ("You have now turned on all Alerts");
		}
	else {
		alert ("You have now turned off all Alerts");
		}		
}

//-- This is a function that sets all Lengths to 0
function selectAllLength (isType)
{
	for (var i=0;i < document.display.elements.length;i++)
	{
  		fldObj = document.display.elements[i];
  		if (fldObj.type.indexOf("text") != -1)
  		{
  			if (fldObj.name.indexOf("Length") != -1)
  			{
     			if (isType == -1)
     			{
     				fldObj.value='0';
        		}
     		}
		}
	}
	if (isType == -1) {
		alert ("You have now set all LENTGH values to 0");
		}
	else {
		alert ("Unknown operation on LENGTH values");
		}		
}
//-- This is a function that sets all Value to 0
function selectAllValue (isType)
{
	for (var i=0;i < document.display.elements.length;i++)
	{
  		fldObj = document.display.elements[i];
  		if (fldObj.type.indexOf("text") != -1)
  		{
  			if (fldObj.name.indexOf("Value") != -1)
  			{
     			if (isType == -1)
     			{
     				fldObj.value='0';
        		}
     		}
		}
	}
	if (isType == -1) {
		alert ("You have now set all VALUE values to 0");
		}
	else {
		alert ("Unknown operation on VALUE values");
		}		
}
//-- This is a function that sets all upper values to nothing
function selectAllUpper (isType)
{
	for (var i=0;i < document.display.elements.length;i++)
	{
  		fldObj = document.display.elements[i];
  		if (fldObj.type.indexOf("text") != -1)
  		{
  			if (fldObj.name.indexOf("Upper") != -1)
  			{
     			if (isType == -1)
     			{
     				fldObj.value='';
        		}
     		}
		}
	}
	if (isType == -1) {
		alert ("You have now set all UPPER values to nothing");
		}
	else {
		alert ("Unknown operation on UPPER values");
		}		
}
//-- This is a function that sets all lower values to nothing
function selectAllLower (isType) {
	for (var i=0;i < document.display.elements.length;i++) {
  		fldObj = document.display.elements[i];
  		if (fldObj.type.indexOf("text") != -1) {
  			if (fldObj.name.indexOf("Lower") != -1) {
     			if (isType == -1) {
     				fldObj.value='';
        		}
     		}
		}
	}
	if (isType == -1) {
		alert ("You have now set all Lower values to nothing");
		}
	else {
		alert ("Unknown operation on Lower values");
		}		
}

<!-- Use one function for multiple text areas on a page -->
<!-- Limit the number of characters per textarea -->
<!--
function textCounter(field,maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
}

function GetClone()
{
	// var l = window.screen.width;
	// var l = l / 4;
	// t = window.screen.height;
	// t = t / 4;
	// window.open('SDL.asp?D='+passedDeviceID+'&U='+passedUniqueId+'&O='+passedOperation,'','toolbar=no,scrollbars=yes,width='+l*2+',height='+t+',top='+t*2+',left='+t+',addressbar=no');
	// window.open('GetClone.asp','Clone this entry','status=yes,location=no,toolbar=no,directories=no,scrollbars=yes,resizable=yes,width=300,height=400,top=50,left=200',true);
}

function randomPassword()
{
  chars = "1234567890";
  pass = "";
  var length = 12;
  for(x=0;x<length;x++)
  {
    i = Math.floor(Math.random() * 10);
    pass += chars.charAt(i);
  }
  document.display.TemporaryPassword.value = pass;
  document.display.ValidateTemporaryPassword.value = pass;
  if ( document.display.TemporaryUser.value == '' ) {
  	alert('You don\'t have a Temporary User Name entered yet... don\'t forget it or the update will be ignored\n\nDon\'t forget to note the password as displayed so that you can give it to the client\n\nThe password being displayed is '+pass);
  } else {
  	alert('Don\'t forget to note the password as displayed so that you can give it to the client\n\nThe password being displayed is '+pass);
  }
}

function PopItUp() {
	PopItUpDetailsWindow=window.open('','PopItUpDetails','height=400,width=600');
	var docWindow = PopItUpDetailsWindow.document;
	docWindow.write('<html><head><title>Copy this information and send it to your user</title>');
	docWindow.write('</head><body><p></p>');
	docWindow.write('<p>Username: '+document.getElementById('TemporaryUser').value+'</p>');
	docWindow.write('<p>Email: '+document.getElementById('TemporaryUserEmail').value+'</p>');
	docWindow.write('<p>Mobile: '+document.getElementById('TemporaryUserMobile').value+'</p>');
	docWindow.write('<p>Alert Destination: '+document.getElementById('TemporaryUserAlertDestination').value+'</p>');
	if ((document.getElementById('TemporaryPassword').value != '****************') && (document.getElementById('TemporaryPassword').value != '')) {
		docWindow.write('<p>Password: '+document.getElementById('TemporaryPassword').value+'</p>');
	}
	docWindow.write('<p></p>');
	docWindow.write('<p><a href="javascript:self.close()">Close</a>.</p>');
	docWindow.write('</body></html>');
	docWindow.close();
}

function CloneNotify() {
var strNotified = document.display.CloneNotified.value;
var keyCount = strNotified.length;
	if (keyCount == 0) {
		document.display.CloneNotified.value = 'x';
		alert("You use this entry to clone the existing device to a new device\r\rIf you do not want to clone this device then simply clear the text box.");
		alert("When you clone a device you MUST make sure that you enter the full, required, DeviceID....\r\rIf you are cloning, for example, an existing device called \'Device_000001_S21\' you MUST add the \'_S21\' because the system will take your original DeviceID of \'DeviceID_000001\', you\'ll confirm that the system has added the '_S21' because you don\'t have that text in the DeviceID of your actual device, and add \'_S21\' to it to create the required DeviceID.\r\rIf you don\'t add the \'_S21\' then your new device wont match the system generated DeviceID and you\'ll find your device data in the invalid list.");
		alert("The Friendly name has been reset to nothing - if you decide not to clone this device then choose \'Update Cancel\' rather than \'Update Data\' otherwise you will erase your configured Friendly name.");4
		document.display.FriendlyName.value = '';
	}
}
// -->
<!--
function OffsetNotify() {
var strNotified = document.display.OffsetNotified.value;
var keyCount = strNotified.length;
	if (keyCount == 0) {
		document.display.OffsetNotified.value = 'x';
		alert("You use this option to OFFSET the date and time of the data from the device\rIf you do not want to OFFSET the time and date in this device then simply enter a 0 (zero).\r\rYou use this option by entering a negative or positive value for the SECONDS that you want the data and time to be offset by.");
	}
}
// -->
<!--
function confirmClone(passedDeviceToDelete)
{
var strOrig = document.display.Original_DeviceID.value;
var strNew = document.display.CloneEntry.value;

	if (strNew.length > 0) {
		var agree=confirm('Are you sure you wish to clone '+strNew+' from '+strOrig+' at this time?');
	}
	if (agree) {
		return true ;
	}
	else {
		return false ;
	}
}

function validateScalingValue(objName)
{
	var numberfield = objName;
	var txt = numberfield.value;
	if (txt == '.')
	{
		return false;
	}
	if (txt == '-')
	{
		return false;
	}
	if (txt>=-32000 && txt<=32000)
	{
		return false;
	}
	else
	{
		document.all(numberfield.name).value = '0';
		alert("Scaling value must be between -32000 and 32000")		
		return false;
	}
}

function getTarget(e)
{
	// IE5
   	if (e.srcElement)
   		return e.srcElement;
	if (e.target)
		return e.target;
}

function getKeyCode(e) {
	//IE5
 	if (e.srcElement)
 		return e.keyCode
	// NC5
	if (e.target)
		return e.which
}

function isNumeric(c)
{
	var sNumbers = "01234567890";
	if (sNumbers.indexOf(c) == -1)
		return false;
	else 
		return true;
}  

function isAlpha(c)
{
	var lCode = c.charCodeAt(0);
	if (lCode >= 65 && lCode <= 122 )
		return true;
	else 
		return false;
}  

function isPunct(c)
{
	var lCode = c.charCodeAt(0);
	if (lCode >= 32 && lCode <= 47 )
		return true;
	else 
		return false;
}

function Email_Validator(ctrl)
{
// test if valid email address, must have @ and .
var checkEmail = "@.";
var checkStr = ctrl.value;
var EmailValid = false;
var EmailAt = false;
var EmailPeriod = false;
	if (ctrl.value == "") {
		return true;
	}
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkEmail.length;  j++)
		{
			if (ch == checkEmail.charAt(j) && ch == "@")
			{
				EmailAt = true;
			}
			if (ch == checkEmail.charAt(j) && ch == ".")
			{
				EmailPeriod = true;
			}
			if (EmailAt && EmailPeriod)
				break;
			if (j == checkEmail.length)
				break;
		}
		// if both the @ and . were in the string
		if (EmailAt && EmailPeriod){
			EmailValid = true;
			break;
		}
	}
	if (!EmailValid)
	{
		alert("The email address must contain an \"@\" and a \".\" - in other words it must be a real email address like someone@microsoft.com");
		ctrl.focus();
		return (false);
	}
	return true;
}

function FixAwakeEvery() {
	
	if (loadedPage==false) {
		return;
	}
	
    var TypeChoice = document.getElementById('Awake_Every_Type').value;
    if(document.layers) {  
	//NN4+
    	if (TypeChoice == "True") {
		document.layers['AwakeMinutes'].visibility = "show";
		document.layers['AwakeOnHour'].visibility = "hide";
    	} 
    	else if (TypeChoice == "False") {
		document.layers['AwakeOnHour'].visibility = "show";
		document.layers['AwakeMinutes'].visibility = "hide";
    	}    	  
    	else {
		document.layers['AwakeMinutes'].visibility = "show";
		document.layers['AwakeOnHour'].visibility = "hide";
    	   	window.status = TypeChoice+' Problem....';
    	}
    }
    else if(document.getElementById) { 
    	// gecko(NN6) + IE 5+
    	if (TypeChoice == "True") {
    	   document.getElementById('AwakeMinutes').style.display = "block";
    	   document.getElementById('AwakeOnHour').style.display = "none";
    	} 
    	else if (TypeChoice == "False") {
       	   document.getElementById('AwakeOnHour').style.display = "block";
       	   document.getElementById('AwakeMinutes').style.display = "none";
    	}    	  
    	else {
    	   document.getElementById('AwakeMinutes').style.display = "block";
    	   document.getElementById('AwakeOnHour').style.display = "none";
    	   window.status = TypeChoice+' Problem....';
    	}
    }
    else if(document.all) {
    	// IE 4 
    	if (TypeChoice == "True") {
		document.all['AwakeMinutes'].style.visibility = "visible";
		document.all['AwakeOnHour'].style.visibility = "hidden";
    	} 
    	else if (TypeChoice == "False") {
    		document.all['AwakeOnHour'].style.visibility = "visible";
		document.all['AwakeMinutes'].style.visibility = "hidden";
    	}    	  
    	else {
		document.all['AwakeMinutes'].style.visibility = "visible";
		document.all['AwakeOnHour'].style.visibility = "hidden";
    	   window.status = TypeChoice+' Problem....';
    	}
    }
    if (blnShownAwakeEveryChange == false) {
    	blnShownAwakeEveryChange = true;
    	SetSelectToAnOption('IMEnabled', 'False');
    	alert('Because some settings are incompatible between timing modes Intelligent Monitoring has been disabled\n\nYou should make sure that the values timing are correct then re-enable Intelligent Monitoring.');
    }
}

function emailCheck (emailStr) {

	// http://javascript.internet.com/forms/email-address-validation.html

	/* The following variable tells the rest of the function whether or not
		to verify that the address ends in a two-letter country or well-known
		TLD.  1 means check it, 0 means don't. */

	var checkTLD=1;

	/* The following is the list of known TLDs that an e-mail address must end with. */
	
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|asia)$/;
	
	/* The following pattern is used to check if the entered e-mail address
		fits the user@domain format.  It also is used to separate the username
		from the domain. */
	
	var emailPat=/^(.+)@(.+)$/;

	/* The following string represents the pattern for matching all special
		characters.  We don't want to allow special characters in the address. 
		These characters include ( ) < > @ , ; : \ " . [ ] */
	
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	
	/* The following string represents the range of characters allowed in a 
		username or domainname.  It really states which chars aren't allowed.*/
	
	var validChars="\[^\\s" + specialChars + "\]";

	/* The following pattern applies if the "user" is a quoted string (in
		which case, there are no rules about which characters are allowed
		and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
		is a legal e-mail address. */
	
	var quotedUser="(\"[^\"]*\")";
	
	/* The following pattern applies for domains that are IP addresses,
		rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
		e-mail address. NOTE: The square brackets are required. */

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	
	/* The following string represents an atom (basically a series of non-special characters.) */
	
	var atom=validChars + '+';
	
	/* The following string represents one word in the typical username.
		For example, in john.doe@somewhere.com, john and doe are words.
		Basically, a word is either an atom or quoted string. */
	
	var word="(" + atom + "|" + quotedUser + ")";
	
	// The following pattern describes the structure of the user
	
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	
	/* The following pattern describes the structure of a normal symbolic
		domain, as opposed to ipDomainPat, shown above. */
	
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	
	/* Finally, let's start trying to figure out if the supplied address is valid. */
	
	/* Begin with the coarse pattern to simply break up user@domain into
		different pieces that are easy to analyze. */
	
	var matchArray=emailStr.match(emailPat);
	
	if (matchArray==null) {
	
	/* Too many/few @'s or something; basically, this address doesn't
		even fit the general mould of a valid e-mail address. */
	
		alert("Email address seems incorrect (check @ and .'s)");
		return false;
		
	}
	
	var user=matchArray[1];
	var domain=matchArray[2];
	
	// Start by checking that only basic ASCII characters are in the strings (0-127).
	
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert("Ths username contains invalid characters.");
			return false;
	   	}
	}
	
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert("Ths domain name contains invalid characters.");
			return false;
	   	}
	}
	
	// See if "user" is valid 
	
	if (user.match(userPat)==null) {
	
		// user is not valid
	
		alert("The username doesn't seem to be valid.");
		
		return false;
		
	}
	
	/* if the e-mail address is at an IP address (as opposed to a symbolic
		host name) make sure the IP address is valid. */
	
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
	
		// this is an IP address
	
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Destination IP address is invalid!");
				return false;
	   		}
		}
		return true;
	}
	
	// Domain is symbolic name.  Check if it's valid.
	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			alert("The domain name does not seem to be valid.");
			return false;
	   	}
	}
	
	/* domain name seems valid, but now make sure that it ends in a
		known top-level domain (like com, edu, gov) or a two-letter word,
		representing country (uk, nl), and that there's a hostname preceding 
		the domain or country. */
	
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
			alert("The address must end in a well-known domain or two letter " + "country.");
			return false;
	}
	
	// Make sure there's a host name preceding the domain.
	
	if (len<2) {
		alert("This address is missing a hostname!");
		return false;
	}
	
	// If we've gotten this far, everything's valid!
	return true;
}

function Post_DeviceToPush(passedID) {

var objDevice = document.getElementById('Device');
var selLength = objDevice.length;
var selectedText = "The data for this port is not pushed to any other device.";
var selectedValue = "-1";
  
var i;
  
	// Find the selected Options in reverse order
	// and delete them from the 'from' Select.
	for(i=selLength-1; i>=0; i--)
	{
		if(objDevice.options[i].selected)
		{
			selectedText = objDevice.options[i].text;
			selectedValue = objDevice.options[i].value;
			break;
		}
	}	
	//
	var objMain = opener.document.getElementById('SDFTD'+passedID);
	objMain.innerHTML = selectedText;
	//
	var objMinor = opener.document.getElementById('SDFTDH'+passedID);
	objMinor.value = selectedValue;
	
	var objTrueFalse = opener.document.getElementById('Field'+passedID+'_WriteINIFileDataForSelect');
	if (objTrueFalse != null) {
		if (selectedValue == -1) {
			objTrueFalse.selectedIndex = 0;
		}
		else {
			objTrueFalse.selectedIndex = 1
		}
	}
	self.close();
}

function Show_Reduced_View(passedValue) {
	var objPopClient = document.getElementById('DeviceClient');
	var objPopDevice = document.getElementById('DeviceID');
	if (objPopDevice.value!='select') {
		parent.DeviceChoices.location='access_Chooser_GPRS.asp?zPassed='+passedValue+'&PopClient='+objPopClient.value+'&PopDevice='+objPopDevice.value;
	} else {
		parent.DeviceChoices.location='Blank_ReducedPage.asp';
	}
}

function Show_Reduced_View_20061113(passedValue) {
	var objPopClient = document.getElementById('DeviceClient');
	var objPopDevice = document.getElementById('DeviceID');
	if (objPopDevice.value!='select') {
		parent.DeviceChoices.location='access_Chooser_GPRS_Reduced.asp?zPassed='+passedValue+'&PopClient='+objPopClient.value+'&PopDevice='+objPopDevice.value;
	} else {
		parent.DeviceChoices.location='Blank_ReducedPage.asp';
	}
}

function myOnError() {
	return false;
}

function SetLastCeilingValue(passedValue) {
	lastCeilingValue = passedValue;
}

function SetSavedGraphFloor(passedGraphFloor) {
	savedGraphFloor = passedGraphFloor;
	return passedGraphFloor;
}

function SetSavedGraphCeiling(passedGraphCeiling) {
	savedGraphCeiling = passedGraphCeiling;
	return passedGraphCeiling;
}

function SetLastCeilingFloor(passedLastCeilingFloor) {
	strLastCeilingFloor = passedLastCeilingFloor;
	return passedLastCeilingFloor;
}

function SetLastFloorValue(passedValue) {
	lastFloorValue = passedValue;
}

function enableRadio(passedID) {
	if (blnDoEnableRadio==false) {
		windows.status = 'Bypassing enableRadio';
		return false;
	}
	if (passedID == 'k') {
		// var objPop = document.getElementById('kMinutesToDisplay');
		// objPop.disabled = false;
		//
 	 	var objPop = document.getElementById('kMinutesToDisplayDays');
 	 	objPop.disabled = false;
 	 	var objPop = document.getElementById('kMinutesToDisplayHours');
 	 	objPop.disabled = false;
 	 	var objPop = document.getElementById('kMinutesToDisplayMinutes');
		objPop.disabled = false;
		//
		// var objPop = document.getElementById('lMinutesToDisplay');
		// objPop.disabled = true;
		//
 	 	var objPop = document.getElementById('lMinutesToDisplayDays');
 	 	objPop.disabled = true;
 	 	var objPop = document.getElementById('lMinutesToDisplayHours');
 	 	objPop.disabled = true;
 	 	var objPop = document.getElementById('lMinutesToDisplayMinutes');
		objPop.disabled = true;
		//
		var objPop = document.getElementById('StartDate');
		objPop.disabled = true;
		var objPop = document.getElementById('EndDate');
		objPop.disabled = true;
		blnIsStartEnabled=false;
		blnIsEndEnabled=false;
	} else if (passedID == 'l') {
		// var objPop = document.getElementById('kMinutesToDisplay');
		// objPop.disabled = true;
		//
 	 	var objPop = document.getElementById('kMinutesToDisplayDays');
 	 	objPop.disabled = true;
 	 	var objPop = document.getElementById('kMinutesToDisplayHours');
 	 	objPop.disabled = true;
 	 	var objPop = document.getElementById('kMinutesToDisplayMinutes');
		objPop.disabled = true;
		//
		// var objPop = document.getElementById('lMinutesToDisplay');
		// objPop.disabled = false;
		//
 	 	var objPop = document.getElementById('lMinutesToDisplayDays');
 	 	objPop.disabled = false;
 	 	var objPop = document.getElementById('lMinutesToDisplayHours');
 	 	objPop.disabled = false;
 	 	var objPop = document.getElementById('lMinutesToDisplayMinutes');
		objPop.disabled = false;
		//
		var objPop = document.getElementById('StartDate');
		objPop.disabled = true;
		var objPop = document.getElementById('EndDate');
		objPop.disabled = true;
		blnIsStartEnabled=false;
		blnIsEndEnabled=false;
	} else if (passedID == 'c') {
		// var objPop = document.getElementById('kMinutesToDisplay');
		// objPop.disabled = true;
		//
 	 	var objPop = document.getElementById('kMinutesToDisplayDays');
 	 	objPop.disabled = true;
 	 	var objPop = document.getElementById('kMinutesToDisplayHours');
 	 	objPop.disabled = true;
 	 	var objPop = document.getElementById('kMinutesToDisplayMinutes');
		objPop.disabled = true;
		//
		// var objPop = document.getElementById('lMinutesToDisplay');
		// objPop.disabled = true;
		//
 	 	var objPop = document.getElementById('lMinutesToDisplayDays');
 	 	objPop.disabled = true;
 	 	var objPop = document.getElementById('lMinutesToDisplayHours');
 	 	objPop.disabled = true;
 	 	var objPop = document.getElementById('lMinutesToDisplayMinutes');
		objPop.disabled = true;
		//
		var objPop = document.getElementById('StartDate');
		objPop.disabled = false;
		var objPop = document.getElementById('EndDate');
		objPop.disabled = false;
		blnIsStartEnabled=true;
		blnIsEndEnabled=true;
	}
	Post_MinutesToDisplay(passedID);

	var objMain = opener.document.getElementById('hKStart');
	// var objSecond = document.getElementById('kMinutesToDisplay');
	// objMain.value = objSecond.value;
	//
	var valWorking=0;
 	var objPop = document.getElementById('kMinutesToDisplayDays');
 	valWorking = objPop.value*1440;
 	var objPop = document.getElementById('kMinutesToDisplayHours');
 	valWorking = parseInt(valWorking)+parseInt(objPop.value*60);
 	var objPop = document.getElementById('kMinutesToDisplayMinutes');
	valWorking = parseInt(valWorking)+parseInt(objPop.value);
	objMain.value = valWorking;
	//
	var objMain = opener.document.getElementById('hLStart');
	// var objSecond = document.getElementById('lMinutesToDisplay');
	// objMain.value = objSecond.value;
	//
	valWorking=0;
 	var objPop = document.getElementById('lMinutesToDisplayDays');
 	valWorking = objPop.value*1440;
 	var objPop = document.getElementById('lMinutesToDisplayHours');
 	valWorking = parseInt(valWorking)+parseInt(objPop.value*60);
 	var objPop = document.getElementById('lMinutesToDisplayMinutes');
	valWorking = parseInt(valWorking)+parseInt(objPop.value);
	objMain.value = valWorking;
	//
	var objMain = opener.document.getElementById('hCStart');
	var objSecond = document.getElementById('StartDate');
	objMain.value = objSecond.value;
	var objMain = opener.document.getElementById('hCStop');
	var objSecond = document.getElementById('EndDate');
	objMain.value = objSecond.value;
	
	var objMain = opener.document.getElementById('hDateAndTimeChoice');
	objMain.value = passedID;
}

function Post_MinutesToDisplay(passedID) {
	// alert('h'+passedID.toUpperCase()+'Start');
	var strResult="";
	var objMain = opener.document.getElementById('h'+passedID.toUpperCase()+'Start')
	var objMainImage = opener.document.getElementById('DateAndTimeChoice')
	if (passedID == 'k' || passedID == 'l') {
		var objPop = document.getElementById(passedID+'MinutesToDisplayDays');
		if (objPop.value=='1') {
			strResult = strResult+objPop.value+' day, '
		} else {
			strResult = strResult+objPop.value+' days and '
		}		
		var objPop = document.getElementById(passedID+'MinutesToDisplayHours');
		if (objPop.value=='1') {
			strResult = strResult+objPop.value+' hour and '
		} else {
			strResult = strResult+objPop.value+' hours and '
		}		
		var objPop = document.getElementById(passedID+'MinutesToDisplayMinutes');
		if (objPop.value=='1') {
			strResult = strResult+objPop.value+' minute'
		} else {
			strResult = strResult+objPop.value+' minutes'
		}		
		var valWorking=0;
	 	var objPop = document.getElementById(passedID+'MinutesToDisplayDays');
	 	valWorking = parseInt(objPop.value)*1440;
	 	var objPop = document.getElementById(passedID+'MinutesToDisplayHours');
	 	valWorking = parseInt(valWorking)+parseInt(objPop.value*60);
	 	var objPop = document.getElementById(passedID+'MinutesToDisplayMinutes');
		valWorking = parseInt(valWorking)+parseInt(objPop.value);
	} else {
		var objPop = document.getElementById(passedID+'MinutesToDisplay');
	}
	if (passedID == 'k') {
		opener.InitializeTimer('DateAndTimeChoice', '<img src=\"../images/b.gif\"> Display '+strResult+' of data stopping at the time of the last known valid data');
		objMainImage.innerHTML = "<img src=\"../images/updated.gif\"> Display "+strResult+" of data stopping at the time of the last known valid data";
		objMain.value = valWorking;		
	} else if (passedID == 'l') {
		opener.InitializeTimer('DateAndTimeChoice', '<img src=\"../images/b.gif\"> Display '+strResult+' of data from the current time');
		objMainImage.innerHTML = "<img src=\"../images/updated.gif\"> Display "+strResult+" of data from the current time";
		objMain.value = valWorking;
		// var objMain = opener.document.getElementById('h'+passedID+'Start')
	} else if (passedID == 'c') {
		var objPop = document.getElementById('StartDate');
		var objPopSecond = document.getElementById('EndDate');
		opener.InitializeTimer('DateAndTimeChoice', '<img src=\"../images/b.gif\"> Using the calendars to set the start time to '+objPop.value+' and the stop time to '+objPopSecond.value);
		objMainImage.innerHTML = "<img src=\"../images/updated.gif\"> Using the calendars to set the start time to "+objPop.value+" and the stop time to "+objPopSecond.value;
		var objMain = opener.document.getElementById('hCStart');
		objMain.value = objPop.value;
		var objMain = opener.document.getElementById('hCStop');
		objMain.value = objPopSecond.value;
		CloseThisWindow.focus();	
	}
	return true;	
}


function quick_ports(passedID) {
	var objMain = document.getElementById('PFS'+passedID)
	var objMainImage = document.getElementById('PD'+passedID)
	if (objMain.value == "") {
		objMain.value="Checked";
		objMainImage.innerHTML = "<a href=\"javascript:void(0)\;\" onclick=\"quick_ports('"+passedID+"')\;\" onmouseover=\"window.status=\'Change whether this port is selected or not\'\;return true\" onmouseout=\"window.status=\'\'\;return true\"><u><img src=\"../images/tick_green.gif\"></u></a>";
	}
	else {
		objMain.value="";
		objMainImage.innerHTML = "<a href=\"javascript:void(0)\;\" onclick=\"quick_ports('"+passedID+"')\;\" onmouseover=\"window.status=\'Change whether this port is selected or not\'\;return true\" onmouseout=\"window.status=\'\'\;return true\"><u><img src=\"../images/redcross.gif\"></u></a>";
	}
	// Now I want to check to see if all ports are used - if they are clear the <PortsUsed> DIV otherwise show the 'There are unselected ports' message
	var blnAreAllPortsSelected = true;
	var blnIsAPortSelected = false;
	var PortsSelected = 0;
	var intTopOfPorts = document.getElementById('PFSTotal').value;
	// alert(intTopOfPorts+" is the top value");
	for (PortsSelected = 1; PortsSelected <= intTopOfPorts; PortsSelected++) {
		var objPop = document.getElementById('PFS'+PortsSelected);
		if (objPop.value == "Checked") {
			blnIsAPortSelected = true;
	} else {
			blnAreAllPortsSelected = false;
		}
	}
	var objMain = document.getElementById('PortsUsed');
	if (blnAreAllPortsSelected == false) {
			objMain.innerHTML = "Ports - Not all ports are selected";
	} else {
			objMain.innerHTML = "Ports";
	}
	if (blnIsAPortSelected == true) {
	   	document.getElementById('ShowReportGenerate').style.display = "block";
	}
	else {
		document.getElementById('ShowReportGenerate').style.display = "none";
	}
}

function quick_trend(passedID) {
	var objMain = document.getElementById('PFST'+passedID)
	var objMainImage = document.getElementById('PDT'+passedID)
	if (objMain.value == "") {
		objMain.value="Checked";
		objMainImage.innerHTML = "<a href=\"javascript:void(0)\;\" onclick=\"quick_trend('"+passedID+"')\;\" onmouseover=\"window.status=\'Change whether the Trend Line is displayed or not\'\;return true\" onmouseout=\"window.status=\'\'\;return true\"><u><img src=\"../images/tick_green.gif\"></u></a>";
	}
	else {
		objMain.value="";
		objMainImage.innerHTML = "<a href=\"javascript:void(0)\;\" onclick=\"quick_trend('"+passedID+"')\;\" onmouseover=\"window.status=\'Change whether the Trend Line is displayed or not\'\;return true\" onmouseout=\"window.status=\'\'\;return true\"><u><img src=\"../images/redcross.gif\"></u></a>";
	}
	// var objMain = document.getElementById('PFST'+passedID)
	// alert(objMain.value);
}

function quick_average(passedID) {
	var objMain = document.getElementById('PFSA'+passedID)
	var objMainImage = document.getElementById('PDA'+passedID)
	if (objMain.value == "") {
		objMain.value="Checked";
		objMainImage.innerHTML = "<a href=\"javascript:void(0)\;\" onclick=\"quick_average('"+passedID+"')\;\" onmouseover=\"window.status=\'Change whether the Average Line is displayed or not\'\;return true\" onmouseout=\"window.status=\'\'\;return true\"><u><img src=\"../images/tick_green.gif\"></u></a>";
	}
	else {
		objMain.value="";
		objMainImage.innerHTML = "<a href=\"javascript:void(0)\;\" onclick=\"quick_average('"+passedID+"')\;\" onmouseover=\"window.status=\'Change whether the Average Line is displayed or not\'\;return true\" onmouseout=\"window.status=\'\'\;return true\"><u><img src=\"../images/redcross.gif\"></u></a>";
	}
	// var objMain = document.getElementById('PFSA'+passedID)
	// alert(objMain.value);
}

function post_value(passedType, passedID) {
	// Checked 03/03/2006 10:21
	if (passedType == 'Ports') {
		var objMain = opener.document.getElementById('PFS'+passedID)
		var objMainImage = opener.document.getElementById('PD'+passedID)
		var objPop = document.getElementById('PFS'+passedID);
		if (objPop.checked == 1) {
			objMain.value="Checked";
			opener.InitializeTimer('PD'+passedID, '<a href=\"javascript:void(0)\;\" onclick=\"quick_ports('+passedID+')\;\" onmouseover=\"window.status=\'Change whether this port is selected or not\'\;return true\" onmouseout=\"window.status=\'\'\;return true\"><u><img src=\"../images/tick_green.gif\"></u></a>');
			objMainImage.innerHTML = "<a href=\"javascript:void(0)\;\" onclick=\"quick_ports('"+passedID+"')\;\" onmouseover=\"window.status=\'Change whether this port is selected or not\'\;return true\" onmouseout=\"window.status=\'\'\;return true\"><u><img src=\"../images/tick_green.gif\"></u></a><img src=\"../images/updated.gif\">";
		}
		else {
			objMain.value="";
			opener.InitializeTimer('PD'+passedID, '<a href=\"javascript:void(0)\;\" onclick=\"quick_ports('+passedID+')\;\" onmouseover=\"window.status=\'Change whether this port is selected or not\'\;return true\" onmouseout=\"window.status=\'\'\;return true\"><u><img src=\"../images/redcross.gif\"></u></a>');
			objMainImage.innerHTML = "<a href=\"javascript:void(0)\;\" onclick=\"quick_ports('"+passedID+"')\;\" onmouseover=\"window.status=\'Change whether this port is selected or not\'\;return true\" onmouseout=\"window.status=\'\'\;return true\"><u><img src=\"../images/redcross.gif\"></u></a><img src=\"../images/updated.gif\">";
		}
		// Now I want to check to see if all ports are used - if they are clear the <PortsUsed> DIV otherwise show the 'There are unselected ports' message
		var blnAreAllPortsSelected = true;
		var PortsSelected = 0;
		var intTopOfPorts = opener.document.getElementById('PFSTotal').value;
		// alert(intTopOfPorts+" is the top value");
		for (PortsSelected = 1; PortsSelected <= intTopOfPorts; PortsSelected++) {
			var objPop = document.getElementById('PFS'+PortsSelected);
			if (objPop.checked == 1) {
			} else {
				blnAreAllPortsSelected = false;
			}
		}
		var objMain = opener.document.getElementById('PortsUsed');
		if (blnAreAllPortsSelected == false) {
				objMain.innerHTML = "Ports - Not all ports are selected";
		} else {
				objMain.innerHTML = "Ports";
		}
	}
	// Checked 03/03/2006 10:21
	if (passedType == 'ReportDisplayTypes') {
		var objMain = opener.document.getElementById('hReportDisplayTypes')
		var objMainSecond = opener.document.getElementById('ReportDisplayTypes')
		if (objMain != null) {
			objMain.value = passedID;
			if (passedID == 'g') {
				opener.InitializeTimer('ReportDisplayTypes', '<img src=\"../images/b.gif\">Only a graph will be generated');
				objMainSecond.innerHTML = "<img src=\"../images/updated.gif\">Only a graph will be generated";
			}
			if (passedID == 'gt') {
				opener.InitializeTimer('ReportDisplayTypes', '<img src=\"../images/b.gif\">A graph and table will be generated');
				objMainSecond.innerHTML = "<img src=\"../images/updated.gif\">A graph and table will be generated";
			}
			if (passedID == 't') {
				opener.InitializeTimer('ReportDisplayTypes', '<img src=\"../images/b.gif\">Only a table will be generated');
				objMainSecond.innerHTML = "<img src=\"../images/updated.gif\">Only a table will be generated";
			}
			
		}
	}
	// Checked 03/03/2006 10:21
	if (passedType == 'AUTORefresh') {
		var objMain = opener.document.getElementById('hAutoRefresh')
		var objMainSecond = opener.document.getElementById('AUTORefresh')
		if (objMain != null) {
			if (passedID == 'y') {
				objMain.value = "on";
				opener.InitializeTimer('AUTORefresh', '<img src=\"../images/b.gif\">The graph auto refreshes every ten minutes');
				objMainSecond.innerHTML = "<img src=\"../images/updated.gif\">The graph auto refreshes every ten minutes";
			}
			if (passedID == 'n') {
				objMain.value = "";
				opener.InitializeTimer('AUTORefresh', '<img src=\"../images/b.gif\">The graph does not auto refresh every ten minutes');
				objMainSecond.innerHTML = "<img src=\"../images/updated.gif\">The graph does not auto refresh every ten minutes";
			}
		}
	}
	// Checked 03/03/2006 11:06
	if (passedType == 'GraphCeiling') {
		var valueToUse = "";
		var objMain = opener.document.getElementById('hGraphCeiling')
		var objMainSecond = opener.document.getElementById('GraphCeiling')
		var objPop = document.getElementById('GraphCeiling');
		if (objMain != null) {
			if (lastCeilingValue != objPop.value) {
				if (objPop.value == '') {
					lastCeilingValue = objPop.value;
					objMain.value = "";
					valueToUse = "";
					savedGraphCeiling = opener.SetSavedGraphCeiling('');
					objMainSecond.innerHTML = "<img src=\"../images/updated.gif\">Graph will not use a configured Ceiling";
					if (strLastCeilingFloor != 'GraphCeilingNone') {
					 	strLastCeilingFloor = opener.SetLastCeilingFloor('GraphCeilingNone');
						opener.InitializeTimer('GraphCeiling', '<img src=\"../images/b.gif\">Graph will not use a configured Ceiling');
						window.status = strLastCeilingFloor+' --- GraphCeiling';
					}
				} else {
					lastCeilingValue = objPop.value;
					objMain.value = objPop.value;
					valueToUse = objPop.value;
					savedGraphCeiling = opener.SetSavedGraphCeiling(objPop.value);
					objMainSecond.innerHTML = "<img src=\"../images/updated.gif\">Graph will use a configured Ceiling of "+objPop.value;
					if (strLastCeilingFloor != 'GraphCeilingValue') {
						strLastCeilingFloor = opener.SetLastCeilingFloor('GraphCeilingValue');
						opener.InitializeTimer('GraphCeiling', '<img src=\"../images/b.gif\">Graph will use a configured Ceiling of ');
						window.status = strLastCeilingFloor+' --- GraphCeiling';
					}
				}
			}
			var objPop = opener.document.getElementById('CeilingMax');
			if (objPop != null) {
				objPop.innerHTML = 'Max:\&nbsp;'+valueToUse;
				alert('Max:\&nbsp;'+valueToUse);
			}			
		}
	}
	// Checked 03/03/2006 11:30
	if (passedType == 'GraphFloor') {
		var valueToUse = "";
		var objMain = opener.document.getElementById('hGraphFloor')
		var objMainSecond = opener.document.getElementById('GraphFloor')
		var objPop = document.getElementById('GraphFloor');
		if (objMain != null) {
			if (lastFloorValue != objPop.value) {
				if (objPop.value == '') {
					lastFloorValue = objPop.value;
					objMain.value = "";
					valueToUse = "";
					savedGraphFloor = opener.SetSavedGraphFloor('');
					objMainSecond.innerHTML = "<img src=\"../images/updated.gif\">Graph will not use a configured Floor";
					if (strLastCeilingFloor != 'GraphFloorNone') {
						savedGraphCeiling = opener.SetLastCeilingFloor('GraphFloorNone');
						opener.InitializeTimer('GraphFloor', '<img src=\"../images/b.gif\">Graph will not use a configured Floor');
						window.status = strLastCeilingFloor+' --- GraphFloor';
					}
				} else {
					lastFloorValue = objPop.value;
					objMain.value = objPop.value;
					valueToUse = objPop.value;
					savedGraphFloor = opener.SetSavedGraphFloor(objPop.value);
					objMainSecond.innerHTML = "<img src=\"../images/updated.gif\">Graph will use a configured Floor of "+objPop.value;
					if (strLastCeilingFloor != 'GraphFloorValue') {
					 	strLastCeilingFloor = opener.SetLastCeilingFloor('GraphFloorValue');
						opener.InitializeTimer('GraphFloor', '<img src=\"../images/b.gif\">Graph will use a configured Floor of ');
						window.status = strLastCeilingFloor+' --- GraphFloor';
					}
				}
			}
			var objPop = opener.document.getElementById('CeilingMin');
			if (objPop != null) {
				objPop.innerHTML = 'Min:\&nbsp;'+valueToUse;
				alert('Min:\&nbsp;'+valueToUse);
			}			
		}
	}
	// Checked 03/03/2006 23:08
	if (passedType == 'DefinedRange') {
		var objMain = opener.document.getElementById('hDefinedRange')
		var objMainSecond = opener.document.getElementById('DefinedRange')
		var objPop = document.getElementById('DefinedRange'+passedID);
		if (objMain != null) {
			objMain.value = passedID;
			if (passedID == 'd') {
				opener.InitializeTimer('DefinedRange', '<img src=\"../images/b.gif\">Graph will be created using the core data associated with the device');
				objMainSecond.innerHTML = "<img src=\"../images/updated.gif\">Graph will be created using the core data associated with the device";
			} else if (passedID == 'r') {
				opener.InitializeTimer('DefinedRange', '<img src=\"../images/b.gif\">Graph will be created with a ceiling and floor that displays the maximimum information');
				objMainSecond.innerHTML = "<img src=\"../images/updated.gif\">Graph will be created with a ceiling and floor that displays the maximimum information";
			} else if (passedID == 'riz') {
				opener.InitializeTimer('DefinedRange', '<img src=\"../images/b.gif\">Graph will be created with a ceiling and floor that displays the maximimum information and any value that is zero will be stripped from the graph');
				objMainSecond.innerHTML = "<img src=\"../images/updated.gif\">Graph will be created with a ceiling and floor that displays the maximimum information and any value that is zero will be stripped from the graph";
			} else if (passedID == 'e') {
				opener.InitializeTimer('DefinedRange', '<img src=\"../images/b.gif\">Graph will be created with a ceiling and floor that displays the maximimum information');
				objMainSecond.innerHTML = "<img src=\"../images/updated.gif\">Graph will be created with a ceiling and floor that displays the maximimum information";
			} else if (passedID == '0100') {
				opener.InitializeTimer('DefinedRange', '<img src=\"../images/b.gif\">Graph will be created with a ceiling of 100 and a floor of zero irrespective of the core data for the device');
				objMainSecond.innerHTML = "<img src=\"../images/updated.gif\">Graph will be created with a ceiling of 100 and a floor of zero irrespective of the core data for the device";
			}
		}
	}
	// Checked 03/03/2006 23:18
	if (passedType == 'ReportOutput') {
		var objMain = opener.document.getElementById('hReportOutput')
		var objMainSecond = opener.document.getElementById('ReportOutput')
		if (objMain != null) {
			objMain.value = passedID;
			if (passedID == 'n') {
				opener.InitializeTimer('ReportOutput', '<img src=\"../images/b.gif\">No output fille will be generated for downloading');
				objMainSecond.innerHTML = "<img src=\"../images/updated.gif\">No output fille will be generated for downloading";
			}
			if (passedID == 'h') {
				opener.InitializeTimer('ReportOutput', '<img src=\"../images/b.gif\">A HTML output fille will be generated for downloading');
				objMainSecond.innerHTML = "<img src=\"../images/updated.gif\">A HTML output fille will be generated for downloading";
			}
			if (passedID == 't') {
				opener.InitializeTimer('ReportOutput', '<img src=\"../images/b.gif\">A Text output fille will be generated for downloading');
				objMainSecond.innerHTML = "<img src=\"../images/updated.gif\">A Text output fille will be generated for downloading";
			}
			if (passedID == 'c') {
				opener.InitializeTimer('ReportOutput', '<img src=\"../images/b.gif\">A CSV output fille will be generated for downloading');
				objMainSecond.innerHTML = "<img src=\"../images/updated.gif\">A CSV output fille will be generated for downloading";
			}
			if (passedID == 'ec') {
				opener.InitializeTimer('ReportOutput', '<img src=\"../images/b.gif\">An Extended CSV output fille will be generated for downloading');
				objMainSecond.innerHTML = "<img src=\"../images/updated.gif\">An Extended CSV output fille will be generated for downloading";
			}
		}
	}
}

function retrieve_value(passedtop) {
	// start our for loop
        for (i = 1; i <= passedtop; i++) {
	 	var objMain = opener.document.getElementById('PFS'+i)
	 	var objPop = document.getElementById('PFS'+i);
	 	if (objMain.value == 'Checked') {
	 		if (objPop != null) {
	 			objPop.checked = 1;
	 		}
	 	}
	 	else {
	 		if (objPop != null) {
	 			objPop.checked = 0;
	 		}
	 	}
	}
	var objMain = opener.document.getElementById('hReportDisplayTypes');
	if (objMain.value == 'g') {
		var objPop = document.getElementById('GTypeG');
		if (objPop != null) {
			objPop.checked = 1;
		}
	}
	if (objMain.value == 'gt') {
		var objPop = document.getElementById('GTypeGT');
		if (objPop != null) {
			objPop.checked = 1;
		}
	}
	if (objMain.value == 't') {
		var objPop = document.getElementById('GTypeT');
		if (objPop != null) {
			objPop.checked = 1;
		}
	}
	//
	var objMain = opener.document.getElementById('hAutoRefresh');
	if (objMain.value == 'on') {
		var objPop = document.getElementById('AUTORefreshY');
		if (objPop != null) {
			objPop.checked = 1;
		}
	}
	if (objMain.value == '') {
		var objPop = document.getElementById('AUTORefreshN');
		if (objPop != null) {
			objPop.checked = 1;
		}
	}
	//
	var objMain = opener.document.getElementById('hGraphCeiling');
	var objPop = document.getElementById('GraphCeiling');
	if (objPop != null) {
		if (objMain.value != undefined) {
			objPop.value = objMain.value;
		} else {
			objPop.value = '';
		}
		lastCeilingValue = objPop.value;
	}
	var objMain = opener.document.getElementById('hGraphFloor');
	var objPop = document.getElementById('GraphFloor');
	if (objPop != null) {
		if (objMain.value != undefined) {
			objPop.value = objMain.value;
		} else {
			objPop.value = '';
		}
		lastFloorValue = objPop.value;
	}
	var objMain = opener.document.getElementById('hDefinedRange');
	if (objMain.value == 'd') {
		var objPop = document.getElementById('DefinedRangeD');
		if (objPop != null) {
			objPop.checked = 1;
		}
	} else if (objMain.value == 'r') {
		var objPop = document.getElementById('DefinedRangeR');
		if (objPop != null) {
			objPop.checked = 1;
		}
	} else if (objMain.value == 'riz') {
		var objPop = document.getElementById('DefinedRangeRIZ');
		if (objPop != null) {
			objPop.checked = 1;
		}
	} else if (objMain.value == 'e') {
		var objPop = document.getElementById('DefinedRangeE');
		if (objPop != null) {
			objPop.checked = 1;
		}
	} else if (objMain.value == '0100') {
		var objPop = document.getElementById('DefinedRange0100');
		if (objPop != null) {
			objPop.checked = 1;
		}
	} else {
		alert(objMain.value);
	}
	
	var objMain = opener.document.getElementById('hReportOutput');
	if (objMain.value == '') {
		var objPop = document.getElementById('ReportOutputN');
		if (objPop != null) {
			objPop.checked = 1;
		}
	} else if (objMain.value == 'n') {
		var objPop = document.getElementById('ReportOutputN');
		if (objPop != null) {
			objPop.checked = 1;
		}
	} else if (objMain.value == 'h') {
		var objPop = document.getElementById('ReportOutputH');
		if (objPop != null) {
			objPop.checked = 1;
		}
	} else if (objMain.value == 't') {
		var objPop = document.getElementById('ReportOutputT');
		if (objPop != null) {
			objPop.checked = 1;
		}
	} else if (objMain.value == 'c') {
		var objPop = document.getElementById('ReportOutputC');
		if (objPop != null) {
			objPop.checked = 1;
		}
	} else if (objMain.value == 'ec') {
		var objPop = document.getElementById('ReportOutputEC');
		if (objPop != null) {
			objPop.checked = 1;
		}
	}

	var objMain = opener.document.getElementById('hDateAndTimeChoice');
	if (objMain.value == 'k') {
	 	var objPop = document.getElementById('EnableRadioK');
	 	if (objPop != null) {
	 	 	objPop.checked = 1;
	 	 	var objPop = document.getElementById('kMinutesToDisplayDays');
	 	 	if (objPop != null) {
	 	 		objPop.disabled = false;
	 	 	}
	 	 	var objPop = document.getElementById('kMinutesToDisplayHours');
	 	 	if (objPop != null) {
	 	 		objPop.disabled = false;
	 	 	}
	 	 	var objPop = document.getElementById('kMinutesToDisplayMinutes');
	 	 	if (objPop != null) {
	 	 		objPop.disabled = false;
	 	 	}
	 	}
	} else if (objMain.value == 'l') {
	 	var objPop = document.getElementById('EnableRadioL');
	 	if (objPop != null) {
	 	 	objPop.checked = 1;
	 	 	var objPop = document.getElementById('lMinutesToDisplayDays');
	 	 	if (objPop != null) {
	 	 		objPop.disabled = false;
	 	 	}
	 	 	var objPop = document.getElementById('lMinutesToDisplayHours');
	 	 	if (objPop != null) {
	 	 		objPop.disabled = false;
	 	 	}
	 	 	var objPop = document.getElementById('lMinutesToDisplayMinutes');
	 	 	if (objPop != null) {
	 	 		objPop.disabled = false;
	 	 	}
	 	}
	} else if (objMain.value == 'c') {
	 	var objPop = document.getElementById('EnableRadioC');
	 	if (objPop != null) {
	 		objPop.checked = 1;
	 	 	var objPop = document.getElementById('StartDate');
	 	 	if (objPop != null) {
	 	 		objPop.disabled = false;
	 	 	}
	 	 	var objPop = document.getElementById('EndDate');
	 	 	if (objPop != null) {
	 	 		objPop.disabled = false;
	 	 	}
	 	}
	}
}

function ShowCalPopup(passedID) {
	if (passedID == '3') {
		if (blnIsEndEnabled == true) {
			cal3.popup();
		}
	} else if (passedID == '4') {
		if (blnIsStartEnabled==true) {
			cal4.popup();
		}
	}
}

function ClientScreenSize() {
var screenW = 640;
var screenH = 480;
	var SizeArray=new Array();
	if (parseInt(navigator.appVersion)>3) {
 		screenW = screen.width;
 		screenH = screen.height;
	} else if (navigator.appName == "Netscape" 
			&& parseInt(navigator.appVersion)==3
			&& navigator.javaEnabled()) {
		 var jToolkit = java.awt.Toolkit.getDefaultToolkit();
		 var jScreenSize = jToolkit.getScreenSize();
		 screenW = jScreenSize.width;
		 screenH = jScreenSize.height;
	}
//	if (self.innerWidth)
//	{
//		screenW = self.innerWidth;
//		screenH = self.innerHeight;
//	}
//	else if (document.documentElement && document.documentElement.clientWidth)
//	{
//		screenW = document.documentElement.clientWidth;
//		screenH = document.documentElement.clientHeight;
//	}
//	else if (document.body)
//	{
//		screenW = document.body.clientWidth;
//		screenH = document.body.clientHeight;
//	}
	SizeArray[0] = screenW;
	SizeArray[1] = screenH;
	return {screenW:screenW,screenH:screenH};
}
function disableGenerateButton () {
	var button=document.getElementById('GenerateButton')
  	if (document.all || document.getElementById) {
    		button.disabled = true;
    	}
  	else if (button) {
  		button.value = "Disabled";
    		button.onclick = null;
  	}
}
function MoveForward(passedURL) {
	document.forms[0].action = passedURL;
	document.forms[0].submit();
}
function MoveBackward() {
	history.go(-1);
}
function handleError() {
	window.status="Error found";
	return false;
}
function MoveForwardDevice(url,passedQuickSelect) {
	if (passedQuickSelect != null) {
		 document.getElementById('DeviceQuick').value = passedQuickSelect;
	}
	if (document.forms[0].Device.value == "-1" && document.getElementById('DeviceQuick').value == "") {
		alert("You must choose a device.");
		document.forms[0].Device.focus();
		return (false);
	}	
	document.forms[0].action = url;
	document.forms[0].submit();
}
function MoveForwardListLastInvalid(passedGFLT, passedWidth,passedHeight) {
	var objFirst = document.getElementById('PickerInputStart');
	var objSecond = document.getElementById('PickerInputEnd');
	// var url='ListLastInvalid.asp?Z='+passedGFLT+'&Start='+objFirst.value+'&Stop='+objSecond.value;
	document.forms[0].action = 'ListLastInvalid.asp?Z='+passedGFLT+'&Start='+objFirst.value+'&Stop='+objSecond.value;
	document.forms[0].submit();
	
	// passedWidth = passedWidth - 40;
	// passedHeight = passedHeight - 40;
	// window_handle = window.open('ListLastInvalid.asp?Z='+passedGFLT+'&Start='+objFirst.value+'&Stop='+objSecond.value+'&sW='+passedWidth+'&sH='+passedHeight,'','resizable=yes,width='+passedWidth+',height='+passedHeight+',top=0,left=0,toolbar=no,scrollbars=yes,addressbar=no');
    	// window_handle.focus();
    	// return false;
}
function MoveForwardPort(url) {
	// var objMain = opener.document.getElementById('OverRideForReduced')
	// if (objMain == null) {
	// 	document.forms[0].action = url;
	// 	document.forms[0].submit();
	// } else {	
		var InputFound=false;
		for ( var i = 0; i < 200; i++ ) {
			if (document.all("FIELD"+i+"Name") !=null) {
      				if (document.all("FIELD"+i+"Name").checked == true) {
      					InputFound=true;
	      				break;
      				}
      			}
      		}
		if (InputFound==false) {
			alert("You must choose an input.");
			document.forms[0].Next.focus();
			return (false);
		}	
		document.forms[0].action = url;
		document.forms[0].submit();
	// }
}
function GenerateReport(url) {
	document.forms[0].action = url;
	document.forms[0].submit();
}
function NumericOnly(event) {
	var KeyTyped = String.fromCharCode(getKeyCode(event));
	if (isNumeric(KeyTyped)) {
   		return true; 
   	}
	if (KeyTyped.charCodeAt(0) == 46 || KeyTyped.charCodeAt(0) == 45) {
		return true;
	}
	return false;
}
function getKeyCode(e) {
	//IE5
 	if (e.srcElement) {
 		return e.keyCode
 	}
  	// NC5
  	if (e.target) {
   		return e.which
  	}
}
function isNumeric(c) {
	var sNumbers = "01234567890";
	if (sNumbers.indexOf(c) == -1)
		return false;
	else return true;
}
function ShowNewConfiguration(szPointer, szDivID) // 1 visible, 0 hidden
{
    var strName = document.getElementById('Field'+szDivID+'Name').value;
    if (strName == '')
    {
    	alert('You need to set a name for the field before you change it\'s type');
    	SetSelectToAnOption(szPointer, 'Display None')
    	return;
    }

    var strPointer = document.getElementById(szPointer).value;
    if (strPointer == 'Value Only' || strPointer == 'Check Range' || strPointer == 'Intelligent Alert' || strPointer == 'Cumulative' || strPointer == 'Differential' || strPointer == 'RadComm Pressure' || strPointer == 'RadComm Flow') {
    	var iState = 1;
    }
    else {
    	var iState = 0;
    }
    if (szDivID < 2) {
    	return false;
    }
    if(document.layers)   //NN4+
    {
       document.layers['a_'+szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById('a_'+szDivID);
        obj.style.display = iState ? "block" : "none";
    }
    else if(document.all)// IE 4
    {
        document.all['a_'+szDivID].style.visibility = iState ? "visible" : "hidden";
    }
    // FindAllVariationMonitoring();
}
function anyMask(event, sMask)
{
	//var sMask = "**?##?####";
	var KeyTyped = String.fromCharCode(getKeyCode(event));
	var targ = getTarget(event);

	keyCount = targ.value.length;
	//alert(sMask.charAt(keyCount));

	if (sMask.charAt(keyCount) == '*')
    	return true; 
	if (sMask.charAt(keyCount) == KeyTyped)
		return true;
	if ((sMask.charAt(keyCount) == '#') && isNumeric(KeyTyped)) 
   		return true; 
	if ((sMask.charAt(keyCount) == 'A') && isAlpha(KeyTyped))
    	return true; 
    if ((sMask.charAt(keyCount) == '?') && isPunct(KeyTyped))
         return true; 
	if (KeyTyped.charCodeAt(0) < 32) return true;
    	return false;   
}
function getTarget(e)
{
	// IE5
   	if (e.srcElement) {
   		return e.srcElement;
   	}
    	if (e.target) {
   		return e.target;
   	}
}
function isPunct(c)
{
	var lCode = c.charCodeAt(0);
	if (lCode == 58) {
		return true;
	}
	else if (lCode >= 32 && lCode <= 47 ) {
		return true;
	}
	else {
		return false;
	}
}
// This function gets called when the end-user clicks on some date.
function selected(cal, date) {
  cal.sel.value = date; // just update the date in the input field.
  if (cal.dateClicked && (cal.sel.id == "sel1" || cal.sel.id == "sel3"))
    // 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();
}
// 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) {
  cal.hide();                        // hide the calendar
  cal.destroy();
  calendar = null;
}
function showCalendar(id, format, showsTime) {
  var el = document.getElementById(id);
  if (calendar != null) {
    calendar.hide();
  } else {
    var cal = new Calendar(true, null, selected, closeHandler);
    // if (typeof showsTime == "string")
    // {
      	cal.showsTime = true;
    	cal.time24 = (showsTime == "24");
    // }
    calendar = cal;
    cal.setRange(2003, 2070);
    cal.create();
  }
  calendar.setDateFormat(format);
  calendar.parseDate(el.value);
  calendar.sel = el;
  calendar.showAtElement(el.nextSibling, "Br");

  return false;
}
function y2k(number) { return (number < 1000) ? number + 1900 : number; }
var today = new Date();
var day   = today.getDate();
var month = today.getMonth();
var year  = y2k(today.getYear());
//
function padout(number) { return (number < 10) ? '0' + number : number; }
//
function newWindow() {
    mywindow=open('cal.htm','myname','resizable=no,width=350,height=270');
    mywindow.location.href = 'cal.htm';
    if (mywindow.opener == null) mywindow.opener = self;
}
function DownloadFile(trace, passedID, passedCompany) {
	var w = window.screen.width;
	var w = w / 2;
	var w = w - 150;
	h = window.screen.height;
	h = h / 2;
	h = h - 75;
	window.open('download.asp?trace='+trace+'&IDToUse='+passedID+'&Company='+passedCompany,'','resizable=yes,toolbar=no,scrollbars=yes,addressbar=no');
}
function Open_Chooser(passedGFLT, passedID, passedUnique) {
    window_handle = window.open('PopUpChooser.asp?Z='+passedGFLT+'&X='+passedID+'&W='+passedUnique,'Open_Chooser','status=yes,resizable=yes,toolbar=no,scrollbars=yes,addressbar=no,width=600,height=300');
    window_handle.focus();
    return false;
}
// --------
function Open_GPRSStatus(passedGFLT, passedWidth, passedHeight, passedDeviceUniqueID) {
	passedWidth = passedWidth - 40;
	passedHeight = passedHeight - 40;
	window.open('GPRS_Status.asp?Y='+passedGFLT+'&sW='+passedWidth+'&sH='+passedHeight+'&X='+passedDeviceUniqueID,"_blank",'resizable=yes,width='+passedWidth+',height='+passedHeight+',top=0,left=0,toolbar=no,scrollbars=yes,addressbar=no');
    	return false;
}
// --------
function validateKeyPress(e, validSet, objName)
{
	var key;
	var keychar;
	
	if (validSet == "@") {
		validSet=validScaling+' '+validLetters;
	}
	if(window.event || !e.which) {
		key = e.keyCode; // IE
	}
	else if(e) {
		key = e.which; // Netscape
	} else {
		return true; // no validation
	}
	keychar = String.fromCharCode(key);
	validSet += String.fromCharCode(8);
	if (validSet.indexOf(keychar) < 0) {
		return false; // validation
	} else {
		return true; // validation
	}
}
function Open_Graph(passedGFLT, passedSaveConfig, passedPortTotal, passedWidth, passedHeight) {
	// We need to check that at least one input is checked....
        var objMain = document.getElementById('OverRideForReduced')
	if (objMain == null) {
		var blnIsThereACheckedPort = true;
	} else if (objMain.value == "True") {
		var blnIsThereACheckedPort = true;
	} else {	
	        var blnIsThereACheckedPort = false;
	        for (i = 1; i <= passedPortTotal; i++) {
		 	var objMain = document.getElementById('PFS'+i)
		 	// alert('PFS'+i+' -- '+objMain.value);
		 	if (objMain.value == 'Checked') {
		 		blnIsThereACheckedPort=true;
		 	}
		}
	}
	if (blnIsThereACheckedPort == false) {
		alert('You must select at least one port');
		return false;
	}
	passedWidth = passedWidth - 40;
	passedHeight = passedHeight - 40;
	var objMain = document.getElementById('hSaveSelections');
	if (objMain != null) {
		objMain.value = passedSaveConfig;
	}
	window.open('GenerateGraph.asp?Z='+passedGFLT+'&sW='+passedWidth+'&sH='+passedHeight,"_blank",'resizable=yes,width='+passedWidth+',height='+passedHeight+',top=0,left=0,toolbar=no,scrollbars=yes,addressbar=no');
    	return false;
}
function Open_QuickGraph(passedGFLT, passedWidth, passedHeight) {
	passedWidth = passedWidth - 40;
	passedHeight = passedHeight - 40;
	window.open('GenerateGraph.asp?Z='+passedGFLT+'&sW='+passedWidth+'&sH='+passedHeight,"_blank",'resizable=yes,width='+passedWidth+',height='+passedHeight+',top=0,left=0,toolbar=no,scrollbars=yes,addressbar=no');
    	return false;
}
function Open_Request(passedGFLT) {
	window.open('Request.asp?Z='+passedGFLT,'','resizable=yes,width=600,height=400,top=0,left=0,toolbar=no,scrollbars=yes,addressbar=no');
    	return false;
}
function Open_Feedback(passedGFLT) {
	// var window_handle_feedback = 
	window.open('Feedback.asp?Z='+passedGFLT,'','resizable=yes,width=600,height=400,top=0,left=0,toolbar=no,scrollbars=yes,addressbar=no');
    	// window_handle_feedback.focus();
    	return false;
}
function Open_Error(passedGFLT, passedErrorDetails) {
	// var window_handle_error = 
	window.open('Error.asp?Z='+passedGFLT+'&Issue='+passedErrorDetails,'','resizable=yes,width=600,height=400,top=0,left=0,toolbar=no,scrollbars=yes,addressbar=no');
    	//window_handle_error.focus();
    	return false;
}
function insertAtEnd (elName, txt) {
	var el = document.getElementById(elName);
	el.value += txt;
	setCaretToEnd (el);
}
function setCaretToEnd (elName) {
	var el = document.getElementById(elName);	
	if (el.createTextRange) {
   		var v = el.value;
   		var r = el.createTextRange();
   		r.moveStart('character', v.length+1);
   		r.select();
   	}
}
//-->
