var chargeRadio = "";
function getCookie(name) {
     if(top.localCookieOK){
	var prefix = name + "="
	var cookieStartIndex = document.cookie.indexOf(prefix)
	if (cookieStartIndex == -1)
		return null
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
	if (cookieEndIndex == -1)
		cookieEndIndex = document.cookie.length
	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
     }else{
     return top.cookiePr
     }
}

function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "")
	if ((name + "=" + escape(value)).length > 3600){
          alert("Be careful! You're running out of space on your order form. \n\nYou should submit the form, or delete some items, or contact us by email or telephone about your order.")
          }
      document.cookie = curCookie
}

function fixDate(date) {
	var base = new Date(0)
	var skew = base.getTime()
	if (skew > 0)
		date.setTime(date.getTime() - skew)
}

function extractItems(str, sep) {
     var a = new Array()
     if (str.length != 0){
     var i = 0
     var j = 0
     var n = 0
     while (n>=0){
          n = str.indexOf(sep, j)
          if (isNaN(parseInt(n))){
              n = -1
              }
          if(n > j){
               var s = str.substring(j, n)
               a[i] = s
               ++i
               j = n + sep.length
               }
          }
     }
     return a
}

function reload(){
     document.location.reload()
}

function saveOrderToCookie() {
     var s_temp = ""
     for (var k=0; k<selected_items.length;++k) {
          var c_temp = ""
          if(selected_items[k][4].length > 1){
              for (var j=0;j<selected_items[k][4].length;++j){
                  c_temp = c_temp + selected_items[k][4][j] + "^"
                  }
              var v_temp = eval(c_ele[k])
              selected_items[k][6] = -1
              for (var l=1; l<v_temp.length; ++l) {
                  if(v_temp.options[l].selected){
                       selected_items[k][6] = l - 1   
                       }
                  }
              }else{
              //c_temp = eval(c_ele[k]).value + "^"
              c_temp = selected_items[k][4][0] + "^"
              selected_items[k][6] = 0
          }
          s_temp = s_temp + escape(selected_items[k][0] + "*" + selected_items[k][1] + "*" + selected_items[k][2] + "*" + selected_items[k][3] + "*" + c_temp + "*" + selected_items[k][5] + "*" + selected_items[k][6] + "* **")
     }
     if(top.localCookieOK){
         var now = new Date()
         fixDate(now)
         now.setTime(now.getTime() + 7 * 24 * 60 * 60 * 1000)
         setCookie("ginsorder", s_temp, now)
     }else{
         top.cookiePr = s_temp
     }
     return false
}

function saveTandNtoVars(){
     top.h_order_t = document.forms[0].total.value
     top.h_order_n = document.forms[0].yourName.value
     //if(navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) >=4){
     //     s = "http://www.ginstrim.com/card.html#" + document.forms[0].total.value + " " + document.forms[0].yourName.value
     //     document.forms[0].if_ok.value = s
     //}
}

function fix_amount(number) {
        var Res = "" + Math.round(number * Math.pow(10, 2));
        var Dec = Res.length - 2;
        var r = (Res.substring(0, Dec) + "." + Res.substring(Dec, Res.length));
        if(r == 0)return "0"
        return r
}

function init_totals(){
    item_subtotal = 0.00
    for(i = 0; i < selected_items.length; ++i){
         var t_temp = compute_item_totals(selected_items[i][2], selected_items[i][5])
         ft_temp = fix_amount(t_temp)
         item_subtotal += parseFloat(ft_temp)
    }
    item_subtotal = fix_amount(item_subtotal)
     if (item_subtotal > 0){
         item_shipping = 7.00
    }else{
         item_shipping = 0.00
    }
    order_total = parseFloat(item_subtotal) + parseFloat(fix_amount(item_shipping))
}

function update_totals(){
    valsAreValid = true
    item_subtotal = 0.00
    for(i = 0; i < selected_items.length; ++i){
         selected_items[i][5] = check_q_int(i)
         if(isNaN(selected_items[i][5])){
             valsAreValid = false
         }
         var t_temp = compute_item_totals(selected_items[i][2], selected_items[i][5])
         ft_temp = fix_amount(t_temp)
         eval(t_ele[i]).value = ft_temp
         item_subtotal += parseFloat(ft_temp)
    }
    item_subtotal = fix_amount(item_subtotal)
     if (item_subtotal > 0){
         item_shipping = 7.00
    }else{
         item_shipping = 0.00
    }
    order_total = parseFloat(item_subtotal) + parseFloat(fix_amount(item_shipping))
    document.forms[0].shipping.value = fix_amount(item_shipping)
    document.forms[0].subtotal.value = fix_amount(item_subtotal)
    document.forms[0].total.value = fix_amount(order_total)
    saveOrderToCookie()
    return valsAreValid
}

function compute_item_totals(p, c) {
     return (parseInt(p * c *100))/100
}

function check_q_int(q_index){
     //if possible, return an integer, else return a non-numeric and show alert
     var i_temp = parseInt(eval(q_ele[q_index]).value)
     if (isNaN(i_temp)){
          alert("You entered a quantity that is not a number.\nEnter a number and recalculate.")
     }else{
          eval(q_ele[q_index]).value = i_temp
     }
     return i_temp
}

function check_colors(){
    for(i = 0; i < selected_items.length; ++i){
        if((selected_items[i][5] != 0) && (selected_items[i][6] == -1)){
             alert("Select a color for Style # " + selected_items[i][0])
        }
    }
}

function simpleClearItems(){
     var s_temp = ""
          if(top.localCookieOK){
              var now = new Date()
              fixDate(now)
              now.setTime(now.getTime() + 7 * 24 * 60 * 60 * 1000)
              setCookie("ginsorder", s_temp, now)
          }else{
              top.cookiePr = s_temp
          }
}

function clearItems(){
     var c_temp = confirm("Are you sure that you want to remove all items from your shopping cart?")
     if(c_temp){
           simpleClearItems()
     }
     reload()
     return false
}

function deleteItem(item_num) {
     var c_temp = confirm("Are you sure that you want to delete item " + selected_items[item_num][0] + " from your shopping cart?")
     if(c_temp){
     var l_temp=selected_items.length
     var a_temp = new Array(l_temp - 1)
     var m = 0
     for (var i=0; i<l_temp; ++i){
          if (i!=item_num){
              a_temp[m]= selected_items[i]
              m = ++m
              }
          }
     selected_items = a_temp
     saveOrderToCookie()
     reload()
     }
     return false
}

function order_help(){
    var fr = parent.content.location.href
    var lastSf = fr.lastIndexOf("/")
    parent.content.location.href = fr.substring(0, lastSf) + "/how.html"
}

 function checkShip()
  {
      if(isName(document.forms[0].yourName,0,"Your Name")){
         if(isNameNum(document.forms[0].shipAdd,0,"Address")){
            if(isName(document.forms[0].shipCity,0,"City")){
               if(isName(document.forms[0].shipState,0,"State")){
                  if(isNameNum(document.forms[0].shipPost,0,"ZIP Code")){
                     return true
                  }
               }
            }
         }
      }
      return false
  }


 function testAndSubmit()
  {
     if(update_totals()){
        if(checkShip()){
           saveTandNtoVars()
           simpleClearItems()
           document.forms[0].submit()
        }
     }
  }

 function isName(p1, p2, str1)
  {
     //p1 is the element
     //p2 is the number of letters in the element; p2<=0 means any length > 0 is okay
    var str = p1.value;
    // Return false if name field is blank.
    if (str == "")
       {
       alert("\n"+str1+" is blank.")
       p1.focus();
       return false;
       }
    if (p2 > 0)
          {
             if (str.length != p2)
                 {
                alert("\nThe "+str1+" requires "+p2+" letters.")
                 p1.select();
                 p1.focus();
                 return false;
                 }
           }
    // Return false if characters are not a-z, A-Z, a period, or a space.
    for (var i = 0; i < str.length; i++) 
       {
       var ch = str.substring(i, i + 1);
       if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != '.' && ch != ' ') 
          {
          alert("\n"+str1+" only accepts letters & spaces.");
          p1.select();
          p1.focus();
          return false;
          }
       }
    return true;
  }

 function isNameNum(p1, p2, str1)
  {
     //p1 is the element
     //p2 is the number of letters in the element; p2<=0 means any length > 0 is okay
    var str = p1.value;
    // Return false if name field is blank.
    if (str == "")
       {
       alert("\n"+str1+" is blank.")
       p1.focus();
       return false;
       }
    if (p2 > 0)
          {
             if (str1.length != p2)
                 {
                alert("\n"+str1+" requires "+p2+" letters.")
                 p1.select();
                 p1.focus();
                 return false;
                 }
           }
    for (var i = 0; i < str.length; i++) 
       {
       var ch = str.substring(i, i + 1);
       if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch) && ch != '.' && ch != ' ') 
          {
          alert("\n"+str1+" only accepts letters, digits & spaces.");
          p1.select();
          p1.focus();
          return false;
          }
       }
    return true;
  }
 function isNum(p1, p2, str1)
  {
     //p1 is the element
     //p2 is the number of digits in the number; p2 <= 0 means any length > 0 is okay
    var str = p1.value;
    // Return false if number field is blank.
    if (str == "")
          {
          alert("\n"+str1+" is blank.");
          p1.focus();
          return false;
          }
    if (p2 > 0)
          {
             if (str.length != p2)
                 {
                alert("\n"+str1+" requires "+p2+" digits.")
                 p1.select();
                 p1.focus();
                 return false;
                 }
           }
    // Return false if characters are not '0-9' or '.' . 
    for (var i = 0; i < str.length; i++) 
       {
       var ch = str.substring(i, i + 1);
       if (ch < "0" || "9" < ch) 
          {
          alert("\n"+str1+" accepts only digits 0 through 9.");
          p1.select();
          p1.focus();
          return false;
          }
       }
    return true;
  }

 function isNumS(p1, p2, p3, str1)
  {
     //the element p1 is checked for ten digits, spaces and -'s are okay
     //p2 = 0 means that empty field is okay
     //p3 is the number of digits required (for a non-empty field)
     //p3 = 0 mean any number of digits is okay (but they must be legal characters)
     //in case an error is detected, str1 is used in the alert
    var str = p1.value;
    var j = 0;
    // Number field is blank.
    if (str == "")
          {
           if (p2 == 0)
                {return true}
           else
                {alert("\n"+str1+" is blank.");
                p1.focus();
                return false;}
          }
    //check for legal characters
    for (var i = 0; i < str.length; i++) 
         {
         var ch = str.substring(i, i + 1);
         if ((ch < "0" || "9" < ch) && (ch != '-') && (ch != ' ') && ch != '.')
              {
              alert("\n"+str1+" accepts only digits 0 through 9, -'s, .'s, and blanks.");
              p1.select();
              p1.focus();
              return false;
              }
        else
             {if (!(ch < "0" || "9" < ch))
                 {j = j + 1}
             }
         }
        if ( p3 == 0  ||  j == p3)
               {return true}
        else
               {
                alert("\n"+str1+" requires" + p3 +"digits.")
                p1.select();
                p1.focus();
                return false;
                }
     }

  function isSelSel(sel, str1)
     {
          if(sel.selected)
              {
              alert("\nYou need to select a"+str1+".")
              return false
              }
              else
             {
             return true
             }
     }

 function isButton(p1, str1)
     {
      if (p1 == "")
           alert("\nYou need to select a "+str1+".")
           else {return true;}
      }

function displayPage(){
//if((navigator.appName == "Microsoft Internet Explorer" && //parseInt(navigator.appVersion) <=3))window.open("mieold.html","",menubar="no")
var c_value = unescape(getCookie("ginsorder"))
var i_array = extractItems(c_value, "**")
selected_items = new Array(i_array.length)
for(i=0; i<i_array.length; ++i) {
     selected_items[i] = extractItems(i_array[i], "*")
     selected_items[i][4] = extractItems(selected_items[i][4], "^")
     }

thumb_head = "<IMAGE SRC=\"images_small/"
thumb_tail = ".jpg\" HEIGHT=60 WIDTH=100>"
c_ele = new Array(selected_items.length)
q_ele = new Array(selected_items.length)
t_ele = new Array(selected_items.length)
init_totals()
document.write("<TR>")
var item_count = selected_items.length
if(item_count > 0)document.write("<TD COLSPAN=7>For each item, choose a <B>color</B> and specify <B>quantity</B>.<BR>Click <B>DELETE</B> to remove an item from the order form.</TD>")
document.write("</TR>")
document.write("<TR>")
document.write("<TH VALIGN=TOP>Item</TH>")
document.write("<TH VALIGN=TOP ALIGN=LEFT>Style #</TH>")
document.write("<TH VALIGN=TOP ALIGN=LEFT>Description</TH>")
document.write("<TH VALIGN=TOP ALIGN=LEFT>Price/Quantity<BR>Color</TH>")
document.write("<TH VALIGN=TOP ALIGN=LEFT>Total</TH>")
document.write("</TR>")
document.write("<TR><TD><IMAGE SRC=\"imagesm/clear.gif\" HEIGHT=2 WIDTH=100></TD>")
document.write("<TD><IMAGE SRC=\"imagesm/clear.gif\" HEIGHT=2 WIDTH=50></TD>")
document.write("<TD><IMAGE SRC=\"imagesm/clear.gif\" HEIGHT=2 WIDTH=140></TD>")
document.write("<TD><IMAGE SRC=\"imagesm/clear.gif\" HEIGHT=2 WIDTH=60></TD>")
document.write("<TD><IMAGE SRC=\"imagesm/clear.gif\" HEIGHT=2 WIDTH=45></TD>")
document.write("<TD><IMAGE SRC=\"imagesm/clear.gif\" HEIGHT=2 WIDTH=45></TD>")
document.write("</TR>")
//table with one item per row
if(item_count == 0)
     {document.write("<TR><TD COLSPAN=7 ALIGN=LEFT>There are currently no items on your shopping cart.</TD></TR>")
     document.write("<TR><TD COLSPAN=7 ALIGN=LEFT>You can add items from the catalog by clicking where it says <B>ADD TO SHOPPING CART</B>.</B></TD></TR>")
     document.write("<TR><TD COLSPAN=7 ALIGN=LEFT></TD></TR>")
     }
     else{
     for(i = 0; i < item_count; ++i){
     document.write("<TR><TD VALIGN=TOP>")
     document.write(thumb_head + selected_items[i][0] + thumb_tail)
     document.write("</TD><TD VALIGN=TOP ALIGN=LEFT>")
     document.write(selected_items[i][0])
     document.write("<INPUT TYPE=\"HIDDEN\" NAME=\"item\"" + i + " VALUE=" + selected_items[i][0] + ">")
     document.write("<BR><BR><INPUT TYPE=\"checkbox\" ONCLICK=\"deleteItem(" + i + ")\"><FONT SIZE=1>DELETE<FONT SIZE=3>")
     document.write("</TD><TD VALIGN=TOP ALIGN=LEFT>")
     document.write(selected_items[i][1])
     document.write("</TD><TD VALIGN=TOP ALIGN=LEFT>")
     var item_q = selected_items[i][5]
     var q_name = "quantity" + i
     q_ele[i] = "document.forms[0]." + q_name
     document.write("<INPUT TYPE=\"TEXT\" VALUE=" + item_q + " NAME=" + q_name + " SIZE=\"3\">")
     document.write(" @ $" + selected_items[i][2] + " " + selected_items[i][3])
     var l_temp = selected_items[i][4]
     var i_sel = parseInt(selected_items[i][6])
     var c_name = "color" + i
     if(l_temp.length > 1){
     document.write("<SELECT NAME=" + c_name + ">")
     var sel_string = "Select a Color"
     document.write("<OPTION>" + sel_string)
     for(n=0; n<l_temp.length; ++n){
          document.write("<OPTION")
          if (i_sel==n){
              document.write(" SELECTED")
              }
          document.write(">" + l_temp[n])
          }
     }else{
     document.write("<SELECT NAME=" + c_name + ">")
     document.write("<OPTION SELECTED>" + l_temp[0])
     }
     document.write("</SELECT></TD>")
     var t_name = "total" + i
     var item_t = compute_item_totals(selected_items[i][2], item_q)
     document.write("<TD VALIGN=TOP><INPUT TYPE=\"TEXT\" VALUE=" + item_t + " NAME=" + t_name + " SIZE=\"5\"></TD></TR>")
     c_ele[i] = "document.forms[0]." + c_name
     t_ele[i] = "document.forms[0]." + t_name
     t_ele[i].value = item_t
     }
     }
//totals
document.write("<TR><TD COLSPAN=4 ALIGN=RIGHT>")
document.write("Subtotal")
document.write("</TD><TD ALIGN=LEFT>")
document.write("<INPUT TYPE=\"TEXT\"")
document.write(" VALUE=" + item_subtotal)
document.write(" NAME=\"subtotal\"")
document.write(" SIZE=\"5\"")
document.write(">")
document.write("</TD></TR>")
document.write("<TR><TD COLSPAN=4 ALIGN=RIGHT>")
document.write("Shipping")
document.write("</TD><TD ALIGN=LEFT>")
document.write("<INPUT TYPE=\"TEXT\"")
document.write(" VALUE=" + item_shipping)
document.write(" NAME=\"shipping\"")
document.write(" SIZE=\"5\"")
document.write(">")
document.write("</TD></TR>")
document.write("<TR><TD COLSPAN=4 ALIGN=RIGHT>")
document.write("Total")
document.write("</TD><TD ALIGN=LEFT>")
document.write("<INPUT TYPE=\"TEXT\"")
document.write(" VALUE=" + order_total)
document.write(" NAME=\"total\"")
document.write(" SIZE=\"5\"")
document.write(">")
document.write("</TD></TR>")
document.write("<TR><TD COLSPAN=3>Click <B>CALCULATE</B> to update totals.</TD>")
document.write("<TD COLSPAN=2 ALIGN=LEFT VALIGN=TOP>")
document.write("<INPUT TYPE=\"BUTTON\" NAME=\"recalculate\" VALUE=\"CALCULATE\"  ONCLICK=\"update_totals()\">")
document.write("</TD>")
document.write("<TD></TD>")
document.write("<TR><TD COLSPAN=3 VALIGN=TOP>Click <B>RESET</B> to clear the shopping cart.</TD>")
document.write("<TD COLSPAN=2 ALIGN=LEFT VALIGN=TOP>")
document.write("<INPUT TYPE=\"BUTTON\" NAME=\"clearTheForm\" VALUE=\"RESET\"  ONCLICK=\"clearItems()\"> ")
document.write("</TD></TR>")
document.write("<TR><TD COLSPAN=3>Click <B>ORDER HELP</B> for help with you order.</TD>")
document.write("<TD COLSPAN=2 ALIGN=LEFT VALIGN=TOP>")
document.write("<INPUT TYPE=\"BUTTON\" NAME=\"orderhelp\" VALUE=\"ORDER HELP\"  ONCLICK=\"order_help()\">")
document.write("</TD>")
document.write("<TD></TD>")
document.write("<TR><TD COLSPAN=7>To complete your order:</TD><TD></TD></TR>")
document.write("<TR><TD></TD><TD COLSPAN=6>select quantities and colors for your items (above);<BR>")
document.write("click <B>CALCULATE</B> to see totals;<BR>")
document.write("fill in your name and shipping address (below); and<BR>")
document.write("click <B>SUBMIT ORDER</B> (below) to send in your completed order.</TD></TR>")
document.write("<TR><TD COLSPAN=7>Once you have submitted your order, you will be given a secure form for your credit card information.</TD><TD></TD></TR>")
document.write("<TR><TD COLSPAN=7><HR WIDTH=80%></TD></TR>")
document.write("</TABLE>")
document.write("<TABLE>")
document.write("<TR><TD ALIGN=RIGHT><B>Name</B></TD>")
document.write("<TD><INPUT TYPE=\"text\" NAME=\"yourName\" SIZE=24 MAXLENGTH=24></TD></TR>")
document.write("<TR><TD ALIGN=RIGHT><B>Address</B></TD>")
document.write("<TD><INPUT TYPE=\"text\" NAME=\"shipAdd\" SIZE=24 MAXLENGTH=24></TD></TR>")
document.write("<TR><TD ALIGN=RIGHT><B>City</B></TD>")
document.write("<TD><INPUT TYPE=\"text\" NAME=\"shipCity\" SIZE=24 MAXLENGTH=24></TD></TR>")
document.write("<TR><TD ALIGN=RIGHT><B>State</B></TD>")
document.write("<TD><INPUT TYPE=\"text\" NAME=\"shipState\" SIZE=2 MAXLENGTH=2>")
document.write("<B> Zip Code</B><INPUT TYPE=\"text\" NAME=\"shipPost\" SIZE=8 MAXLENGTH=8><TD></TR>")
document.write("<TR><TD ALIGN=RIGHT><B>Country</B></TD>")
document.write("<TD><INPUT TYPE=\"text\" NAME=\"shipCountry\" SIZE=24 MAXLENGTH=24></TD><TR>")
document.write("<TR><TD ALIGN=RIGHT><B>Telephone</B></TD>")
document.write("<TD><INPUT TYPE=\"text\" NAME=\"telep\"  SIZE=12 MAXLENGTH=12></TD></TR>")
document.write("<TR><TD ALIGN=RIGHT><B>eMail</B></TD>")
// Changed to conform with Interland Specs  ejm 10-10-01
document.write("<TD><input type=\"text\" name=\"email\" value=\"\" size=\"30\"></TD></TR>")
//End Changes
document.write("<TR><TD ALIGN=RIGHT VALIGN=TOP><B>Comments</B></TD>")
document.write("<TD><TEXTAREA NAME=\"comments\" ROWS=6 COLS=32></TEXTAREA></TD></TR>")
document.write("<TR><TD></TD></TR>")
document.write("<TR><TD COLSPAN=3>When your order form is complete, click <B>SUBMIT ORDER</B>.</TD></TR>")
document.write("<TR><TD></TD>")
document.write("<TD ALIGN=LEFT><INPUT TYPE=\"button\" VALUE=\"SUBMIT ORDER\" onClick=\"testAndSubmit()\">")
document.write("</TD></TR>")
document.write("<TR><TD COLSPAN=4><HR WIDTH=80%></TD></TR>")
} 

