/* site_functions.js
 * put site specific javascript functions here
 * is already included in header.tpl
 */

// new window popup used for opening up artwork and flash projects
function launchwin(uri,name,args){
	windowReference = window.open(uri,name,args);
	if (!windowReference.opener){
		windowReference.opener = self;
	}
	windowReference.focus();
}

function toggleReferralDivs(){
	if(document.getElementById("referralOption")){
		checkedValue = getChecked(document.forms[0].referralOption);
		if(checkedValue == "Yes"){
			document.getElementById("retail_dealer_name").style.width = "auto";
			document.getElementById("retail_dealer_name").style.display = "inline";
			document.getElementById("retail_dealer_name").style.visibility = "visible";
			
			document.getElementById("referral_type").style.width = "0px";
			document.getElementById("referral_type").style.display = "none";
			document.getElementById("referral_type").style.visibility = "hidden";
		} else {
			document.getElementById("retail_dealer_name").style.width = "0px";
			document.getElementById("retail_dealer_name").style.display = "none";
			document.getElementById("retail_dealer_name").style.visibility = "hidden";
			
			document.getElementById("referral_type").style.width = "auto";
			document.getElementById("referral_type").style.display = "inline";
			document.getElementById("referral_type").style.visibility = "visible";
		}
	}
}

function toggleVideoOptions(){
	if(document.getElementById("send_full_corporate_video")){
		if(document.getElementById("send_full_corporate_video").checked == true){
			document.getElementById("videoOptions").style.visibility = "visible";
		} else {
			document.getElementById("videoOptions").style.visibility = "hidden";
			document.getElementById("email_link").checked = false;
			document.getElementById("mail_dvd").checked = false;
		}
	}
}

function getChecked(formElementObject){
	for (i=0;i<formElementObject.length;i++){ 
		if (formElementObject[i].checked){ 
			return formElementObject[i].value; 
		} 
	}
}

function setMaxLength() {
	var x = document.getElementsByTagName('textarea');
	var counter = document.createElement('div');
	counter.className = 'counter';
	for (var i=0;i<x.length;i++) {
		if (x[i].getAttribute('maxlength')) {
			var counterClone = counter.cloneNode(true);
			counterClone.relatedElement = x[i];
			counterClone.innerHTML = 'Character Limit: <span>0</span>/'+x[i].getAttribute('maxlength');
			x[i].parentNode.insertBefore(counterClone,x[i].nextSibling);
			x[i].relatedElement = counterClone.getElementsByTagName('span')[0];

			x[i].onkeyup = x[i].onchange = checkMaxLength;
			x[i].onkeyup();
		}
	}
}

// use this from Flash for the centerpiece
function changeClass(elementId, newClassName){
	if(document.getElementById(elementId)){
		document.getElementById(elementId).setAttribute("class", newClassName);
	}
}

function checkMaxLength() {
	var maxLength = this.getAttribute('maxlength');
	var currentLength = this.value.length;
	if (currentLength > maxLength)
		this.relatedElement.className = 'toomuch';
	else
		this.relatedElement.className = '';
	this.relatedElement.firstChild.nodeValue = currentLength;
	// not innerHTML
}

function toggleMaterialSummary(materialId){
	var divId = "materialSummary" + materialId;
	if(document.getElementById(divId)){
		if(document.getElementById(divId).style.visibility && document.getElementById(divId).style.visibility == "visible"){
			document.getElementById(divId).style.visibility = "hidden";
			document.getElementById(divId).style.height = "0px";
		} else {
			document.getElementById(divId).style.visibility = "visible";
			document.getElementById(divId).style.height = "auto";
		}
	}
}

function imageMapHover(imageId, rollover){
	if(document.getElementById(imageId)){
		if(rollover){
			if(rollover == 'bellmont') pos = "0px 210px";
			else if(rollover == 'amero') pos = "0px 140px";
			else if(rollover == 'pacificcrest') pos = "0px 70px";
			document.getElementById(imageId).style.backgroundPosition = pos;
		} else {
			document.getElementById(imageId).style.backgroundPosition = "0px 0px";
		}
	}
}

function toggleBox(boxName) {
    box = document.getElementById(boxName);
    if (box.style.display == 'block') {
        box.style.display = 'none';
    }
    else {
        box.style.display = 'block';
    }
}

function toggleSearchBox(){
	var searchBox = document.getElementById("searchBox");
	//searchLink = document.getElementById("searchLink");
	if(searchBox.style && searchBox.style.visibility == "visible"){
		searchBox.style.visibility = "hidden";
		//searchLink.style.visibility = "visible";
	} else {
		searchBox.style.visibility = "visible";
		//searchLink.style.visibility = "hidden";
	}
}
