// JavaScript Document

function validateField(inputField,helpText,blankMessage)
	{
	if (inputField.value.length == 0)
		{
		if (helpText != null)
			{
			helpText.innerHTML = blankMessage;
			return false;
			}
		}
	else (helpText != null)
		{
		helpText.innerHTML = "*";
		return true;
		}
	}

function validateEmail(inputField,helpText,blankMessage)
	{
	if (inputField.value.length == 0)
		{
		if (helpText != null)
			{
			helpText.innerHTML = blankMessage;
			return false;
			}
		}
	else if (inputField.value != document.getElementById('email_address').value)
		{
		if (helpText != null)
			{
			helpText.innerHTML = "<div>E-mail address does not match.</div>";
			return false;
			}
		}
	else (helpText != null)
		{
		helpText.innerHTML = "*";
		return true;
		}
	}

function validatePassword(inputField,helpText,blankMessage)
	{
	if (inputField.value.length == 0)
		{
		if (helpText != null)
			{
			helpText.innerHTML = blankMessage;
			return false;
			}
		}
	else if (inputField.value != document.getElementById('password').value)
		{
		if (helpText != null)
			{
			helpText.innerHTML = "<div>Passwords do not match.</div>";
			return false;
			}
		}
	else (helpText != null)
		{
		helpText.innerHTML = "*";
		return true;
		}
	}

function validatePhone(inputField,helpText,blankMessage)
	{
	var regex = /^\d{3}-\d{3}-\d{4}$/;
	if (inputField.value.length == 0)
		{
		if (helpText != null)
			{
			helpText.innerHTML = blankMessage;
			return false;
			}
		}
	else if (!regex.test(inputField.value))
		{
		if (helpText != null)
			{
			helpText.innerHTML = "<div>Phone number form must be xxx-xxx-xxxx</div>";
			return false;
			}
		}
	else (helpText != null)
		{
		helpText.innerHTML = "*";
		return true;
		}
	}
	
function validateZip(inputField,helpText,blankMessage)
	{
	var regex = /^\d{5}(-\d{4})?$|^.{3}( )?.{3}$/;
	if (inputField.value.length == 0)
		{
		if (helpText != null)
			{
			helpText.innerHTML = blankMessage;
			return false;
			}
		}
	else if (!regex.test(inputField.value))
		{
		if (helpText != null)
			{
			helpText.innerHTML = "<div>Please enter a valid zip code</div>";
			return false;
			}
		}
	else (helpText != null)
		{
		helpText.innerHTML = "*";
		return true;
		}
	}	

function URLEncode(plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	
	return encoded;
};
//function validateField(inputField,helpText,blankMessage)
//	{
//	if (inputField.value.length == 0)
//		{
//		if (helpText != null)
//			{
//			helpText.innerHTML = blankMessage;
//			return false;
//			}
//		}
//	else (helpText != null)
//		{
//		helpText.innerHTML = "*";
//		return true;
//		}
//	}
//
//function validateEmail(inputField,helpText,blankMessage)
//	{
//	if (inputField.value.length == 0)
//		{
//		if (helpText != null)
//			{
//			helpText.innerHTML = blankMessage;
//			return false;
//			}
//		}
//	else if (inputField.value != document.form1.email_address.value)
//		{
//		if (helpText != null)
//			{
//			helpText.innerHTML = "E-mail address does not match.";
//			return false;
//			}
//		}
//	else (helpText != null)
//		{
//		helpText.innerHTML = "*";
//		return true;
//		}
//	}
//
//function validatePassword(inputField,helpText,blankMessage)
//	{
//	if (inputField.value.length == 0)
//		{
//		if (helpText != null)
//			{
//			helpText.innerHTML = blankMessage;
//			return false;
//			}
//		}
//	else if (inputField.value != document.form1.password.value)
//		{
//		if (helpText != null)
//			{
//			helpText.innerHTML = "Passwords do not match.";
//			return false;
//			}
//		}
//	else (helpText != null)
//		{
//		helpText.innerHTML = "*";
//		return true;
//		}
//	}
//
//function validatePhone(inputField,helpText,blankMessage)
//	{
//	var regex = /^\d{3}-\d{3}-\d{4}$/;
//	if (inputField.value.length == 0)
//		{
//		if (helpText != null)
//			{
//			helpText.innerHTML = blankMessage;
//			return false;
//			}
//		}
//	else if (!regex.test(inputField.value))
//		{
//		if (helpText != null)
//			{
//			helpText.innerHTML = "Phone number form must be xxx-xxx-xxxx";
//			return false;
//			}
//		}
//	else (helpText != null)
//		{
//		helpText.innerHTML = "* ex. xxx-xxx-xxxx";
//		return true;
//		}
//	}
//	
//function validateZip(inputField,helpText,blankMessage)
//	{
//	var regex = /^\d{5}(-\d{4})?$|^.{3}( )?.{3}$/;
//	if (inputField.value.length == 0)
//		{
//		if (helpText != null)
//			{
//			helpText.innerHTML = blankMessage;
//			return false;
//			}
//		}
//	else if (!regex.test(inputField.value))
//		{
//		if (helpText != null)
//			{
//			helpText.innerHTML = "Please enter a valid zip code";
//			return false;
//			}
//		}
//	else (helpText != null)
//		{
//		helpText.innerHTML = "*";
//		return true;
//		}
//	}	

function updateDatePullDownMenu(objForm, fieldName) 
{
	var pdmDays = fieldName + "_days";
	var pdmMonths = fieldName + "_months";
	var pdmYears = fieldName + "_years";

	time = new Date(objForm[pdmYears].options[objForm[pdmYears].selectedIndex].text, objForm[pdmMonths].options[objForm[pdmMonths].selectedIndex].value, 1);

	time = new Date(time - 86400000);

	var selectedDay = objForm[pdmDays].options[objForm[pdmDays].selectedIndex].text;
	var daysInMonth = time.getDate();

	for (var i=0; i<objForm[pdmDays].length; i++)
	{
		objForm[pdmDays].options[0] = null;
	}

	for (var i=0; i<daysInMonth; i++)
	{
		objForm[pdmDays].options[i] = new Option(i+1);
	}

	if (selectedDay <= daysInMonth)
	{
		objForm[pdmDays].options[selectedDay-1].selected = true;
	}
	else
	{
		objForm[pdmDays].options[daysInMonth-1].selected = true;
	}
}
function downloadMWC2009() { //v3.0
	window.location.replace('/video/MWC2009.zip');
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function downloadMIRACLE5() { //v3.0
	window.location.replace('/downloads/Miracle5.zip');
}
function downloadMIRACLEVICTORY() { //v3.0
	window.location.replace('/downloads/Miracle_Victory_Team.zip');
}
function downloadALLIANCE() { //v3.0
	window.location.replace('/downloads/Alliance.zip');
}
function downloadFULLNESS() { //v3.0
	window.location.replace('/downloads/Fullness.zip');
}
function downloadPBA() { //v3.0
	window.location.replace('/downloads/PBA.zip');
}
function downloadVICTORYBUILDERS() { //v3.0
	window.location.replace('/downloads/VictoryBuilders.zip');
}
function downloadMEAD() { //v3.0
	window.location.replace('/downloads/MEAD.zip');
}
function downloadMILLIONAIREPROMO() { //v3.0
	window.location.replace('/downloads/MILLIONAIREPROMO.zip');
}
function downloadVENTURA() { //v3.0
	window.location.replace('/downloads/VENTURA.zip');
}
function downloadGONZALEZ() { //v3.0
	window.location.replace('/downloads/GONZALEZ.zip');
}
function downloadHOWARD() { //v3.0
	window.location.replace('/downloads/HOWARD.zip');
}
function downloadREACH() { //v3.0
	window.location.replace('/downloads/REACH.zip');
}
function downloadYOUNGER() { //v3.0
	window.location.replace('/downloads/YOUNGER.zip');
}
function downloadROCKY() { //v3.0
	window.location.replace('/downloads/ROCKY.zip');
}
function downloadVALLIANTYOZI() { //v3.0
	window.location.replace('/downloads/VALLIANTYOZI.zip');
}
function downloadVERDUGO() { //v3.0
	window.location.replace('/downloads/VERDUGO.zip');
}
function downloadNEIL() { //v3.0
	window.location.replace('/downloads/NEIL.zip');
}
function downloadVERDUGO2() { //v3.0
	window.location.replace('/downloads/VERDUGO2.zip');
}
function downloadVICTORY2() { //v3.0
	window.location.replace('/downloads/VICTORY2.zip');
}
function downloadKORNEGAY2() { //v3.0
	window.location.replace('/downloads/KORNEGAY2.zip');
}
function downloadKAN2() { //v3.0
	window.location.replace('/downloads/KAN2.zip');
}
function downloadHAWES5() { //v3.0
	window.location.replace('/downloads/HAWES5.zip');
}
function downloadVAILLANT2() { //v3.0
	window.location.replace('/downloads/VAILLANT2.zip');
}
function downloadKNOTTMEDRANO() { //v3.0
	window.location.replace('/downloads/Knott-Medrano.zip');
}
function showHideDIV (elementID) {
	whichElement = document.getElementById(elementID);
	if (whichElement.style.display == 'none') {
		whichElement.style.display = 'block';
	}else {
		whichElement.style.display = 'none';
	}
}

function visHideDIV (elementID) {
	whichElement = document.getElementById(elementID);
	if (whichElement.style.visibility == 'hidden') {
		whichElement.style.visibility = 'visible';
	}else {
		whichElement.style.visibility = 'hidden';
	}
}

function showYNDIV (elementID) {
	whichElement = document.getElementById(elementID);
	whichElement.style.display = 'block';
}

function hideYNDIV (elementID) {
	whichElement = document.getElementById(elementID);
	whichElement.style.display = 'none';
}
function hideTextDIV (elementID) {
	whichElement = document.getElementById(elementID);
	whichElement.style.display = 'none';
}

function showTextDIV(selObj,restore){ //v3.0
	eval(whichElement = document.getElementById(selObj.options[selObj.selectedIndex].value));
	whichElement.style.display = 'inline';
	whichElement.style.fontWeight = 'bold';
	if (restore) selObj.selectedIndex=0;
}

function clearText(field){
 	var field1 = document.getElementById(field);
    if (field1.value == '0.00') {
		field1.value = '';
	}
}

function addMask(field) {
 	var field1 = document.getElementById(field);
	if (field1.value == '') {
		field1.value = '0.00';
	}
}

function clearTextDOB(field){
	if(field.value == "MM/DD/YYYY"){
		field.value = '';
	}
}

function addMaskDOB(field) {
	if (field.value == ''){
		field.value = "MM/DD/YYYY";
	}
}
function clearTextAll(field){
    if (field.defaultValue == field.value) {
		field.value = '';
	}
}

function addMaskAll(field) {
	if (field.value == '') {
		field.value = field.defaultValue;
	}
}
function showTextDIV(selObj,restore){ //v3.0
	eval(whichElement = document.getElementById(selObj.options[selObj.selectedIndex].value));
	whichElement.style.display = 'inline';
	whichElement.style.fontWeight = 'bold';
	if (restore) selObj.selectedIndex=0;
}

function toggleElement(sel1, element) {
  var element1 = document.getElementById(element);
  if (sel1.value == 'OTHER_AMOUNT') {
    element1.style.display = 'block';
	document.getElementById('other_amount').value = '0.00';
  } else {
    element1.style.display = 'none';
	document.getElementById('other_amount').value = '';
  }
  return;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


// ====================================================================
//       URLEncode and URLDecode functions
//
// Copyright Albion Research Ltd. 2002
// http://www.albionresearch.com/
//
// You may copy these functions providing that 
// (a) you leave this copyright notice intact, and 
// (b) if you use these functions on a publicly accessible
//     web site you include a credit somewhere on the web site 
//     with a link back to http://www.albionresarch.com/
//
// If you find or fix any bugs, please let us know at albionresearch.com
//
// SpecialThanks to Neelesh Thakur for being the first to
// report a bug in URLDecode() - now fixed 2003-02-19.
// ====================================================================
function URLEncode(plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	
	return encoded;
};
