function writeToNewWindow(theText, windowName, windowProps) {
	var pageName='style.asp';
	var gidstart=0;
	var gidend=0;
	var loc=document.location.href;
	
	if (loc.indexOf('gid=')>-1 && loc.indexOf('gid=0')==-1) {
		//There is a gid reference on the querystring, and it's not zero-value
		//This must be appended to the URL to acquire the proper CSS in the heirarchy.
		gidstart=loc.indexOf('gid=')+4; //Start location of the gid parameter
		gidend=loc.indexOf('&',gidstart);
		if (gidend==-1) { gidend=loc.length; }
		pageName+='?gid='+loc.substring(gidstart,gidend);
	}
	
	var handle=window.open('', windowName, windowProps); //Dynamic Window
	handle.document.write('<html><head><link rel="stylesheet" type="text/css" href="'+pageName+'"><title>Amortization Table</title></head><body>');
	handle.document.write(theText);
	handle.document.write("</body></html>");
}

function launch(strURL,strType,dblDealerID) {
	strURL=escape(strURL);
	strType=escape(strType);
	var handle=window.open('launch.asp?url='+strURL+'&tracktype='+strType+'&did='+dblDealerID);
}

function submitCreateAgent() {

//document.submitcreateagent.submit();
	if (document.submitcreateagent) { document.submitcreateagent.submit(); }
}

function updateQueryString(queryString, newKey, newValue) {
	//Function to alter the contents of a querystring.  It will add the value if not present,
	//	or change the value if it already exists.
	//Querystring can be passed in as location.search.substring(1)
	
	//Possible routine to URL encode the newValue and keyName
	var newString='';
	var word=queryString
	var keyPairs=word.split('&');
	var delim='';
	//var keyPairs=queryString.split('&')
	//var keyPairs=word.split('&');
	var pos;
	var match=false;
	
	for (var i=0; i<keyPairs.length; i++) {
	
		//Make sure we have name/value pair
		pos=keyPairs[i].indexOf('=');
		if (pos != -1) {
			var key=keyPairs[i].substring(0,pos);
			var value=keyPairs[i].substring(pos + 1);
			//Check for match.
			if (key==newKey) {
				//replace the existing key in new string.
				newString+=delim+newKey+'='+newValue;
				match=true;
				delim='&';
			} else {
				//add the new key to new string.
				newString+=delim+keyPairs[i];
				delim='&';
			}
		}
	}
	if (!match) { newString+=delim+newKey+'='+newValue; }
	return newString;
}

function submitPasswordRequest() {
	if (document.login) {
		if (document.login.loginemail.value=='') {
			alert('Enter email address');
		} else {
			document.login.requestpwd.value='true';
			document.login.submit();
		}
	}
}

/*
function toggleDIV(object) {

	if (document.all) {
		if (document.all[object].style.display == "none") {
			document.all[object].style.display = "inline" ;
		} else {
			document.all[object].style.display = "none" ;
		}
	}
	if (document.getElementsByTagName && document.getElementsByTagName(object)) {
		if (document.getElementsByTagName(object).style.display == "none") {
			document.getElementsByTagName(object).style.display = "inline" ;
			document.getElementsByTagName(object).style.visibility = "visible" ;
		} else {
			document.getElementsByTagName(object).style.display = "none" ;
			document.getElementsByTagName(object).style.visibility = "hidden" ;
		}
	}
}
*/

function toggleDIV(object) {

	if (document.getElementById) {
              displayType = (document.getElementById(object).style.display == 'none') ? 'inline' : 'none';
              document.getElementById(object).style.display=displayType;
         }
         else if (document.layers) {
              displayType = (document.layers(object).style.display == 'none') ? 'inline' : 'none';
              document.layers(object).style.display=displayType;
         }
         else if (document.all) {
              displayType = (document.all(object).style.display == 'none') ? 'inline' : 'none';
              document.all(object).style.display=displayType;
         }

}


function validatePersonalInfo(theForm) {
	//Add items to the 'theMsg' variable if fields don't check out.
	var theMsg='';

	if (theForm) {
		if (theForm.firstname.value.length==0) {
			theMsg+='First name is required\n';
		}
		if (theForm.lastname.value.length==0) {
			theMsg+='Last name is required\n';
		}
		if (theForm.email.value.length==0) {
			theMsg+='Email Address is required\n';
		}
		if (theForm.emailbodytype.value=='') {
			theMsg+='Email Type is required\n';
		}
		
		//Fields required, if present
		if (theForm.password) {
			if (theForm.password.value.length==0) {
				theMsg+='Password is required\n';
			}
		}
		//Fields required, if present
		if (theForm.confirmpassword) {
			if (theForm.confirmpassword.value.length==0) {
				theMsg+='Confirm Password is required\n';
			}
		}

		//Fields required to be the same, if present and both valued.
		if (theForm.password && theForm.confirmpassword) {
			if (theForm.password.value.length>0 && theForm.confirmpassword.value.length>0) {
				if (theForm.password.value != theForm.confirmpassword.value) {
					theMsg+'Password and Confirm password values do not match.\n'
				}
			}
		}

	}
	
	return theMsg;	
}



