//search form 
var fulltext = false;

function submitSearch(sform, s) {
    var obj = sform["keyword"];
    if (obj.value.replace(/\ /ig, "") == "") {
        if (s != "") alert(s);
        obj.focus();
        return false;
    }
    sform["q"].value = sform["keyword"].value;
    stype(sform);
    return true;
}
function stype(sform) {
    var fulltext = (sform["searchtype"].options[2].selected == true); //fulltext

    sform["q"].disabled =
    sform["site"].disabled =
    sform["client"].disabled =
    sform["proxystylesheet"].disabled =
    sform["output"].disabled =
    !fulltext;

    sform["keyword"].disabled = fulltext;

    sform.action = (fulltext) ? actions[1] : actions[0];
}

function setSearchValue() {
    var name, value;
    var obj;
    var pos = document.URL.indexOf("?");
    var len = document.URL.length;
    var quarys, q;

    if (pos > -1) {
        quarys = document.URL.substring(pos + 1, len).split("&");
        for (var i = 0; i < quarys.length; i++) {
            q = quarys[i].split("=");
            if (q.length > 1) {
                obj = document.getElementById(q[0]);
                if (obj)
                    if (obj.type == "select-one")
                    for (var j = 0; j < obj.options.length; j++) obj.options[j].selected = (obj.options[j].value == q[1]);
            }
        }
    }
}


//product detail tabs
function sel(obj){
	var o=findObj(obj);
	var s=findObj("tab"+obj);
	var h,b;
	if(o!=null)
		o.style.display="block";
	if(s!=null)
		s.className="aFocus";
	for(var oTab in infoTabs){
		h=findObj(infoTabs[oTab]);
		if(h!=null && h!=o)h.style.display="none";

		b = findObj("tab" + infoTabs[oTab]);
		if(b!=null && b!=s)b.className="";
	}
}

function findObj(id) {    
	if(document.getElementById)return document.getElementById(id);
	if(document.all)return document.all[id];
	if(document.layers)return document.layers[id];
	return null
}

//////////////////////////////////
//		FOR POPUP WINDOW		//
//////////////////////////////////

function pop(w, url) {
    //change to thick box
    $.fn.colorbox({ iframe: true, width: "530px", height: "530px", href: url, title: $(".main .navigation span.focus").text(), scrolling: false });
}
function pop2(w,url)
{
	var popwin=open(url,w,"toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,top=100,left=100,width=320,height=240");
	popwin.focus();
}

//
function contactEvent(originalEvent,newEvent)
{
try{
if(originalEvent)originalEvent();
if(newEvent)newEvent();
}catch(ex){};
}

window.onerror=function(){return true;}

//Confirm Exit Site
function ces(url)
{
	//var msg="You are now leaving the W.A.C. Lighting website and entering a third party site. W.A.C. Lighting is not responsible for the content presented by a third party website, including advertising claims, special offers, illustrations, names or endorsements. Thank you for visiting waclighting.com. Click \"OK\" to continue.";
	//var cf=confirm(msg);
    //if (!cf) return;
    if (url.indexOf("http://maps.google.com/") > -1) {
        $.fn.colorbox({ iframe: true, width: "90%", height: "90%", href: url });
    } else {
        var e = open(url);
    }
}

//where to buy

function fObj(o) { return findObj(o); }

function chang() {
    var lb0 = fObj("lb0");
    var lb1 = fObj("lb1");
    var lbs = fObj("lbs");
    var lbz = fObj("lbz");
    var flt = fObj("filter");
    var lt3 = fObj("lt3");

    var map = fObj("map");

    if (!lt3.checked) {
        flt.style.display = "";
        if (lb0.checked && !lb1.checked) {
            lbs.style.display = "";
            map.style.display = "";
            lbz.style.display = "none";
        }
        if (!lb0.checked && lb1.checked) {
            lbs.style.display = "none";
            map.style.display = "none";
            lbz.style.display = "";
        }
    } else {
        flt.style.display = "none";
        map.style.display = "none";
        lbs.style.display = "none";
        lbz.style.display = "none";
    }
}

function chkform(f) {
    chang();
    var lb0 = fObj("lb0");
    var lb1 = fObj("lb1");
    var lbs = fObj("lbs");
    var lbz = fObj("lbz");
    var lt3 = fObj("lt3");

    if (!lt3.checked && lb0.checked && (lbs.value.replace(/ /gi, "").length == 0)) {
        alert("Please select a state.");
        lbs.focus();
        return false;
    }
    if (!lt3.checked && lb1.checked && (lbz.value.replace(/ /gi, "").length == 0)) {
        alert("Please entry a zipcode.");
        lbz.select();
        lbz.focus();
        return false;
    }
}

function initform() {
    chang();
    //var lt="<%=lt%>",lb="<%=lb%>",ls="<%=ls%>", lz="<%=lz%>";
    //defined in locator page
    if (lb == "1" || ls == "") return;

    var lbs = fObj("lbs");
    var l = lbs.length;
    for (var i = 0; i < l; i++) {
        if (lbs.options[i].value == ls) {
            lbs.selectedIndex = i;
            return;
        }
    }
}
//init function
$(document).ready(function() {
    var u = document.URL;
    //report system pop window
    $("a.box[href*='reportsystem.waclighting']").colorbox({ iframe: true, width: "720px", height: "420px" });
    //led calculator
    $("a.box[href*='calculator']").colorbox({ iframe: true, width: "980px", height: "640px" });
    //search form
    setSearchValue();
    //where to buy
    if (u.indexOf("/locator/") > -1) {
        initform();
        //map click
        $("area").click(function() {
            var os = $("#lbs option[selected]").val(); //original value
            var s = $(this).attr("href").replace("#", "").replace("+", " "); //click value
            var o = $("#lbs option[value='" + s + "']");
            if (os != s && o != null) {
                o.attr("selected", "selected");
                $("form#locator").submit();
            }
            //$("#lbs option[value='" + s + "']").attr("selected", "selected");
            return false;
        });
    }
    //e-catalog
    if (u.indexOf("/e-catalog/") > -1) {
        //$("a.popbox").colorbox({ iframe: true, scrolling: false, width: "95%", height: "95%", href: $(this).href });
		$("a.popbox, a.dl-pdf").attr("target", "_blank");
    }

    //videos
    if (u.indexOf("/videos/") > -1) {
        $("#videos a.video").colorbox({ iframe: true, scrolling: true, innerWidth: true, innerHeight: true });

        //add 30px for border
        $("#videos a#v01").colorbox({ width: "680px", height: "463px" }); //650x433 Dallas Showroom
        $("#videos a#v02, #videos a#v05").colorbox({ width: "830px", height: "505px" }); //800x475 Monorail, led presentation
        $("#videos a#v03, #videos a#v04").colorbox({ width: "414px", height: "318px" }); //384x288 New Products, WAC Manufacture
        $("#videos a#v06, #videos a#v07").colorbox({ width: "350px", height: "270px" }); //320x240 Shelley Wang, ALA

    }
    //2010 dallas
    if (u.indexOf("/showroom/") > -1) {
        $("area").click(function() {
            $.fn.colorbox({ href: this.href, title:this.title,photo:true});
            return false;
        });
    }
	$("#toolbar a#howtoBtn").text("Instrunction Sheet");
});
