function toggleArrow (el) {
	var homeLeftMenuDiv = document.getElementById ("homeLeftMenu");
	var aDivs = homeLeftMenuDiv.getElementsByTagName("div");
	var aSpans = homeLeftMenuDiv.getElementsByTagName("span");
	var arrowRight = el.getElementsByTagName("span")[0];
	var arrowDown = el.getElementsByTagName("span")[1];

	subitemsDiv = el.parentNode.nextSibling;
	//fix for FF where nextSibling of el is not div with subitems but "\n "
	if (!subitemsDiv.className)
		subitemsDiv = subitemsDiv.nextSibling;

	for (i=0; i < aDivs.length; i++) {
		if (aDivs[i].className.indexOf("subitemsLevel2") > -1 && aDivs[i] != subitemsDiv && aDivs[i].className.indexOf("hidden") < 0) {
			aDivs[i].className = aDivs[i].className + " hidden";
		}
	}
	for (i=0; i < aSpans.length; i++) {
		if (aSpans[i].className.indexOf("arrowDown") > -1 && aSpans[i] != arrowDown && aSpans[i].className.indexOf("hidden") <0) {
			aSpans[i].className = aSpans[i].className + " hidden";
			aSpans[i].previousSibling.className = aSpans[i].previousSibling.className.replace(" hidden", "");
		}
	}
	if (arrowRight.className.indexOf("hidden")<0) {
		arrowRight.className = arrowRight.className + " hidden";
		arrowDown.className = arrowDown.className.replace(" hidden", "");
		subitemsDiv.className = subitemsDiv.className.replace(" hidden", "");
	} else {
		arrowDown.className = arrowDown.className + " hidden";
		arrowRight.className = arrowRight.className.replace(" hidden", "");
		subitemsDiv.className = subitemsDiv.className + " hidden";
	}
}

function DealersLocatorSearch(){
	var location = document.getElementById("_location");
	var state = document.getElementById("_state");
	var brand = document.getElementById("_brand");
	var collision = document.getElementById("_collision");
	var newURL = window.location.protocol + "//" + window.location.host + window.location.pathname;
	var aURL  = newURL.split('/');
	var pageName = aURL[aURL.length-1];
	newURL = newURL.replace(pageName, "");
	newURL = newURL + "dealer-locator.aspx";
	if (location.value != '' || brand.value != '' || collision.checked ){
		var isFirst= true;
		newURL = newURL + "?";
		if (location.value != '') {
			isFirst = false;
			newURL = newURL + '_location=' + location.value;
			if (location.value.toLowerCase() == 'us' && state!= null && state.value != '') {
				newURL = newURL + '&_state=' + state.value;
			}
		}
		if (brand.value != '') {
			if (!isFirst) newURL = newURL + '&'; 
			isFirst = false;
			newURL = newURL + '_brand=' + brand.value;
		}
		if (collision.checked) {
			if (!isFirst) newURL = newURL + '&'; 
			isFirst = false;
			if (collision.checked) newURL = newURL + '_collision=true';
			else  newURL = newURL + '_collision=false';
		}
	}
	window.location = newURL;
}

function OnChangeLocation() {
	var location = document.getElementById("_location");
	var state = document.getElementById("_state");
	if (location.value.toLowerCase() == 'us') {
		state.style.display = "inline";
	} else {
		state.style.display = "none";
	}
}

function clearEmploymetForm() {
	document.getElementById('_dealershipName').value = '';
	document.getElementById('_firstName').value = '';
	document.getElementById('_middleName').value = '';
	document.getElementById('_lastName').value = '';
	document.getElementById('_streetAddress').value = '';
	document.getElementById('_city').value = '';
	document.getElementById('_state').value = '';
	document.getElementById('_zipCode').value = '';
	document.getElementById('_phone').value = '';
	document.getElementById('_mobilePhone').value = '';
	document.getElementById('_emailAddress').value = '';
	document.getElementById('_multiLine').value = '';
	document.getElementById('_position').value = '';
}

function checkEmailStr(email) {
	if(!(/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$/.test(email))) {
		return false;
	} else {
		return true;
	}	
}

function ValidateEmploymentForm(positionError) {
    var errorList = '';
    if (document.getElementById("_dealershipName").value.length == 0) {
        errorList += '- Please select dealership.\n';
    }

    if (document.getElementById("_firstName").value.length == 0) {
        errorList += '- Please provide your First Name.\n';
    }
    
    if (document.getElementById("_lastName").value.length == 0) {
        errorList += '- Please provide your Last Name.\n';
    }

    if (document.getElementById("_streetAddress").value.length == 0) {
        errorList += '- Please provide your Street Address.\n';
    }

    if (document.getElementById("_city").value.length == 0) {
        errorList += '- Please provide your City.\n';
    }

    if (document.getElementById("_state").value.length == 0) {
        errorList += '- Please provide your State.\n';
    }

    if (document.getElementById("_state").value.length == 0) {
        errorList += '- Please provide your State.\n';
    }

    if (document.getElementById("_zipCode").value.length == 0) {
        errorList += '- Please provide your Zip Code.\n';
    }

    if (checkEmailStr(document.getElementById("_emailAddress").value) == false) {
        errorList += '- Please provide valid Email.\n';
    }

    if (document.getElementById("_position").value.length == 0) {
        errorList += '- Please provide ' + positionError + '.\n';
    }

    if (errorList != '') {
        alert('You must enter a value in the following fields: \n' + errorList);
        return false;
    } else
        return true;
}

function OpenWindowCenter(url, name, width, height, scroll){

	var params = '';
	if (scroll){
		params += 'scrollbars=yes, ';
		width = width + 16;
	} 
	var scrX = (document.all)?window.screenLeft:window.screen.left;
	var left   = scrX + (window.screen.width  - width)/2;
	var top    = (window.screen.height - height)/2;
	
	params += 'width=' + width + ', height=' + height;
	params += ', top=' + top+', left=' + left;
	popupWin = window.open(url, name, params);
	popupWin.focus();

}

function closeSelf() {
	window.open('','_parent','');
	window.opener = top;        
	window.close();
}

function flashLoader(flashMovie, flashVars, flashHeight, flashWidth, flashAlign, flashQuality, flashBGColor, flashID, flashScale) {
	var flashPluginSpace = 'http://www.macromedia.com/go/getflashplayer';
	document.write('<OBJECT type="application/x-shockwave-flash"  classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" WIDTH="' + flashWidth + '" HEIGHT="' + flashHeight + '" id="' + flashID + '" ALIGN="' + flashAlign + '">');
	document.write('<PARAM NAME="FlashVars" VALUE="' + flashVars + '">');
	document.write('<PARAM NAME="movie" VALUE="' + flashMovie + '">');
	document.write('<PARAM NAME="quality" VALUE="' + flashQuality + '">');
	if (flashScale == null) {
		var flashScale = '';
		var flashScaleParam = '';
	} else {
		document.write('<PARAM NAME="scale" VALUE="' + flashScale + '">');
		var flashScaleParam = ' scale="' + flashScale + '"';
	}
	document.write('<PARAM NAME="bgcolor" VALUE="' + flashBGColor + '">');
	document.write('<param name="wmode" value="transparent">');
	document.write('<param name="allowScriptAccess" value="always">');
	document.write('<EMBED src="' + flashMovie + '" quality="' + flashQuality + '"' + flashScaleParam + ' bgcolor="' + flashBGColor + '"  WIDTH="' + flashWidth + '" HEIGHT="' + flashHeight + '" NAME="' + flashID + '" ALIGN="' + flashAlign + '" TYPE="application/x-shockwave-flash" PLUGINSPAGE="' + flashPluginSpace + '" FlashVars="' + flashVars + '" wmode="transparent" allowScriptAccess="always"></EMBED>');
	document.write('</OBJECT>');
}
