function initPage()
{
    var nav = document.getElementById("dropdown");
    if (nav)
    {
        var nodes = nav.getElementsByTagName("li");
        for (var i = 0; i < nodes.length; i++)
        {        
                nodes[i].onmouseover = function () 
                {
                    this.className += " hover";
                }
                nodes[i].onmouseout = function ()
                {
                    this.className = this.className.replace(" hover", "");
                }
        }
    }
}

if (window.attachEvent)
    window.attachEvent("onload", initPage);

    
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function flvFSL1(){//v2.3
// Copyright 2002-2004, Marja Ribbers-de Vroed, FlevOOware (www.flevooware.nl/dreamweaver/)
var v1=arguments,v2=v1[0],v3=MM_findObj(v2),v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,v17,v18,v19,v20=window,v21=navigator;if (v3){v4=parseInt(v1[1]);v5=parseInt(v1[2]);v6=parseInt(v1[3]);v7=(v1.length>4)?parseInt(v1[4]):0;v8=(v1.length>5)?parseInt(v1[5]):0;v9=10;v10=document.layers?v3:v3.style;if (v3.SL1!=null){clearTimeout(v3.SL1);}v11=isNaN(parseInt(v10.left))?v3.offsetLeft:parseInt(v10.left);v12=isNaN(parseInt(v10.top))?v3.offsetTop:parseInt(v10.top);if (v8!=0){if (v8==1){v4=v11-v4;v5=v12;}else if (v8==2){v4=v11+v4;v5=v12;}else if (v8==3){v5=v12-v5;v4=v11;}else {v5=v12+v5;v4=v11;}}v13=v4;v14=v5;if ((v11!=v4)||(v12!=v5)){if (v7>0){v9=v6;v15=v7;v16=v7,v17=Math.abs(v11-v4),v18=Math.abs(v12-v5);if (v17<v18){v16=(v17!=0)?((v18/v17)*v7):v7;}else {v15=(v18!=0)?((v17/v18)*v7):v7;}if (v15>=v17){v15=Math.min(Math.ceil(v15),v7);}if (v16>=v18){v16=Math.min(Math.ceil(v16),v7);}if ((v11<v4)&&(v11+v15<v4)){v4=v11+v15;}if ((v11>v4)&&(v11-v15>v4)){v4=v11-v15;}if ((v12<v5)&&(v12+v16<v5)){v5=v12+v16;}if ((v12>v5)&&(v12-v16>v5)){v5=v12-v16;}}else {v17=((v4-v11)/v6);v18=((v5-v12)/v6);v17=(v17>0)?Math.ceil(v17):Math.floor(v17);v4=v11+v17;v18=(v18>0)?Math.ceil(v18):Math.floor(v18);v5=v12+v18;}v19=(document.layers||window.opera)?"":"px";if (v17!=0){v10.left=v4+v19;}if (v18!=0){v10.top=v5+v19;}var v22="flvFSL1('"+v2+"',"+v13+","+v14+","+v6+","+v7+",0)";v3.SL1=setTimeout(v22,v9);}else {if (v20.onSlideEnd){onSlideEnd(v2);}}}}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function shift_promo(slider, direction)
{
    // get the current position
    if (slider == "slider1")
    {
        var cur_pos = parseFloat(document.stopform.cur_pos1.value);
        var last_pos = parseFloat(document.stopform.last_pos1.value);
        if (direction == "up")
        {    

            if (cur_pos != 0)
            {
                flvFSL1('slider1',0,110,10,0,4)
                cur_pos -= 110;
                document.stopform.cur_pos1.value = cur_pos;
            }
        }
        else
        {
            if (cur_pos != last_pos)
            {
                flvFSL1('slider1',0,110,10,0,3)
                cur_pos += 110;
                document.stopform.cur_pos1.value = cur_pos;
            }
        }
    }
    else
    {
        var cur_pos = parseFloat(document.stopform.cur_pos2.value);
        var last_pos = parseFloat(document.stopform.last_pos2.value);
        if (direction == "up")
        {
            if (cur_pos != 0)
            {
                flvFSL1('slider2',0,110,10,0,4)
                cur_pos -= 110;
                document.stopform.cur_pos2.value = cur_pos;
            }
        }
        else
        {
            if (cur_pos != last_pos)
            {
                flvFSL1('slider2',0,110,10,0,3)
                cur_pos += 110;
                document.stopform.cur_pos2.value = cur_pos;            }
        }
    }

}
function stoprotate()
{
    document.stopform.stopvalue.value = "1";
}

function rotate_mini_promos1(promo_num, last_promo)
{
    var stopvalue = document.stopform.stopvalue.value;
    if (stopvalue == "0")
    {
        var div_position;
        if (promo_num != 0)
        {
            //alert (promo_num+" - "+last_promo);
            if (promo_num == last_promo)
            {
                flvFSL1('slider1',0,0,10,0,0);
                promo_num = 0;
                document.stopform.cur_pos1.value = "0";
            }
            else
            {
                div_position = promo_num * 110;
                flvFSL1('slider1',0,-div_position,10,0,0);
                document.stopform.cur_pos1.value = div_position;
            }
        }
        var the_num = parseInt(promo_num);
        var next_num = the_num + 1;
        setTimeout("rotate_mini_promos1('"+next_num+"','"+last_promo+"')",6000);
    }
}

function rotate_mini_promos2(promo_num, last_promo)
{
    var stopvalue = document.stopform.stopvalue.value;
    if (stopvalue == "0")
    {
        var div_position;
        if (promo_num != 0)
        {
            if (promo_num == last_promo)
            {
                flvFSL1('slider2',0,0,10,0,0);
                promo_num = 0;
                document.stopform.cur_pos2.value = "0";
            }
            else
            {
                div_position = promo_num * 110;
                flvFSL1('slider2',0,-div_position,10,0,0);
                document.stopform.cur_pos2.value = div_position;
            }
        }
        var the_num = parseInt(promo_num);
        var next_num = the_num + 1;
        setTimeout("rotate_mini_promos2('"+next_num+"','"+last_promo+"')",6000);
    }
}
function check_promo(cookie)
{
    
    if(document.forms[1].promo_code.value != "")
        execAjaxPromo(0,"check_promo_code.php?cookie=" + cookie + "&promo_code=" + document.forms[1].promo_code.value,"sub_total_cell");
}


function viewCategories(promo_code)
{
    window.open("view_categories.php?promo_code=" + promo_code,"EducationStation","width=360,height=500,scrollbars=yes,top=200,left=200"); 
}

function addtocart()
{
    document.cart.add_to_cart.value = "yes";
    document.cart.submit();
}

function showCart()
{
    document.getElementById('cart-details').style.display = "block";

}
function hideCart()
{
   
    document.getElementById('cart-details').style.display = "none";
}
function update_quantity(id, field)
{
    document.form1.order_id.value = id;
    document.form1.quantity.value = field.value;
    document.form1.form_action.value = "update_quantity";
    document.form1.submit();
}

function remove(id)
{
    document.form1.order_id.value = id;
    document.form1.form_action.value = "remove";
    document.form1.submit();
}




function calculate_totals()
{
    var subtotal = parseFloat(document.form1.ordersubtotal.value);
    var country = document.form1.country.options[document.form1.country.selectedIndex].value;
    var shippingdiv = document.getElementById('shippingdiv');
    var gstdiv = document.getElementById('gstdiv');
    var ordertotaldiv = document.getElementById('ordertotaldiv');
    var shipcountrydiv = document.getElementById('shipcountrydiv');
    var shipcountryCAdiv = document.getElementById('shipcountryCAdiv');
    var shipcountryUSdiv = document.getElementById('shipcountryUSdiv');
    var shipcountryINTdiv = document.getElementById('shipcountryINTdiv');
    var shipping;
    var gst;
    var total;
    
    
    if (country == "Canada")
    {
        shipping = parseFloat(subtotal) * 0.1;
        if (shipping < 9) shipping = 9;
        gst = ((parseFloat(subtotal) + parseFloat(shipping)) * .05);
        total = parseFloat(subtotal) + parseFloat(shipping) + parseFloat(gst);
        
        // Round everything off to two decimal places
        shipping = shipping.toFixed(2);
        gst = gst.toFixed(2);
        total = total.toFixed(2);

        document.form1.shipping.value = shipping;
        document.form1.gst.value = gst;
        document.form1.order_total.value = total;
        document.form1.shipcountryINT.value = "Canada";
        
        shippingdiv.innerHTML= "$"+shipping;
        gstdiv.innerHTML= "$"+gst;
        ordertotaldiv.innerHTML= "$"+total;
        shipcountrydiv.style.display = "none";
        shipcountryCAdiv.style.display = "inline";
        shipcountryUSdiv.style.display = "none";
        shipcountryINTdiv.style.display = "none";
    }
    else if (country == "United States")
    {
        shipping = parseFloat(subtotal) * 0.1;
        if (shipping < 11.5) shipping = 11.5;
        gst = 0;
        total = parseFloat(subtotal) + parseFloat(shipping);
        
        // Round everything off to two decimal places
        shipping = shipping.toFixed(2);
        gst = gst.toFixed(2);
        total = total.toFixed(2);

        document.form1.shipping.value = shipping;
        document.form1.gst.value = gst;
        document.form1.order_total.value = total;
        document.form1.shipcountryINT.value = "United States";

        shippingdiv.innerHTML= "$"+shipping;
        gstdiv.innerHTML= "$"+gst;
        ordertotaldiv.innerHTML= "$"+total;
        shipcountrydiv.style.display = "none";
        shipcountryCAdiv.style.display = "none";
        shipcountryUSdiv.style.display = "inline";
        shipcountryINTdiv.style.display = "none";
    }
    else if (country == "International")
    {
        document.form1.shipping.value = "we will contact you";
        document.form1.gst.value = 0;
        document.form1.order_total.value = "we will contact you";
        document.form1.shipcountryINT.value = "";

        shippingdiv.innerHTML= "<font size=1>we will contact you</font>";
        gstdiv.innerHTML= "$0.00";
        ordertotaldiv.innerHTML= "<font size=1>we will contact you</font>";
        shipcountrydiv.style.display = "none";
        shipcountryCAdiv.style.display = "none";
        shipcountryUSdiv.style.display = "none";
        shipcountryINTdiv.style.display = "inline";
    }
}

function submit_order()
{
    var problems = ""; 
    var selected_heard_about = document.form1.heard_about.options[document.form1.heard_about.selectedIndex].value;
    if(document.form1.country.selectedIndex != undefined)
        var selectedcountry = document.form1.country.options[document.form1.country.selectedIndex].value;
    else
        var selectedcountry = document.form1.country.value;

        
    if (selectedcountry == " ")
    {
        problems = problems+"\n- You must select your shipping country (in the totals box at the top)";
    }
    
    if (document.form1.first_name.value == "")
    {
        problems = problems+"\n- Please enter your First Name";
    }
    if (document.form1.last_name.value == "")
    {
        problems = problems+"\n- Please enter your Last Name";
    }
    if (document.form1.email.value == "")
    {
        problems = problems+"\n- Please enter your email address";
    }
    if (!(document.form1.email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.biz)|(\.coop)|(\.info)|(\.name)|(\.pro)|(\.int)|(\.aero)|(\..{2,2}))$)\b/gi)))
    {
        problems = problems+"\n- Your Email Address does not appear to be valid";
    }
    if (document.form1.phone.value == "")
    {
        problems = problems+"\n- Please enter your phone number";
    }
    if (document.form1.address1.value == "")
    {
        problems = problems+"\n- Please enter your billing address";
    }
    if (document.form1.city.value == "")
    {
        problems = problems+"\n- Please enter your billing city";
    }
    if (document.form1.province.value == "")
    {
        problems = problems+"\n- Please enter your billing province/state";
    }
    if (document.form1.zip.value == "")
    {
        problems = problems+"\n- Please enter your billing postal/zip code";
    }
    if (document.form1.billcountry.value == "")
    {
        problems = problems+"\n- Please enter your billing country";
    }
 
    if(document.form1.samebilling != undefined)   //this group of inputs wont be loaded when dealing with GC, so this is to avoid JS Errors...
            if (document.form1.samebilling.checked)
            {
                // do nothing
            }
            else
            {
                // check the shipping fields
                if (document.form1.shipaddress1.value == "")
                {
                    problems = problems+"\n- Please enter your shipping address";
                }
                if (document.form1.shipcity.value == "")
                {
                    problems = problems+"\n- Please enter your shipping city";
                }
                if (document.form1.shipprovince.value == "")
                {
                    problems = problems+"\n- Please enter your shipping province/state";
                }
                if (document.form1.shipzip.value == "")
                {
                    problems = problems+"\n- Please enter your shipping postal/zip code";
                }
                if (selectedcountry == "International")
                {
                    if (document.form1.shipcountryINT.value == "")
                    {
                        problems = problems+"\n- Please enter your shipping country";
                    }
                }
            }
    
    var radio_choice = false;
    for (counter = 0; counter < document.form1.paymentmethod.length; counter++)
    {
        if (document.form1.paymentmethod[counter].checked) radio_choice = true;
    }
    if (!radio_choice)
    {
        problems = problems+"\n- Please select Visa, Mastercard, or P.O. Number";
    }
    
    // paymentmethod[2] is the P.O. number
    if (document.form1.paymentmethod[2].checked)
    {
        if (document.form1.ponumber.value == "")
        {
            problems = problems+"\n- Please enter the P.O. Number";
        }
    }
    else
    {
        if (document.form1.ccnumber.value == "")
        {
            problems = problems+"\n- Please enter your credit card number";
        }
        if (document.form1.ccexp.value == "")
        {
            problems = problems+"\n- Please enter your credit card expiry date";
        }
    }

    if (selected_heard_about == " ")
    {
        problems = problems+"\n- Please select an option from the How Did You Hear About Us dropdown";
    }
    
    
    if (problems != "")
    {
        alert ("The following problems were encountered:\n"+problems+"\n\nPlease enter these fields and try again. Thanks!");
    }
    else if(document.form1.samebilling != undefined)
            {
                // Lastly, check for PO Boxes
                if (document.form1.samebilling.checked)
                {

                }
                document.form1.submit();
            }
          else
          {
           document.form1.submit();
          }
}
function browsercheck(){ //Browsercheck (needed)
    this.ver=navigator.appVersion
    this.agent=navigator.userAgent
    this.dom=document.getElementById?1:0
    this.opera5=this.agent.indexOf("Opera 5")>-1
    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
    this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
    this.ieX=(this.ver.indexOf("MSIE")>-1 && this.dom && !this.opera5)?1:0;
    this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
    this.ie=this.ie4||this.ie5||this.ie6||this.ieX;
    this.mac=this.agent.indexOf("Mac")>-1
    this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
    this.ns4=(document.layers && !this.dom)?1:0;
    this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
    return this
}
bw = browsercheck();

function hide_billing_box(hide){
var display_value = "";
    if(bw.ie != 1)
       display_value = "table-row";
    else
       display_value = "block";
       
    if(hide == true)
    {
        document.getElementById("same_billing_box_1").style.display = "none";
        document.getElementById("same_billing_box_2").style.display = "none";
        document.getElementById("same_billing_box_3").style.display = "none";
        document.getElementById("same_billing_box_4").style.display = "none";
        document.getElementById("same_billing_box_5").style.display = "none";
        document.getElementById("same_billing_box_6").style.display = "none";
        document.getElementById("same_billing_box_7").style.display = "none";
    }
    else
    {
        document.getElementById("same_billing_box_1").style.display = display_value;
        document.getElementById("same_billing_box_2").style.display = display_value;
        document.getElementById("same_billing_box_3").style.display = display_value;
        document.getElementById("same_billing_box_4").style.display = display_value;
        document.getElementById("same_billing_box_5").style.display = display_value;
        document.getElementById("same_billing_box_6").style.display = display_value;
        document.getElementById("same_billing_box_7").style.display = display_value;
    }

}
