function submitToLegacyPage(url) {
	var theForm = getPageHeaderForm();
	theForm.method = "get";
	theForm.action = url;
	theForm.submit();
}

function submitToLegacyPopupPage(url, settings) {
	var theForm = getPageHeaderForm();
	url += "?ptz=" + theForm.ptz.value;
	url += "&ptt=" + theForm.ptt.value;
	url += "&ptd=" + theForm.ptd.value;
	url += "&pth=" + theForm.pth.value;
	var newWindow = window.open(url, "tms_popup", settings);
	newWindow.focus();
}

var _comparisonsPopup = null

function submitComparisons() {
	var theForm = getPageHeaderForm();
	var tdaId = theForm.tda_id.value;
	//_comparisonsPopup = popupWin(_comparisonsPopup, "comparisons", false, "/comparisons/index.aspx?tda_id=" + tdaId, 500, 800, false, false, false, false, true, true);
	//_comparisonsPopup = popupWin(_comparisonsPopup, "comparisons", false, "http://www.toyota.com/vehicles/compare.html?contenttype=kiosk&dealername=BAT", 500, 800, false, false, false, false, true, true);
	_comparisonsPopup = popupWin(_comparisonsPopup, "comparisons", false, "http://www.toyota.com/espanol/compare/#h_select", 500, 800, false, false, false, false, true, true);
}

var _configuratorWindow = null
function submitConfigurator() {
	//var url = "http://staging.toyota.com/byt/index.jsp?zipcode="
    var url = "/deeplinks/registerClick.aspx?"
	var theForm = getPageHeaderForm();
	var tdaId = theForm.tda_id.value;
	url += "tda_code=" + tdaId	
	
	var cookie_info = unescape(document.cookie);
	var crumbs = cookie_info.split("originatingZipCode=");
	var parameters = crumbs[1].split("&");
	url += "&zip_code=" + parameters[0];
	
	//alert('javascript - ' + url);
	_configuratorWindow = popupWin(_configuratorWindow, "configurator", false, url, 650, 850, true, true, true, true, true, true);

}

/*function popupWin(hwndPopup, windowName, closeFirst, sURL, Height, Width, toolbar, status, loc, menu, resize, scroll) {
	var	opts = "toolbar=" + (toolbar == false ? 0 : 1) + ",status=" + (status == false ? 0 : 1) + ",location=" + (loc == false ? 0 : 1) + ",menubar=" + (menu == false ? 0 : 1) + ",resizable=" + (resize == false ? 0 : 1) + ",";
	opts = opts + "height=" + Height + ",width=" + Width + ",scrollbars=" + (scroll == false ? 0 : 1);

	if (hwndPopup == null || hwndPopup.closed) {
		newPopup = window.open(sURL, windowName, opts);
		newPopup.focus();
		return newPopup;
	}

	if (closeFirst) {
		if (hwndPopup != null) { hwndPopup.close(); }
		newPopup = window.open(sURL, windowName, opts);
		newPopup.focus();
		return newPopup;
	}

	hwndPopup.location.href = sURL;
	hwndPopup.focus();
	return hwndPopup;			
} */


function submitTcuv() {
    
    var cookie_info = unescape(document.cookie);
    var tdacrumbs = cookie_info.split("tdaCode=");
    var tdaparameters = tdacrumbs[1].split("&");
    
    var tdaCode = tdaparameters[0];
    if (tdaCode.length >= 5) 
    {
        tdaCode = tdaCode.substring(0, 5);
    }
    
    var zipcrumbs = cookie_info.split("originatingZipCode=");
    var zipparameters = zipcrumbs[1].split("&");
    var zipcode = zipparameters[0];
    _comparisonsPopup = popupWin(_comparisonsPopup, "tcuv", false, "http://www.toyotacertificados.com/inventory/?SearchZipCode=" + zipcode + "&siteid=BAT_Esp_" + tdaCode + "__topnav_TCUV-Esp:TCUV-Esp_Search_Inventory ", 600, 1024, true, true, true, false, true, true);

	//submitHeader("/preowned/tcuvFrame.aspx");
}

function submitToToyota() {
	var cookie_info = unescape(document.cookie);
	var crumbs = cookie_info.split("originatingZipCode=");
	var parameters = crumbs[1].split("&");
	
	top.location = "http://www.toyota.com?zipcode=" + parameters[0];
	//top.location = "http://www.toyota.com/byt/pub/init.do?zip_code=" + parameters[0];	
}

var _toyotaWindow = null
function submitToToyotaNewWindow(url, addlQuerystring) {	
	var cookie_info = unescape(document.cookie);
	var crumbs = cookie_info.split("originatingZipCode=");
	var parameters = crumbs[1].split("&");
	
	url += "?zipcode=";
	url += parameters[0];
	if (addlQuerystring.length > 0) {
		url+= "&" + addlQuerystring;
	}	
	_toyotaWindow = popupWin(_toyotaWindow, "toyota", false, url, 650, 1050, true, true, true, true, true, true);

	//top.location = "http://www.toyota.com?zipcode=" + parameters[0];
}

function submitParticipatingDealers() {
	submitHeader("/participating_dealers/index.aspx");
}

function submitHeader(url) {
	var theForm = getPageHeaderForm();
	theForm.method = "post";
	theForm.action = url;
	theForm.submit();
}

//espanol.tmsbat2.local
function switchLanguage() {
	var theForm = getPageHeaderForm();
	theForm.method = "post";
	theForm.action = "http://espanol.tmsbat2.local" + page;
	theForm.submit();
}

function getPageHeaderForm() {
	return document.pageHeaderForm;
}
