/****************************************************/
function include(script_filename) {
    document.write('\n\t<' + 'script');
    document.write(' type="text/javascript"');
    document.write(' language="javascript"');
    document.write(' src="' + script_filename + '">');
    document.write('</' + 'script' + '>');
}

function includeCSS(script_filename) {
    document.write('\n\t<' + 'link rel="stylesheet"');
    document.write(' type="text/css"');
    document.write(' href="' + script_filename + '" />');
}
/******* included on every file on the site **********/
include("/includes/jquery.js");
include("/includes/request.js");
//include("/includes/jquery/jquery.truncate.js");
include("/includes/jquery/gJQuery.js");
//include("/includes/jquery/jquery-ui-packed.js");
/*****************************************************/

function clearInput(el){
	if(el.defaultValue==el.value)
		el.value = "";
}
function showhide(id){ 
	if (document.getElementById){ 
		obj = document.getElementById(id); 
		if (obj.style.display == "none"){ 
			obj.style.display = ""; 
		} else { 
			obj.style.display = "none"; 
		} 
	} 
}

function addSearch() {
 if (window.external && ("AddSearchProvider" in window.external)) {
   // Firefox 2 and IE 7, OpenSearch
   window.external.AddSearchProvider("http://dev.ecstuning.com/ECSsearch.xml");
 } else {
   // No search engine support (IE 6, Opera, etc).
   alert("No search engine support");
 }

}


function load() {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(41.010190,-81.762500), 13);
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl()); 
		var baseIcon = new GIcon();
		baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
		baseIcon.iconSize = new GSize(20, 34);
		baseIcon.shadowSize = new GSize(37, 34);
		baseIcon.iconAnchor = new GPoint(9, 34);
		baseIcon.infoWindowAnchor = new GPoint(9, 2);
		baseIcon.infoShadowAnchor = new GPoint(18, 25);
		function createMarker(point, index) {
			var letter = String.fromCharCode("A".charCodeAt(0) + index);
			var letteredIcon = new GIcon(baseIcon);
			letteredIcon.image = "http://www.google.com/mapfiles/marker.png";
			markerOptions = { icon:letteredIcon };
			var marker = new GMarker(point, markerOptions);
			GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowHtml("<span style='margin-left:25px;'><b>ECS Tuning</b> - <b>1-800-924-5172</b></span><br /><br /><img src='/img/building.gif' border='0'style='float:left;margin-top:-5px;margin-right:80px;' /><br /><br /><br style='clear:both;' />");
			});
			return marker;
		}
		var point = new GLatLng(41.010190,-81.762500);
		map.addOverlay(createMarker(point, 1));
	}
};

function preloadImages(){
    var images= []; // if images are needed add them here.
    images.push("/img/addtocartbig-over.gif");
    images.push("/udm-resources/Audi-over.gif");
    images.push("/udm-resources/BMW-over.gif");
    images.push("/udm-resources/Volkswagen-over.gif");
    images.push("/img/addtocartsmall-over.gif");		
    images.push("/img/wait.gif");
    images.push("/img/btnAdd-hover.gif");
    images.push("/img/btnAddtocart-hover.gif");
    images.push("/img/btnCheckout-hover.gif");
    images.push("/img/btnContinue-hover.gif");
    images.push("/img/btnContShopping-hover.gif");
    images.push("/img/btnDelivery-hover.gif");
    images.push("/img/btnEdit-hover.gif");
    images.push("/img/btnLogin-hover.gif");
    images.push("/img/btnNewCustomer-hover.gif");
    images.push("/img/btnNext-hover.gif");
    images.push("/img/btnProceed2Chk-hover.gif");
    images.push("/img/btnProceedShipping-hover.gif");
    images.push("/img/btnSaveCart-hover.gif");
    images.push("/img/btnSaveChanges-hover.gif");
    images.push("/img/btnSearch-hover.gif");
    images.push("/img/btnSubmitOrder-hover.gif");
    images.push("/img/btnUpdateCart-hover.gif");
    images.push("/img/btnRecoverPassword-hover.gif");
    images.push("/img/btnContCheckout-hover.gif");
    images.push("/img/bkg-hover.gif");
    images.push("/img/subCatBkg0.gif");
    if(document.images){    
        for(var i=0; images.length > i; i++){
            var img = new Image();
            img.src = images[i];
        }
    }
}


/****** image roll overs *******/
/*

id of the file needs to be the same as 
the file name without the extension.

*/
function hover(id){
	id.src="/img/" + id.id + "-hover.gif";
}

function out(id){
	id.src = "/img/" + id.id + "-normal.gif";
}

function btnAddOver(img){
	img.src = "/img/btnAddtocart-hover.gif";
}

function btnAddOut(img){
	img.src = "/img/btnAddtocart-normal.gif";
}


function getIndex(el){
    element = document.getElementById(el);
    var ele = element.options[element.selectedIndex].value;
    return ele;
}
function x(){}
var emailLink = function(){
    document.write('<a');
    document.write(' href="mailto:email@somedomain.com?subject=Check out this ECS Tuning product!&amp;body=Take a look at this: '+top.location.href);
    document.write('"><img src="/img/icons/email.gif" width="10" height="10" border="0" alt="" style="margin-right:3px">E-mail this to a friend</a>');
} 

function seekAttn(objID){ // since it's collecting the class names this function needs to have the entire page loaded before it run otherwise it will may not get all the elements.
    if(navigator.appName != "Microsoft Internet Explorer"){
        // and another that doesn't work in ie.. get Class no worky
        var off = document.getElementsByClassName("subHeadOff");
        for(var i=0;off.length>i;i++){
            off[i].style.background = "#666";
            removeClass(off[i],"activeHead");
        }
        var object = document.getElementById(objID+"_tg");
        if(object!=undefined){
            object.style.background = "url(/img/subCatBkg0.gif)";
            addClass(object,"activeHead");
        } else {
            document.cookie = "subHeading="+objID+";";
        }
    }  
}

function stockStatus(productid,selector){
    try{
        closeStockBox('stockBox'+productid);
    } catch(e){ // if there is an alert box on the screen, kill it.
        // alert(e);
    }
    var margin_left = Math.floor(Math.random()*100)-Number(103);
    var callingObj = document.getElementById(productid);
    var stockBox = document.createElement("div");
    (navigator.appName == "Microsoft Internet Explorer") ? stockBox = document.createElement("<div class='modalStockBox' id='stockBox"+productid+"'>") : 1 ;
    stockBox.setAttribute('class','modalStockBox');
    stockBox.setAttribute('id','stockBox'+productid);
    stockBox.style.marginLeft = margin_left+"px";
    stockBox.innerHTML = "";
    var displayTime;
    switch(selector){
        case 0: // special order
            stockBox.innerHTML +="<img src='/img/icons/inventory/0.gif' style='float:left;border:none;' />";
            stockBox.innerHTML +="This product is a special order item. This product will be ordered once your order has been placed. An Estimated Time of Arrival (ETA) based on the expected delivery time from our vendor is shown. Actual time of delivery may vary.";
            displayTime = 30000;
            break;
        case 1: // out of stock
            stockBox.innerHTML +="<img src='/img/icons/inventory/1.gif' style='float:left;border:none;' />";
            stockBox.innerHTML +="This part is currently on order with our supplier or manufacturer. We are unable to predict the exact date that this product will be available for shipment. Orders placed containing back ordered items will ship as soon as possible in their received order as product becomes available. An alternate or equivalent product may be available, please contact the ECS sales staff if you have any questions.";
            displayTime = 30000;
            break;
        case 2: // on order with ETA
            stockBox.innerHTML +="<img src='/img/icons/inventory/2.gif' style='float:left;border:none;' />";
            stockBox.innerHTML +="This product is currently on order with our supplier, an (ETA), estimated time of arrival is listed below.";
            displayTime = 15500;
            break;
        case 3: // ships in 4-7 days
            stockBox.innerHTML +="<img src='/img/icons/inventory/3.gif' style='float:left;border:none;' />";
            stockBox.innerHTML +="This product is sourced from a local supplier and will usually ship within the time frame shown.";
            //stockBox.innerHTML +="This product usually takes four to seven business days to arrive at our facility before shipping.";          
            displayTime = 15500;
            break;
        case 4: // Ships in one day
            stockBox.innerHTML +="<img src='/img/icons/inventory/4.gif' style='float:left;border:none;' />";
            stockBox.innerHTML +="This product will usually ship within two business days.";
            displayTime = 15500;
            break;
        case 5: // in stock
            stockBox.innerHTML +="<img src='/img/icons/inventory/5.gif' style='float:left;border:none;' />";
            //stockBox.innerHTML +="Product is available, in stock and ready to ship. Note that some ECS Big Brake Kits require special assembly which may slightly delay delivery time.";
            stockBox.innerHTML +="Usually ships within one business day.";
            displayTime = 15500;
            break;
        case 'alphaError':
            stockBox.innerHTML +="Please only input Numberic values in the Shipping Override box.";
            displayTime = 15500;
            break
        default:
            stockBox.innerHTML += "This status is not defined.";
            displayTime = 15500;
            break;
    }
    stockBox.innerHTML +="<span class='btnClose' onclick='closeStockBox(\"stockBox"+productid+"\")'>Close</span>"; 
    callingObj.appendChild(stockBox);
    setTimeout(function(){
        closeStockBox('stockBox'+productid);
    },displayTime);
}

function closeStockBox(id){
    var node = document.getElementById(id);
    (node) ? node.parentNode.removeChild(node) : 1 ;
}

/************************************************
borrowed from
http://www.openjs.com/scripts/dom/class_manipulation.php
****************/
function hasClass(ele,cls) {
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
	if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}
function removeClass(ele,cls) {
	if (hasClass(ele,cls)) {
		var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		ele.className=ele.className.replace(reg,' ');
	}
}
/********* end borrowed **********/

function productAdminWindow(url){
    window.open("http://www.ecstuning.com/stage/product_admin/?productID="+url,"ES"+url,'height=700,width=1000,scrollbars=yes');
} 

function openWindow(url){
    window.open(url,'height=500,width=700,scrollbars=no');
}

// just incase we need this for later.. will delete soon.. 
function changeImages() { // working on replacing these two functions..
	if (document.images) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}
function xd() {  
	if (document.images) {
		for (var i=0; i<xd.arguments.length; i+=2) {
			document[xd.arguments[i]].src = xd.arguments[i+1];
		}
	}
}




