// JavaScript Document
<!--

var verRequired = 9;
var nonflashURI = "/upgradeflash.do";
var flash = false;
var flashVer;
var refer = escape(location.href);
var activeX = ( ! navigator.plugins.length);
if (activeX) {
  document.write("\<script type=\"text/vbscript\"\> \n" +
	"On Error Resume Next \n" +
	"For count = 15 To 1 Step -1 \n" +
	"	plugVers = IsObject(CreateObject(\"ShockwaveFlash.ShockwaveFlash.\" & count)) \n" +
	"	If plugVers Then \n" +
	"		flashVer = count \n" +
	"		flash = true \n" +
	"		Exit For \n" +
	"	End If \n" +
	"Next \n" +
	"plugVers = nothing \n" +
	"\</script\> \n");
}else{
	flash = navigator.plugins["Shockwave Flash"];
	if (flash) flashVer = parseInt(flash.description.match(/\d+.\d+/i));
}

// if ((!flash || flashVer < verRequired)) location.href = nonflashURI + "?referrer=" + refer;

var BrowserDetect  = new Object;
BrowserDetect.OS = (navigator.userAgent.match('Win'))?'Win':(navigator.userAgent.match('Mac'))?'Mac':'';
BrowserDetect.browser = (navigator.userAgent.match('MSIE'))?'Explorer':(navigator.userAgent.match('Firefox'))?'Firefox':(navigator.userAgent.match('Safari'))?'Safari':(navigator.userAgent.match('Opera'))?'Opera':'';
BrowserDetect.version = (navigator.userAgent.match('MSIE'))? parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('MSIE')+5,navigator.userAgent.indexOf('MSIE')+8)):(navigator.userAgent.match('Firefox'))?parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('Firefox')+8,navigator.userAgent.indexOf('Firefox')+11)):(navigator.userAgent.match('Safari'))?parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('Safari')+7,navigator.userAgent.indexOf('Safari')+10)):(navigator.userAgent.match('Opera'))?parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('Opera')+6,navigator.userAgent.indexOf('Opera')+8)):'';

function newSize (width, height, divId) {
	var n_element = (getElem(divId) != null) ? getElem(divId) : (getElem("view") != null) ? getElem("view") : getElem("content");
	n_element.style.height = (typeof height == 'number')? height.toString() + "px" : height;
	if(width != null) n_element.style.width = (typeof width == 'number')? width.toString() + "px" : width;
}

function couponClosed() {
	if(isDOM('mainswf') && document.getElementById("mainswf").couponClosed != null) document.getElementById("mainswf").couponClosed();
}

function closePseudoCoupon() {
	removeElement('couponDiv');
	couponClosed();
}

function expand_to (d,t_element) {
	c_ht = t_element.offsetHeight;
	if ((d && (c_ht += inc) >= d) || ( ! d && (c_ht -= inc) <= 0)) {
		t_element.style.height = d + 'px';
		clearInterval(intv);
		if ( ! d) t_element.style.display = 'none';
		return true;
	}
	t_element.style.height = c_ht + 'px';
}

function toggle_menu (el) { 
	if(isDOM(el)){
	t_element = getElem(el);
	d = 0;
		if (t_element.offsetHeight == 0) {
			t_element.style.display = 'block';
			t_element.style.height = '0px';
			t_element.style.overflowY = 'hidden';
			d = t_element.scrollHeight;
		}
	inc = (t_element.scrollHeight / 250) * 100;
	intv = setInterval("expand_to(d,t_element)", 10);
	}
}

function staff_tabs (num) {
	var divs = new Array();
	var children = getElem('staff-sections').childNodes;
	for(x=0,count=0; x<children.length; x++) if(children[x].nodeName.toLowerCase() == "div") divs[count++] = (children[x]);
	var links = getElem('staff-tabs').getElementsByTagName("a");
	for (i = 0; i < links.length; i++) {
		if(divs[i]){
			if(i != num && num != 'all') divs[i].style.display = 'none';
			else divs[i].style.display = 'block';
		}
	}
}

function showVTD (modelId) {
	var url = "plugin.do?pluginId=inventory&action=vtd";
	if(modelId) {
		url += "&modelId=" + modelId;
	} else {
		alert("Please provide a model");
		return;
	}
	popup(url, "vtd", 630, 410, "scrollbars=yes,resizable=yes,status=yes");
}

function showCoupon(makeId) {
	var url = "view.do?pluginId=coupon";
	if(makeId) {
		url += "&makeId=" + makeId;
	}
	if(BrowserDetect['browser']!="Explorer" || (!isDmiPage && !jsonText)) popup(url, "coupon", 640, 480, "resize=no");
}

function showCouponPopOver() {
	var url = "view.do%3FpluginId=coupon%3Ahtml?TB_iframe=true&height=400&width=600"
	if(BrowserDetect['browser']!="Explorer" || (!isDmiPage && !jsonText)) TB_show(null, url, false);
}

function loadIframe (frameId, url) {
	if (window.frames[frameId]) {
		window.frames[frameId].location = url;
		return false;
	} else return true;
}

function toggle_details (num) {
	var divs = new Array();
	var children = getElem('details-list').childNodes;
	for(x=0,count=0; x<children.length; x++) if(children[x].nodeName.toLowerCase() == "div") divs[count++] = (children[x]);
	for (i = 0; i < divs.length; i++) divs[i].style.display = (i != num)? 'none' : 'block';
	getElem('incentives-list').style.display = (num != 'back')? 'none' : 'block';
}

function popup (url, target, width, height, options) {
	var _options = options + ",width=" + width + ",height=" + height;
	var top = (screen.height/2)-(height/2);
	var left = (screen.width/2)-(width/2);
	_options += ",top=" + top + ",left=" + left;
	window.open(url, target, _options);
}

function showPrivacy() {
	popup("custom.do?src=/pages/html/policy.vm", "privacy", 640, 480, "resize=yes,scrollbars=yes");
}

function getRequestParameter(param){
	var q = document.location.search || document.location.href.hash;
	if (q && q.indexOf(param + "=") != -1) {
		val = q.split(param + "=")[1];
		if (val.indexOf("&") != -1) val = val.split("&").shift();
		return val;
	}
	return "";
}

function getElem() {  
	if(arguments.length > 1)var g_elements = new Array();
		var g_element;
		for (i = 0; i < arguments.length; i++) {
			g_element = (typeof arguments[i] == 'string') ? document.getElementById(arguments[i]) : arguments[i];
			if (arguments.length == 1) return g_element;
			g_elements.push(g_element);
		}
	return g_elements;
}

function toggleDiv(status, divEl) {
	if(isDOM(divEl))getElem(divEl).style.display = (status) ? 'block' : 'none';
}

function changeDiv (show, hide, model) {
	if(isDOM(show))getElem(show).style.display = model;
	if(isDOM(hide))getElem(hide).style.display = 'none';
}

/*
** quick browser check this will be removed after my testing -Aaron */

var Browser = {
  Version: function() {
    var version = 999; // we assume a sane browser
    if (navigator.appVersion.indexOf("MSIE") != -1)
      version = parseFloat(navigator.appVersion.split("MSIE")[1]);
    return version;
  }
}

function correctPNG () {	
	if(Browser.Version() < 7) {
		/*
	for (i = 0; i < document.images.length; i++) {
		var img = document.images[i];
		var imgName = img.src.toUpperCase();
		if (imgName.substring(imgName.length - 3, imgName.length) == "PNG") {
			var imgID = (img.id) ? "id='" + img.id + "' " : "";
			var imgClass = (img.className) ? "class='" + img.className + "' " : "";
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
			var imgStyle = "display:inline-block;" + img.style.cssText;
			if (img.align == "left") imgStyle = "float:left;" + imgStyle;
			if (img.align == "right") imgStyle = "float:right;" + imgStyle;
			if (img.parentElement.href || img.parentElement.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
			if (img.parentElement.parentElement.href) img.parentElement.style.cursor = "hand";
			var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
			img.outerHTML = strNewHTML;
			i--;
		}
	}*/
	}
}

		
function removeElement (id) {
	if (isDOM(id)) document.body.removeChild(getElem(id));
	pageDimState(false);
}

function pageDimState(state) {
	if (state){
		dim = document.createElement('div');
		dim.id = 'dim';
		dim.className = 'dim';
		(typeof dim.style.filter != 'undefined') ? dim.style.filter = 'alpha(opacity=30)' : dim.style.opacity = '0.3';
		(document.body.firstChild) ? document.body.insertBefore(dim, document.body.firstChild) : document.body.appendChild(dim);
		if (typeof dim.style.filter != 'undefined') {
		comboBlocker = document.createElement('iframe');
		comboBlocker.id = 'comboBlocker';
		comboBlocker.setAttribute("frameborder", "0");
		comboBlocker.className = 'comboBlocker';
		document.body.appendChild(comboBlocker);
		}
	} else if (isDOM('dim')) {
		document.body.removeChild(dim);
		if (isDOM('comboBlocker')) document.body.removeChild(comboBlocker);
	}
}

function positionCoupon(w, h) {
	if (isDOM('couponDiv')) {
	if (isNaN(w) == true) w = getElem('couponDiv').offsetWidth;
	if (isNaN(h) == true) h = getElem('couponDiv').offsetHeight;
		getElem('couponDiv').style.left = (document.documentElement.clientWidth - w) / 2 + 'px';
		getElem('couponDiv').style.top = (document.documentElement.clientHeight - h) / 2 + 'px';
	}
	if (isDOM('comboBlocker')) {
		getElem('comboBlocker').style.left = (document.documentElement.clientWidth - w) / 2 + 'px';
		getElem('comboBlocker').style.top = (document.documentElement.clientHeight - h) / 2 + 'px';
	}
}

function createElement (uri, mediaType, w, h, cid, pid, make, page) {
if (mediaType == 'flash') {
if (make == 'undefined') make = null;
	swf = uri +'?cid=' + cid +'&pid=' + pid + '&couponStyle=pseudo&make=' + make;
	var f99Obj = new SWFObject(swf, "coupon", w, h, "7", "");
	f99Obj.addParam("menu", "false");
	if(BrowserDetect['OS']!="Mac" && BrowserDetect['browser'] != "Firefox"){
	f99Obj.addParam("wmode", "opaque");
}
f99Obj.write("couponDiv");
} else {
	c_element = document.createElement(mediaType);
	c_element.id = mediaType;
	c_element.className = mediaType;
	c_element.width = w;
	c_element.height = h;
	if (mediaType == 'img') c_element.alt = 'Loading Image';
	else if (mediaType == 'iframe') c_element.setAttribute("frameborder", "0");
	coupon.appendChild(c_element);
	function isLoaded () {
	if (mediaType == 'iframe' && page != 'undefined') c_element.src = uri + '?' + page;
	else c_element.src = uri;
}
setTimeout(isLoaded, 100);
}
}

function draw_coupon (uri, mediaType, w, h, cid, pid, make, page) {
	if(BrowserDetect['browser']!="Explorer" || (!isDmiPage && !jsonText)) drawElement(uri, mediaType, w, h, cid, pid, make, page);
}

function drawElement (uri, mediaType, w, h, cid, pid, make, page) {
if (window.location.search.indexOf('offer=false') != -1) var parameters = false;
if (make == '') make = 'null';
if (isDOM('couponDiv')) removeElement ('couponDiv');
if (parameters != false) {
if (BrowserDetect['OS']=="Mac" && BrowserDetect['browser'] == "Firefox") {
	pageDimState(false);
} else {
	pageDimState(true);
}
coupon = document.createElement('div');
coupon.id = 'couponDiv';
coupon.className = 'floater';
if (mediaType == true) mediaType = 'flash';
if (mediaType == 'flash') document.body.appendChild(coupon);
if (mediaType != 'flash') {
coupon.innerHTML = '<div id="close"><a href=\'javascript:removeElement("couponDiv");\' title="Click to Close">close</a></div>';
}
createElement (uri, mediaType, w, h, cid, pid, make, page);
if (mediaType != 'flash') document.body.appendChild(coupon);
positionCoupon(w, h);
}
window.onresize = positionCoupon;
}

var gotDOM = false;
function isDOM(elemOrIdString){
	elemOrIdString = (typeof elemOrIdString == 'string') ? elemOrIdString : elemOrIdString.id;
	gotDOM = (document.getElementById(elemOrIdString))? true: false;
	return gotDOM;
}

function isNotEmpty (elemValueString) {
	return /\S+/.test(elemValueString);
}

function isNotChecked (checkedElem) {
	return !checkedElem.checked;
}

function isNotSelected (selectElem) {
	var isNotSelected = (selectElem.selectedIndex == -1 || selectElem.selectedIndex == 0 || selectElem.options[selectElem.selectedIndex].getAttribute('value')=='select')? true : false;
	return isNotSelected;
}

function checkEmail (email) {
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	return filter.test(email);
}

//END -->


