/* Global Javascript Functions */

//open window

function popup(url,winName,w,h) {
	newWin = window.open(url,winName,"width=" + w + ",height=" + h + ",menubar=no,scrollbars=yes,resizable=yes,toolbar=no")
}
function popup2(url,winName,w,h) {
	newWin = window.open(url,winName,"width=" + w + ",height=" + h + ",menubar=no,scrollbars=no,resizable=no,toolbar=no")
}
// w=width, h=height, m=menubar, s=scrollable, r=resizeable, t=toolbar
function popup3(url,winName,w,h,m,s,r,t) {
	newWin = window.open(url,winName,"width=" + w + ",height=" + h + ",menubar=" + m + ",scrollbars=" + s + ",resizable=" + r + ",toolbar=" + t + "")
}



/* submit button through link */
function formSubmit(thisForm,name,value) {
	if (name && value) {
		var hiddenField = document.createElement("input");
		hiddenField.setAttribute("type","hidden");
		hiddenField.setAttribute("name",name);
		hiddenField.setAttribute("value",value);
		thisForm.appendChild(hiddenField);
	}
	thisForm.submit();
}

/* formats a number with appropriate commas */
function commaNum(num) {
	var formattedNum = "";
	var stringNum = "" + num;
	var numPart = 0;
	var separator = "";
	for (var i = stringNum.length; i > 0; i=i-3) {
		numPart = ((i-3) < 0) ? 0 : (i-3);
		formattedNum = "" + stringNum.substring(numPart,i) + separator + formattedNum;
		separator = ",";
	}
	return formattedNum;
}

//pop up that takes different parameters
// this will center the window within the browser and bring the window to focus
var legendWin;
function createWin(url,width,height) {

	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	if(legendWin == null || legendWin.closed) {
		var props = "resizable,scrollbars=no,left=" + left + ",top=" + top + ",width=" + width + ",height=" + height;
		legendWin = window.open(url, "legend", props);
		legendWin.focus();
	} else {
		legendWin.close();
		var props = "resizable,scrollbars=no,left=" + left + ",top=" + top + ",width=" + width + ",height=" + height;
		legendWin = window.open(url, "legend", props);
		legendWin.focus();
	}
}


/* incentives popup */
function winincentivesopen() {
	var w = 540, h = 500;

	if (document.all || document.layers) {
	w = screen.availWidth;
	h = screen.availHeight;
	}

	var popW = 540, popH = 500;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;

	var myWindow;
	myWindow = window.open("displayRegionalIncentivesPopup.action", "regionalIncentives", "width=" + popW + ",height=" + popH + ",top=" + topPos + ",left=" + leftPos + ",resizable=no,status=no,scrollbars=yes");
	myWindow.focus();
}

function cleanWin(url,width,height) {
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	newWin = window.open(url,"popup","left=" + left + ",top=" + top + ",width=" + width + ",height=" + height + ",menubar=no,scrollbars=no,resizable=no,toolbar=no")
}

function staticRedirect() {
	alert('Maintenance on MazdaUSA.com is complete.  You are being redirected to the MazdaUSA.com home page where all features are accessible.');
	if(window.location.href.indexOf("forward=false") < 0) window.location.href='http://www.mazdausa.com/MusaWeb/displayHomepage.action';
}

function submitAnchoredForm(formObj, anchorDropDownObj) {
	formObj.action+="#"+anchorDropDownObj.options[anchorDropDownObj.selectedIndex].value;
	formObj.submit();
}