//general site js functions

//submits a search from the main site search 
//currently disabled for internal site search. use this for atmoz search only.
function submitSearch() {
	var searchText = document.getElementById("fSearch").value;
	location.href=('http://search.storactive.com/search/?sp-a=sp100159cd&sp-q='+ searchText +'');
}

// Collapses the requested area
function doCollapse(elemId) {
	targetElement = document.getElementById(elemId);

	if (targetElement.style.display == "none") {
		targetElement.style.display = "";
	} else {
		targetElement.style.display = "none";
	}
}

//displays the other title field if 'other' selected
function checkTitle(selected) {
	if (selected == "Other") {
		document.getElementById("otherTitleDis").style.display = "";
		} else {
		document.getElementById("otherTitleDis").style.display = "none";
		}
	}


//displays the state/province selector if the country is US or Canada
//if the form has hidden value _recipientsOff, the original value will not be altered (routing override feature)
function countrySelect(name) {
	
	switch(name){
	case "US": case "United States": case "Canada":
	showState(1);
	break;
	default:
	showState(0);
	}
	
	//shows or hides the state selector in multiForm
	function showState(tf) {
		if (tf == 1) {
			document.getElementById("stateDis").style.display = "";
		} else {
			document.getElementById("stateDis").style.display = "none";
		}
	}
}

//displays the data protection field if 'yes' selected
function dataProtectionSelect(name) {
	
	switch(name){
	case "Yes":
	showDataProtection(1);
	break;
	default:
	showDataProtection(0);
	}
	
	//shows or hides the state selector in multiForm
	function showDataProtection(tf) {
		if (tf == 1) {
			document.getElementById("dataProtectionDis").style.display = "";
		} else {
			document.getElementById("dataProtectionDis").style.display = "none";
		}
	}
}


function productSelect(name) {
	switch(name){
	case "Atempo Live Backup":
		showTiNa(0);
		showArchiveForMessaging(0);
		showDigitalArchive(0);
		showLiveNavigator(0);
		showLiveBackup(1);
	break;
	case "Atempo Live Backup for Mac":
		showTiNa(0);
		showArchiveForMessaging(0);
		showDigitalArchive(0);
		showLiveNavigator(0);
		showLiveBackup(1);
	break;
	case "Atempo Time Navigator":
		showLiveBackup(0);
		showArchiveForMessaging(0);
		showDigitalArchive(0);
		showLiveNavigator(0);
		showTiNa(1);
	break;
	case "Atempo Digital Archive":
		showLiveBackup(0);
		showArchiveForMessaging(0);
		showTiNa(0);
		showLiveNavigator(0);
		showDigitalArchive(1);
	break;
	case "Atempo Digital Archive for Messaging":
		showLiveBackup(0);
		showDigitalArchive(0);
		showTiNa(0);
		showLiveNavigator(0);
		showArchiveForMessaging(1);
	break;
	case "Atempo Live Navigator":
		showTiNa(0);
		showArchiveForMessaging(0);
		showDigitalArchive(0);
		showLiveBackup(0);
		showLiveNavigator(1);
	break;
	default:
		showTiNa(0);
		showArchiveForMessaging(0);
		showLiveBackup(0);
		showDigitalArchive(0);
		showLiveNavigator(0);
	}
	
	//shows or hides the state selector in multiForm
	function showTiNa(tf) {
		if (tf == 1) {
			document.getElementById("numofserversDis").style.display = "";
		} else {
			document.getElementById("numofserversDis").style.display = "none";
		}
	}
	//shows or hides the state selector in multiForm
	function showLiveBackup(tf) {
		if (tf == 1) {
			document.getElementById("numofpcsDis").style.display = "";
		} else {
			document.getElementById("numofpcsDis").style.display = "none";
		}
	}
	//shows or hides the state selector in multiForm
	function showLiveNavigator(tf) {
		if (tf == 1) {
			document.getElementById("numofpcsDis").style.display = "";
		} else {
			document.getElementById("numofpcsDis").style.display = "none";
		}
	}
	//shows or hides the state selector in multiForm
	function showDigitalArchive(tf) {
		if (tf == 1) {
			document.getElementById("amountofstorageDis").style.display = "";
		} else {
			document.getElementById("amountofstorageDis").style.display = "none";
		}
	}
	//shows or hides the state selector in multiForm
	function showArchiveForMessaging(tf) {
		if (tf == 1) {
			document.getElementById("numofmailboxesDis").style.display = "";
		} else {
			document.getElementById("numofmailboxesDis").style.display = "none";
		}
	}
}

//Submits the form you pass to the target and url you provide
function submitForm(frm, target, url) {
    if (frm) {
        frm.action = url;
        frm.target = target;
        frm.submit();
    }
}

//Submits a form with id "multiForm" to the default system mailer and salesforce.com
function multiSubmit() {
    var frm = document.getElementById("multiForm");
    if (frm) {
        //Send Email
        submitForm(frm, "systemMailer",  "/inc/systemMailer.asp");
        
        //Send to SalesForce
        submitForm(frm, "salesForceSub", "https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8");
        
        //Give the SalesForce form time to submit
        var nextPage = (frm._returnPage) ? frm._returnPage.value : "/default.asp";
        setTimeout(function(url) {
            location.href = url;
        }, 2000, nextPage);
    }
    return false;
}

//Just sends an email
function justMail() {
	
	//set the action to the default system mailer
	document.multiForm.action = "/inc/systemMailer.asp";
	document.multiForm.target = "systemMailer";
    	document.multiForm.submit();

	//redirect to page specified in form as "_returnPage". if none specified, home page will be used
	if (!document.multiForm._returnPage) {
		location.href = '/default.asp';
	} else {
		location.href = document.multiForm._returnPage.value;
	}
}
