var popupWindow;
function openWindow(url) {
//    popupWindow = window.open(url, "popupWindow",
//        "resizable=yes, left=1, top=1, height=200, width=300, scrollbars=yes");
//    popupWindow.focus();
    Modalbox.show(url, {title: document.title, width: 300, height: 200});
    return false;
}
var privacyPolicyWindow;
function displayPrivacyPolicy(siteId) {
    var url = 'privacyPolicy.do?method=displayPrivacyPolicy&privacySiteId='+siteId; 
    //privacyPolicyWindow = window.open(url, "privacyPolicyWindow","resizable=no, left=1, top=1, height=400, width=500, scrollbars=yes");
    //privacyPolicyWindow.focus();
    Modalbox.show(url, {title: "Site Privacy Policy", width: 600, height: 500});
    return false;
}

var featureDescriptionWindow;
function displayFeature(featureId) {
    var url = 'displayFeature.do?method=displayFeatureDescription&featureId='+featureId;
//    featureDescriptionWindow = window.open(url, "featureDescriptionWindow",
//        "resizable=no, left=150, top=150, height=300, width=400, scrollbars=yes");
//    featureDescriptionWindow.focus();
    Modalbox.show(url, {title: document.title, width: 400, height: 300});
    return false;
}

//wtb 9.4.03 Terms of Use
function displayTermsOfUse() {
    var url = 'termsOfUse.do?privacySiteId=1';
    Modalbox.show(url, {title: document.title, width: 550, height: 400});
    return false;
}

var sameWindow;
function openInSameWindow(url) {
//    sameWindow = window.open(url, "_top");
//    sameWindow.focus();
    Modalbox.show(url, {title: document.title});
    return false;
}
var printWindow;
function openPrintWindow(url) {
    printWindow = window.open(url, "printWindow",
        "resizable=yes, left=1, top=1, height=570, width=700, scrollbars=yes");
    printWindow.focus();
}
var questionWindow;
function openQuestionWindow(url) {
//    questionWindow = window.open(url, "questionWindow",
//        "resizable=no, left=100, top=100, height=600, width=840, scrollbars=yes");
//    questionWindow.focus();
    Modalbox.show(url, {title: document.title, width: 840, height: 600});
    return false;
}
var helpWindow;
function displayHelp(helpKey) {
    var helpUrl = "getHelp.do?helpKey=" + helpKey;
//    helpWindow = window.open(helpUrl, "helpWindow",
//        "resizable=no, left=1, top=1, height=200, width=400, scrollbars=yes");
//    helpWindow.focus();
    Modalbox.show(helpUrl, {title: document.title});
    return false;
}

function displayIframeHelp(helpKey) {
    var helpUrl = "getHelp.do?helpKey=" + helpKey;
    helpWindow = window.open(helpUrl, "helpWindow",
        "resizable=no, left=1, top=1, height=200, width=400, scrollbars=yes");
    helpWindow.focus();
}

function toggleDiv( targetId ){
	target = document.getElementById( targetId );
  	if (target.style.display == "none"){
  		target.style.display = "";
  	} else {
  		target.style.display = "none";
  	}
}

function showDiv(targetId) {
    target = document.getElementById( targetId );
  	if (target.style.display == "none"){
  		target.style.display = "";
  	}
}

function showHelpDiv(divId, xOffSet, yOffSet, width) {
    var c = getAnchorPosition(divId);
    showDiv(divId, c.x + xOffSet, c.y + yOffSet, width);
}

function showHelpDivWithUniqueAnchor(anchorId, divId, xOffSet, yOffSet, width) {
    var c = getAnchorPosition(anchorId);
    //showDiv(divId, c.x + xOffSet, c.y + yOffSet, width);
    var b = $j("#" + divId + ".button");
    b.remove();
    var content = document.getElementById(divId).innerHTML;
    Modalbox.show(content, {title: document.title, width: width});
    return false;
}

function showDiv(targetId, x, y, width) {
    target = document.getElementById( targetId );
  	if (target.style.display == "none"){
  	    target.style.position = "absolute";
  	    target.style.left = x;
  	    target.style.top = y;
  	    target.style.width = width
  		target.style.display = "";
  	}
}

function hideDiv(targetId) {
    target = document.getElementById( targetId );
  	if (target.style.display != "none"){
  		target.style.display = "none";
  	}
}

function hideHelpDivs() {
//    var helpDivIds = window.helpDivIds;
//    if(helpDivIds == null) {
//      return;
//    }
//    for(i=0; i<helpDivIds.length; i++) {
//      hideDiv(helpDivIds[i]);
//    }
	
	if (Modalbox.initialized) {
		Modalbox.hide();
		return false;		
	}
}


function no_click(e){
    //alert("No Click called");
	if (navigator.appName == 'Netscape' && ( e.which == 2 || e.which == 3))
	{
		;return false;
	}
	if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3))
	{
		;return false;
	}
}

function disableHistory() {
    //alert("Disable History");
    //window.captureEvents(Event.MOUSEDOWN);

    window.onmousedown=no_click;
    document.onmousedown=no_click;
}

function disableBackButton() {
//	alert("disableBackButton--DEBUG MSG");
    disableHistory();
    window.history.forward(1);
}		

function filterSecretQuestions() {
	 	
	with (document.forms[0]) {
 	 	var monthIndex = elements['month'].selectedIndex;
 	 	var themonth = elements['month'].options[monthIndex].value;
 	 	var dayIndex = elements['day'].selectedIndex;
 	 	var theday = elements['day'].options[dayIndex].value;
 	 	var yearIndex = elements['year'].selectedIndex;
 	 	var theyear = elements['year'].options[yearIndex].value;	 	 	

		if (theday == '0' || themonth == '-1' || theyear == '0') {
			//alert("theday=" + theday + " themonth=" + themonth + " theyear="+theyear);
			resetSecretQuestions();
			return;
		}
		
		var age = getUserAge(theday, themonth, theyear);

 		//Should follow this structure...
 		//var teenQuestionString = new String("1:Question 1,2:Question 2");	 		
 		var teenQuestions = teenQuestionString.value.split(',');
 		var adultQuestions = adultQuestionString.value.split(',');
 		var childQuestions = childQuestionString.value.split(',');
 		

 		//alert('age=' + age + ' childMax=' + childMax.value + ' teenMax='+teenMax.value);
		if (age > childMax.value && age <= teenMax.value) { 
			//alert('im a teen');
			addOptions( elements['secretQuestion'], teenQuestions);
		} else if (age <= childMax.value) {
			//alert('im a child');
			addOptions( elements['secretQuestion'], childQuestions);
		} else {
			//alert('im an adult');
			addOptions( elements['secretQuestion'], adultQuestions);
		}
	}
}

function addOptions(selectbox, list) {
	
	clearSecretQuestions(selectbox);

	for (var i=0; i < list.length;++i) {
		var textValue = list[i].split(":");
		addOption(selectbox, textValue[1], textValue[0]);
	}
}

function clearSecretQuestions(selectbox) {
	//var selectbox = document.forms[0].elements["secretQuestion"];
	if (selectbox.options) {
		var numberOfOptions = selectbox.options.length  
		for (i=0; i<numberOfOptions; i++) {  
		 	//Note: Always remove(0) and NOT remove(i)  
			selectbox.remove(0)  
		}  
	}
}

function resetSecretQuestions() {
	var selectbox = document.forms[0].elements["secretQuestion"];
	clearSecretQuestions(selectbox);
	addOption(selectbox,"Choose a password hint" , "0" );
}


function addOption(selectbox,text,value )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}

function disableContinueBtn(disabled) {
	var submitBtn = document.getElementById('continueBtn');
	if (!disabled) {
		enable(submitBtn);
	} else {
		disable(submitBtn);
	}
	return false;
	
//	var submitBtn = document.getElementById('continueBtn');
//	if (disable) {
//		submitBtn.disabled = true;
//		submitBtn.className = "button_disabled";
//	} else {
//		submitBtn.disabled = false;
//		submitBtn.className = "button";
//	}
}

function isDateSelected(monthSel, daySel, yearSel) {
	if (monthSel.selectedIndex > 0 && daySel.selectedIndex > 0 && yearSel.selectedIndex > 0) {
		return true;
	}
	else {
		return false;
	}
}

function getUserAge(month, day, year) {
	var dd = parseInt(day);
		var mm = parseInt(month);
		var yy = parseInt(year);
		
		var days = new Date();
		var gdate = days.getDate();
		var gmonth = days.getMonth();
		var gyear = days.getFullYear();
		if (gyear < 2000) gyear += 1900;
		var age = gyear - yy;

		if ((mm == (gmonth)) && (dd <= parseInt(gdate))) 
		{
			age = age; 
		} 
		else 
		{
			if (mm < (gmonth)) 
			{
				age = age;
			} 
			else 
			{
				age = age - 1; 
	   		}
		}

		if (age == 0) age = age;
		return age;	
}

function isChild(childMax, age) {
	return parseInt(age) <= parseInt(childMax)
}

function isTeen(childMax, teenMax, age) {
	return parseInt(age) > parseInt(childMax) && parseInt(age) <= parseInt(teenMax)
	
}
function isAdult(teenLoginAllowed, teenMax, age) {
	// if teens not allowed, min adult age is 18.
	if (!teenLoginAllowed) {
		teenMax = 17;
	}
	return parseInt(age) > parseInt(teenMax);
}

function setOptionalFeaturesDefaultValues() {
	for (i=0; i < document.forms[0].elements.length; i++) {
		if (document.forms[0].elements[i].name.indexOf('default_optinMap.propertyValue') != -1) 
		{
			var defaultSetting = document.forms[0].elements[i];

			var optInRadioName = defaultSetting.name.substring(8);
			var optInRadio = document.forms[0].elements[optInRadioName];

			if (defaultSetting.value == "true")
			{
				optInRadio[0].checked = true;
			}
			else
			{
				optInRadio[1].checked = true;
			}
		}
	}
}

