//Template :  Display picture of product on catalog, 
//and the picture will also appear at the product 
//detailed information page. Use GreatShop Secure Form.
//LAYOUT DEFINITION = ISAIAH



var totalShip = 0;
var exp = new Date();                                   
exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 1));
var detail_value='';
var order = new makeArray(100); 


// Use this function to retrieve a cookie.
function getCookie(name){
var cname = name + "=";               
var dc = document.cookie;   
    if (dc.length > 0) {              
    begin = dc.indexOf(cname);       
        if (begin != -1) {           
        begin += cname.length;       
        end = dc.indexOf(";", begin);
            if (end == -1) end = dc.length;
            return unescape(dc.substring(begin, end));
        } 
    }
return null;
}

//alert(getCookie('orders'));
//decode the string;
function decodeorder(detail_value){
var ss; var k=1;
ss=detail_value.split("|");
for(var i = 0; i <= ss.length;i=i+4)  {
order[k] = new cartGoods(ss[i],ss[i+1],ss[i+2],ss[i+3]);

k++;
}

}


// Function to retrieve form element's value.

function setCookie(name, value, expires) {
document.cookie = name + "=" + escape(value) + "; path=/" +((expires == null) ? "" : "; expires=" + expires.toGMTString());
}



function makeArray(n){

      this.length = n;

      for(var i = 1; i <= n; i++){

            this[i] = 0;

      }

      return this;

   }


var value = getCookie('orderNum');
    if (value != null) {orderNum=value; } else
  {var orderNum = 0; }
value = getCookie('orders');
   if (value != null) {decodeorder(value); }
value = getCookie('SearH');
   if (value != null) {sWord=value; }

//alert(orderNum);
//var orderNum = 0;                                             
                     
var indexNum = 0;
var count;
var formSave;

function updatetot(){
//scrollit(100);
var  u_tot=0;
for(var i = 1; i <= orderNum;i++)  {
u_tot+=parseFloat(order[i].totSum);}
document.forms[0].u_total.value=currency(u_tot);

}


  function currency(money){

     money = money + ""           

     var monLen = money.length;

     var digPos = money.indexOf(".");

     if(digPos == -1 & monLen < 1){

       money = money.substring(0,digPos+ 1) + "00";
    } else if(digPos == -1 & monLen > 0){
       return money;

    }else{

              cents = money.substring(digPos + 1, monLen + 1);

              if(cents.length == 1){

                  money = money + "0";

             }else if(cents.length > 2){

                      roundVal = cents.charAt(2);

                      if(roundVal  >= 5){

                         money = parseFloat(money) + .01;

                         money = money + "";

                         money = money.substring(0,digPos + 3)

                      }else{

                          money = money.substring(0,digPos + 3)

                      }

               }

      }

     return money;

   }


//////////////////////      1


function Currency(money)
{
	//convert an value into a string
	money =  parseFloat(money);
	money += 0.005;
	money +=  "";           
	var monLen = money.length;
	var digPos = money.indexOf(".");
	if(digPos == -1) {
		if (money <=0) {
			money ="0.00";
		} else {
			money += ".00";
		}
		return money;
	} else {
		if (digPos + 3 > monLen) {
			money += "0";
		} else if (digPos + 3 != monLen) {
			money = money.substring(0, digPos+3);
		} 
		return money;
	}     
}


//////////////////////////////////


function S_Method (name,price){

        this.name = name;

        this.price = price;

}

// for paypal shipping method
function sUpate (obj,total){
	var ship ;
        ship = obj.shipSelection.options[obj.shipSelection.options.selectedIndex].value;
	for (var i=1;i<=s_method.length;i++) {
	
	if (ship==s_method[i].name) { total+=parseFloat(s_method[i].price); 
	obj.finalTot.value = currency(parseFloat(total)); 
	obj.amount.value = currency(parseFloat(total)); 
	break; }
	}
	
}



function Addword(theForm)
{
	var cWin= parent.frames['catalog'].document;
	var itemName = theForm.itemName.value;
	var basePrice = parseFloat(theForm.basePrice.value);
	var totalPrice = basePrice;
	var totalSubField = parseInt(theForm.totalSubField.value);
	
	
	//now the subfield
	var i;
	var tmpStr;
	for (i=0;i<totalSubField;i++) {
		tmpStr = GetSelection(theForm, i);
		totalPrice += parseFloat(tmpStr);
		//now we need to append the subfield into the item name
		var n= tmpStr.indexOf("::");
		n+=2;
		itemName += ", " + tmpStr.substr(n);
			
	}
	var str="Add this item?\n"+itemName + "\n";
	var unitPrice= totalPrice;
	str += "Unit Price $" + Currency(totalPrice ) +"\n";
	var qty=parseInt(theForm.Qty.value);
	str += "Quantity " + qty +"\n";
	str += "Total Price:$"+Currency(totalPrice*qty);
	if (confirm(str)) {
		AddRecord(itemName, unitPrice, qty);
	} else {
		alert("This item was not placed in your shopping cart.");
		return;
	}

}


function MakeArray(n) {
      this.length = n;
      for(var i = 0; i < n; i++){
            this[i] = 0;
      }
      return this;
}


function RECORD(n)
{
	this.length = n;
	this.curLength = 0;
	this.itemName=new MakeArray(n);
	this.price=new MakeArray(n);
	this.quantity=new MakeArray(n);
	return this;
}



//we temp. make the user able to put up to a max of 250 orderRecords per store
var orderRecord = new RECORD(20000);


function AddRecord(itemName, unitPrice, qty)
{
	var i;
	for (i=0;i<orderRecord.curLength;i++) {
		if (orderRecord.itemName[i] == itemName) {
			orderRecord.quantity[i] += qty;
			return;
		}
	}

	if (orderRecord.curLength < orderRecord.length) {
		orderRecord.itemName[orderRecord.curLength] =itemName;
		orderRecord.quantity[orderRecord.curLength] = qty;
		orderRecord.price[orderRecord.curLength] = unitPrice;
		orderRecord.curLength++;
	} else {
		alert("This order was not placed in your shopping cart because your shopping cart has fill up.\nPlease check out to empty it before continue with next order");
	}
}






//////////////////  2


function GetSelection(theForm, fieldNum)
{
	var subField = eval("theForm.subfield"+fieldNum);
	for (var i = 0; i < subField.length; i++) {
		   if (subField.options[i].selected) {
				return subField.options[i].value;
			}
	}
	return 0;
}




/////////////////////3





function CalUnitPrice(theForm)
{

	var totalPrice = parseFloat(theForm.basePrice.value);
	var totalSubField = parseInt(theForm.totalSubField.value);


	//now the subfield
	var i;
	for (i=0;i<totalSubField;i++) {
		var tmpStr = GetSelection(theForm, i);
		totalPrice += parseFloat(tmpStr);
	}
	theForm.unit.value = Currency(totalPrice) ;


parent.frames['catalog'].document.isaiah.subTotal.value =Currency(totalPrice) ;



}



///////////////////////






   function showProd(form){

       var iter = 0;

       var match = false;

       var oldlen = 1;

       count = 1;

       sWin = parent.document // sWin = parent.frames['catalog'].document

       prodName = getCookie("SearH"); // prodName = parent.frames['toc'].document.searcher.lookup.value;

       sWin.open();

       sWin.write("<HTML><HEAD><TITLE>"+  prodName + " </TITLE></HEAD>");

       sWin.write("<BODY  bgcolor=#ffffff  text=#000000>");

       for (var i = 1; i <= prodID.length; i++){

             //alert(theProd + " " + prodID[i].name.toUpperCase());

             if(prodName.toUpperCase() == prodID[i].name.toUpperCase()){

                indexNum = i;

                prodID[i].show(sWin,i);

                match = true;

             }

       }








       if(!match){
            pTotal = new makeArray(prodID.length);
            for (var i = 1; i <= prodID.length; i++){
                 var pSearch = prodName.toUpperCase();
                 var pInventory = prodID[i].name.toUpperCase();
                 //for(var x = 1; x <= pSearch.length; x++){
		 for(var x = 0; x <= pInventory.length-pSearch.length; x++){
		         //alert(pInventory.substring(x,x+pSearch.length));
			 if(pSearch == pInventory.substring(x,x+pSearch.length)){
			 //if(pSearch.substring(0,x) == pInventory.substring(0,x)){
			 pTotal[i] = pSearch;
			 break;    
                     }
                  }
              };

oldlen=0;
              for (var i = 1; i <= prodID.length; i++){
                  // alert(pTotal[i] + " " + i);
                   if(pTotal[i] != "0"){ prodID[i].show(sWin,i);
                       if(pTotal[i].length >= oldlen){
                            oldlen = 1;// pTotal[i].length;
                            olditer = iter;
                            var iter = i;
                        }
                    }
                 }
                if (oldlen!=1){

sWin.write("<center><font face=arial size=+1 color=blue><b>Your Search Got 0 Result!<br>Please try again.</b></font></center>");

}

      }
           sWin.write("</BODY></HTML>");
           sWin.close();
   }






    function searchType(form){

         count = 1;

         prodTypeInfo = form;

         var match = false;

         tWin = parent.document //tWin = parent.frames[2].document

         tWin.open();

        tWin.write("<HTML><HEAD><TITLE>"+  prodTypeInfo + " </TITLE></HEAD>");



        tWin.write("<BODY  background=back_browse.gif>");

        for (var i = 1; i <= prodID.length; i++){

             if(prodTypeInfo == prodID[i].type){

                indexNum = i;

                prodID[i].show(tWin,i);

                match = true;

              }

       }

       tWin.write("</BODY></HTML>");

       tWin.close();

   }



    function product (name,description,image,price,type,link,url){

        this.name = name;

        this.description = description;
        this.image = image

        this.price = price;

        this.type = type;

        this.show = show;
        if(link != ""){
          this.link = "<center><TABLE BORDER=0><TR><TD><A HREF='" + url + "'><Font face=arial size=-2>" + link + "</font></A></TD></TR></TABLE></center>";
        }else{
          this.link = "";
        }

    }

    

    function show(w,prodIndexNum){

         w.write("<center><TABLE BORDER = 0 WIDTH=300><TR><TD BGCOLOR=#d5d5ff><FONT FACE='arial' color=blue><b>"  + this.name + "</b></FONT></TD></TR></TABLE></center>");

             if(this.image.length > 1){

               w.write("<CENTER><TABLE BORDER=0 COLS=2 WIDTH=300 BGCOLOR=#FFCC00 ><TR BGCOLOR=#00CC00><TD><FONT FACE = 'Arial' SIZE = 2 >Image</FONT></TD><TD><FONT FACE = 'Arial' SIZE = 2 >Description</FONT></TD></TR><TR><TD><IMG SRC='" + this.image + "'></TD>");

 w.write("<TD><FONT FACE = 'Arial' SIZE = 2 >" + this.description + "</TD></TR></Table></CENTER>");

             }
           if(this.link != ""){
              w.write(this.link);
           }




           w.write("<FORM NAME=isaiah>");

            //alert(prodIndexNum);

           orderProd(this,w,prodIndexNum);

           w.write("</FORM><HR SIZE=1 NOSHADE WIDTH=90%><br>");

          // w.write("&nbsp;&nbsp;&nbsp;&nbsp; <INPUT TYPE = 'button' VALUE = 'Go Back' onClick = history.go(-1)>");
          


    }



   function orderProd(obj,win,index){


     win.write("<CENTER><TABLE BORDER=0 COLS=2 WIDTH=300 BGCOLOR=#CCCCCC><TR><TD><FONT FACE = 'arial' size=-1><b>Price Each: $</b>" + obj.price+"</font></CENTER>");

     win.write("&nbsp;&nbsp;<FONT FACE = 'arial' size=-1><b>Enter Quantity:</b></font>  " + "<INPUT TYPE = 'text' SIZE = 3 NAME = 'q' VALUE = '1' onBlur = parent.reTotal("+ count + "," +  obj.price + ") onFocus = parent.reTotal("+ count + "," +  obj.price + ")><br>");



     win.write("&nbsp;&nbsp;<FONT FACE = 'arial' size=-1><b>Total:" + " $</b></font><INPUT TYPE = 'text' SIZE=7 NAME= subTotal VALUE =" + obj.price + " onfocus=this.blur()>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;" + "<INPUT TYPE ='button' VALUE = 'SubTotal' onClick = parent.reTotal("+ count + "," +  obj.price + ")></TR></TABLE></CENTER>");



     win.write("<CENTER><IMG SRC=pickit.gif ALIGN=TEXTTOP><A HREF=javascript:parent.add(" + count + "," + index + ")><IMG SRC=addtocart.gif border=0></A>")


   count++;

 }



    function add(id, oIndex){
	
	
        var theForm =  parent.document.forms[id];

        productName = prodID[oIndex].name;

        totalSum = parent.document.forms[id].subTotal.value;

        totalQuantity =  parent.document.forms[id].q.value;

     if(totalQuantity == 0){

         alert("You entered a quantity of 0!\n We cannot process this order");


        parent.document.forms[id].q.value = 1;

         reTotal(id,prodID[oIndex].price);

     }else{

      if( confirm("You are adding " + totalQuantity + " order/s of " + productName + " \n Subtotal: " + totalSum + " to your shopping cart.")){

          store(oIndex,totalSum,totalQuantity,totalShip);
	  orderdata();
	
	  setCookie('orderNum', orderNum, exp);
	  setCookie('orders', detail_value, exp);	

        }else{

           alert("\n\nThis order was not placed in your shopping cart.");

        }

    }

   }



      function store(o,ts,tq,totS){

            orderNum++;

           order[orderNum] = new cartGoods(o,ts,tq,totS);

           showTotal = 0;

           for(var i = 1; i <= orderNum;i++){

                 showTotal += parseFloat(order[i].totSum);                
		 //alert(totalShip);
            }

             parent.document.forms[0].u_total.value = currency(showTotal);



     }


function orderdata(){
detail_value='';
 for(var i = 1; i <= orderNum; i++){ 
detail_value += order[i].Indx+'|';
detail_value += order[i].totSum+'|';
detail_value += order[i].totQ+'|';
detail_value += order[i].ttS+'|';
//alert(detail_value);
}  }


//////////////






function Addmore(theForm)
{
	var cWin= parent.frames['catalog'].document;
	var itemName = theForm.itemName.value;
	var basePrice = parseFloat(theForm.basePrice.value);
	var totalPrice = basePrice;
	var totalSubField = parseInt(theForm.totalSubField.value);
	
	
	//now the subfield
	var i;
	var tmpStr;
	for (i=0;i<totalSubField;i++) {
		tmpStr = GetSelection(theForm, i);
		totalPrice += parseFloat(tmpStr);
		//now we need to append the subfield into the item name
		var n= tmpStr.indexOf("::");
		n+=2;
		itemName += ", " + tmpStr.substr(n);
			
	}
	var str="Add this item?\n"+itemName + "\n";
	var unitPrice= totalPrice;
	str += "Unit Price $" + Currency(totalPrice ) +"\n";
	var qty=parseInt(theForm.Qty.value);
	str += "Quantity " + qty +"\n";
	str += "Total Price:$"+Currency(totalPrice*qty);
	if (confirm(str)) {


		AddRecord(itemName, unitPrice, qty);
             


	} else {
		alert("This item was not placed in your shopping cart.");
		return;
	}
	//ViewCart();
	//PrintCartTotal();
}







    function cartGoods(Indx, totSum, totQ, ttS){

         //this.Indx = prodID[Indx].name;
	 this.Indx = Indx;
         this.totSum = totSum;

         this.totQ = totQ; this.ttS = ttS;

   }



    function view(){
	 vWin = parent.document;         // vWin = parent.frames[2].document;
           vWin.open();
         vWin.write("<HTML><BODY BGCOLOR=White text=Black><CENTER>");
       if(orderNum != 0){
         vWin.write("<IMG SRC=updatebasket.gif><FONT COLOR=blue  Size=5><b>" + "Your Shopping Basket Contents</b></FONT><P>");
         vWin.write("<FORM><TABLE BORDER=0>");
         vWin.write("<TD COLSPAN=1 BGCOLOR=#ffcc00><FONT face=arial COLOR=WindowText>Quantity</FONT></TD>");
         vWin.write("<TD COLSPAN=1 BGCOLOR=#ffcc00><FONT face=arial COLOR=WindowText>Product</FONT></TD>");
         vWin.write("<TD COLSPAN=1 BGCOLOR=#ffcc00><FONT face=arial COLOR=WindowText>Price</FONT></TD>");
         vWin.write("<TD COLSPAN=1 BGCOLOR=#ffcc00><FONT face='Arial' size=2 COLOR=WindowText></FONT></TD><TR>");
         for(var i = 1; i <= orderNum; i++){
         vWin.write("<TD COLSPAN=1 align=center BGCOLOR=#D5D5FF><FONT COLOR=WindowText face='Arial' Size=3>"+order[i].totQ+"</FONT></TD>");
         vWin.write("<TD COLSPAN=1 BGCOLOR=#D5D5FF><FONT COLOR=WindowText face='Arial' Size=3>"+prodID[order[i].Indx].name+"</FONT></TD>");
         vWin.write("<TD COLSPAN=1 BGCOLOR=#D5D5FF><FONT COLOR=WindowText face='Arial' Size=3>"+order[i].totSum+"</FONT></TD>");
         vWin.write("<TD VAlign=TOP align=center BGCOLOR=white><input type='checkbox' Name=checkbox"+i+" onclick=parent.remove("+i+")></Font>");
         vWin.write("<FONT COLOR=WindowText face='Arial' Size=1><b>Check here to remove item</b></FONT></TD></TR>");
         }
      


// vWin.write("</TABLE></FONT></FORM><br><br><A HREF=javascript:history.back()><IMG SRC=continueShop.gif border=0></A>");

  vWin.write("</TABLE></FONT></FORM><br><TABLE BORDER=0 COLS=4 WIDTH=100% ><TR><TD><A HREF=view.html><IMG BORDER=0 SRC=updatebasket.gif ></A><font size=-2 face=arial>View Basket</font></TD><TD><A HREF=javascript:check()><IMG BORDER=0 SRC=checkout.gif></A><font size=-2 face=arial>Check Out</font></TD><TD><A HREF=index.html><img SRC=Home.gif border=0></A> <font size=-2 face=arial>Store Front</font></TD><TD><A HREF=javascript:history.back(-1)><font face=arial size=-2><img src=exit.gif border=0></font></A><font size=-2 Face=arial>Continue To Shop</font></TD></TR></TABLE>");

      }else{
            vWin.write("<FONT SIZE = 5 FACE = 'arial'><br>" + "<br><IMG SRC=noitem.gif border=0></FONT>");
            if(navigator.appName.indexOf("Netscape") != -1){
               vWin.write("<FORM><INPUT TYPE='button' VALUE='Back to Order Form' onclick='history.go(-1)'>");
            }
            }
            vWin.write("</TABLE></FONT></FORM></BODY></HTML>");
            vWin.close();
    }

    function remove(item){
       var newSum = 0;
       for(var i = item+1; i <= orderNum; i++){
          if(item == orderNum){
                   order[i].Indx = "";
                   order[i].totSum = 0 ;
                   order[i].totQ = "";
                   order[i].ttS = 0;
		   break;
          }else{
                   order[i-1].Indx = order[i].Indx;
                   order[i-1].totSum = order[i].totSum;
                   order[i-1].totQ = order[i].totQ;
		   order[i-1].ttS = order[i].ttS;
          }
      }
      orderNum--;
      for(var i = 1; i <= orderNum;i++){
          newSum += parseFloat(order[i].totSum);
      }
      parent.document.forms[0].u_total.value = currency(newSum);
      orderdata();
	
      setCookie('orderNum', orderNum, exp);
      setCookie('orders', detail_value, exp);
      document.location="view.html";

     }
    function checkOut(){
      if(orderNum != 0){
        cWin = parent.document;
        cWin.open();
        cWin.write("<HTML><BODY background=back_invoice.gif text=Black><Center>");
	cWin.write("<center><IMG SRC=checkout.gif><Font COLOR=Blue Size=5><b>Check Out At Cash Register</b></Font></center><br><Table border=0><tr>");
        grandTotal = 0;
        // cWin.write("<FORM NAME = 'orderfor'>");
        cWin.write("<TD COLSPAN=1 BGCOLOR=#ffcc00><FONT face=arial COLOR=WindowText>Quantity</FONT></TD>");
        cWin.write("<TD COLSPAN=1 BGCOLOR=#ffcc00><FONT face=arial COLOR=WindowText>Product</FONT></TD>");
        cWin.write("<TD COLSPAN=1 BGCOLOR=#ffcc00><FONT face=arial COLOR=WindowText>Price</FONT></TD>");
        cWin.write("<TD COLSPAN=1 BGCOLOR=#ffcc00><FONT face=arial COLOR=WindowText>Total Price</FONT></TD></TR>");
        for(var i = 1; i <= orderNum; i++){
        cWin.write("<TD COLSPAN=1 align=center BGCOLOR=#d5d5ff><FONT COLOR=WindowText face='Arial' Size=2>"+order[i].totQ+"</FONT></TD>");
        cWin.write("<TD COLSPAN=1 align=center BGCOLOR=#d5d5ff><FONT COLOR=WindowText face='Arial' Size=2>"+prodID[order[i].Indx].name+"</FONT></TD>");
        cWin.write("<TD COLSPAN=1 align=center BGCOLOR=#d5d5ff><FONT COLOR=WindowText face='Arial' Size=2>"+parent.currency(order[i].totSum/order[i].totQ)+"</FONT></TD>");
        cWin.write("<TD COLSPAN=1 align=center BGCOLOR=#d5d5ff><FONT COLOR=WindowText face='Arial' Size=2>"+parent.currency(order[i].totSum)+"</FONT></TD></TR>");
        grandTotal += parseFloat(order[i].totSum); 
        }
	finalSum = currency(grandTotal);
        cWin.write("<TD COLSPAN=3 ALIGN=CENTER bgcolor='#009933'><font face=arial COLOR=#ffcc00><b>Total:</b></font></TD>");

        cWin.write("<TD COLSPAN=1 ALIGN=CENTER bgcolor='#009933'><font face=arial COLOR=#ffcc00><b>$ " + finalSum + " </b><SMALL>(excluded tax)</SMALL></font></TD>");

        cWin.write("</TR></TABLE></CENTER>");
	// cWin.write("<br><br><b>Total:  $" + finalSum + " </b><b>");
        cWin.write("</b></form><br><br><font face=arial size =-1>If this is correct please fill out and submit the form below.<br>");

	cWin.write("If there is an error in your order or something you wish" + " to change, click \"View Basket\" to make the changes.</font><br>");

//THE FOLLOWING SECURE FORM SUBMISSION USES SSL SERVICE UNDER GREATSHOP'S ACCOUNT.


//CHANGE YOUR E-MAIL HERE! 

	cWin.write("<FORM NAME=orderform METHOD='POST' " );
	cWin.write("ACTION=https://ssl.webspan.net/~greatsho/cgi-bin/greatshop2.cgi>  <INPUT type=hidden name=recipient value=" ); 





	cWin.write("iscsoftware@programmer.net");

	cWin.write(" onSubmit=return false>");



	cWin.write("<table border=0>");
        cWin.write("<tr><td colspan=2><b>Billing Address:</b></td></tr>");
        cWin.write("<tR><td align=right>NAME:</td><td><INPUT TYPE = 'text' SIZE = 50 NAME = 'name'></td></tr>");


	cWin.write("<Tr><td align=right>Street Address:</tD><td><INPUT TYPE = 'text' SIZE = 43 NAME = 'addr'></td></tr>");


        cWin.write("<Tr><td align=right>City, State, Zip:</td><td><INPUT TYPE = 'text' SIZE = 52 NAME = 'city'></td></tr>");


        cWin.write("<Tr><td align=right>Country:</td><tD><INPUT TYPE = 'text' SIZE = 2 NAME = 'country'></td></tr>");



        cWin.write("<Tr><td align=right>Telephone:</td><td><INPUT TYPE = 'text' SIZE = 20 NAME = 'phone'></td></tr>"); 
        cWin.write("<Tr><td align=right>Fax:</td><td><INPUT TYPE = 'text' SIZE = 20 NAME = 'fax'></td></tr>");
        cWin.write("<Tr><td colspan=2><b>Shipping Address (Optional):</b></td></tr>");
        cWin.write("<Tr><td align=right>NAME:</td><td><INPUT TYPE = 'text' SIZE = 50 NAME = 'shipname'></td></tr>");           
        cWin.write("<Tr><td align=right>Street Address:</td><td><INPUT TYPE = 'text' SIZE = 43 NAME = 'shipaddress'></td></tr>");
        cWin.write("<Tr><td align=right>City:</td><td><INPUT TYPE = 'text' SIZE = 52 NAME = 'shipaddress2'></td></tr>");
        cWin.write("<Tr><td align=right>State:</td><td><INPUT TYPE = 'text' SIZE = 2 NAME = 'shipcity'></td></tr>"); 
        cWin.write("<Tr><td align=right>Zip Code:</td><Td><INPUT TYPE = 'text' SIZE = 5 NAME = 'shipcode'></td></tr>");
        cWin.write("<Tr><td align=right>Telephone:</td><td><INPUT TYPE = 'text' SIZE = 20 NAME = 'phone'></td></tr>");
        cWin.write("<Tr><td align=right>Shipping Method (Fees Billed Separately):</td><td><SELECT NAME = 'shipSelection' onChange = 'parent.shipping(this.form," +  currency(grandTotal) + ")'>");

        //cWin.write("<Tr><td align=right>Shipping Method:<SELECT NAME = 'item' onChange = 'parent.shipping(this.form," +  currency(grandTotal) + ")'>");



//EDIT SHIPPING METHOD HERE!

        for(var i=1; i <= s_method.length;i++){
	cWin.write("<option value='"+s_method[i].name+"'>");
	cWin.write(s_method[i].name);
	cWin.write("</option>");
	}
	cWin.write("</Select><font size=-1 face=arial><A HREF=shipping.html>Click here for shipping rate..</A></font></td></tr>");
        cWin.write("<Tr><td align=right></td><td><INPUT TYPE = 'hidden' SIZE = 15 NAME = 'finalTot'></td></tr>");
  
        cWin.write("<Tr><td align=right>Other shipping instructions:</td><td><TEXTAREA NAME=item2 ROWS=8 COLS=50  value=''></TEXTAREA></td></tr><br>");

      


// EDIT THE LINE BELOW. ASK: DO YOU LIVE IN CALIFNORNIA OR OTHER STATE AS APPLICABLE.
// TO REMOVE THE LINE BELOW, TYPE // AT THE FRONT OF THE LINE.

      
	//cWin.write("<tr><td align=right>Do you live in CA?</td><td><input type=radio Name=co Value=yes onclick =parent.shipping(this.form," +  finalSum + ");parent.withTax(this.form)>Yes <input type=radio Name=co value=no checked onclick =parent.shipping(this.form," +  currency(finalSum - (grandTotal * 8.25/100)) + ");parent.withoutTax(this.form)>No</td></tr>");
	cWin.write("<tr><td align=right>Do you live in CA?</td><td><input type=radio Name=co Value=yes onclick =parent.withTax(this.form)>Yes <input type=radio Name=co value=no checked onclick =parent.withoutTax(this.form)>No</td></tr>");          

        cWin.write("<tr><td align=right>Total Due: $</td><td><input type='text' value='"+currency(grandTotal)+"' size=15 name='finalTax'><font face=arial size=-1>(Include applicable sales tax)</font></td></tr>");

//EDIT PAYMENT TYPE HERE!

        cWin.write("<Tr><td align=right>Payment Type:</td><td><SELECT NAME = 'card'>");
	cWin.write("<OPTION VALUE = 'CreditCard (VISA)'>Credit Card (VISA)");
	cWin.write("<OPTION VALUE = 'CreditCard (MASTERCARD)'>Credit Card (MASTERCARD)");
	cWin.write("<OPTION VALUE = 'CreditCard (AMERICAN EXPRESS)'>Credit Card (AMERICAN EXPRESS)");
	cWin.write("<OPTION VALUE = 'CreditCard (DISCOVER)'>Credit Card (DISCOVER)");
	cWin.write("<OPTION VALUE = 'Check/MoneyOrder'>Check or Money Order.");
	cWin.write("<OPTION VALUE = 'BillMe'>Send Bill To Me</select></td></tr>");
        cWin.write("<Tr><td align=right>Credit Card Number:</td><td><INPUT TYPE = 'text' SIZE = 20 NAME = 'card_num'><font face=arial size=-1>(if pay by credit card)</font></td></tr>");
        cWin.write("<Tr><td align=right>Expiration Date (MM/YY):</td><td><INPUT TYPE = 'text' SIZE = 8 NAME = 'exp'><font face=arial size=-1>(if pay by credit card)</font></td></tr>");
          
        cWin.write("<INPUT TYPE='hidden' NAME='order'" + " VALUE = ''>");
        cWin.write("<input type='hidden' name='totwotax' value='"+grandTotal+"'>");
	cWin.write("<input type='hidden' name='tax' value='"+currency(grandTotal * 8.25/100)+"'>");

        cWin.write("<Tr><td align=right><INPUT TYPE = 'submit' VALUE = 'Submit Now (Secured)' onClick = 'parent.formData(this.form)'></td>");

        cWin.write("<td><INPUT TYPE = 'reset' VALUE = 'Reset'></td></tr></table>");
        cWin.write("</FORM>");
        cWin.write("<br><small>Secured Form Mailer: Courtesy of Majon International.</small></b></FONT>");
        cWin.write("</BODY></HTML>");
        cWin.close();
      }else{
         alert("\n\nYour shopping cart is empty!\n\n");
	 //document.location="checkout.html"
      }
    }



    function formData(form){

         var formElems = form.elements.length;
         formSave = new makeArray(formElems-3);
         for(var i = 1; i <= formElems; i++){
              formSave[i] = form.elements[i-1].value;
         }
         for(var i = 1; i <= orderNum; i++){
               form.elements[23].value += "Quantity:" + order[i].totQ

               form.elements[23].value += " " + prodID[order[i].Indx].name
               form.elements[23].value += " at " + order[i].totSum/order[i].totQ + " |"
         }
        form.submit();           
    }



  

      function reTotal(c,totalPrice){
             //totalPrice = totalPrice * parent.frames['catalog'].document.forms[c].q.value;
	     totalPrice = totalPrice * parent.document.forms[c].q.value;

             newTotal = currency(totalPrice) 
             //parent.frames['catalog'].document.forms[c].subTotal.value = newTotal;
	     parent.document.forms[c].subTotal.value = newTotal;
      }

     function shipping(form, fSum){
	//	  form.finalTax.value =currency(parseFloat(fSum));
        //  shipCost = form.shipSelection.options[form.shipSelection.selectedIndex].value;
	//    form.finalTot.value =currency( parseFloat(shipCost) + parseFloat(fSum));
	
	var ship ;
        ship = form.shipSelection.options[form.shipSelection.options.selectedIndex].value;
      for (var i=1;i<=s_method.length;i++) {
	
	if (ship==s_method[i].name) { fSum+=parseFloat(s_method[i].price); 
		if (form.co[0].checked == true) {
		setCookie('ShiP',s_method[i].price,exp);
		//form.finalTax.value = currency(parseFloat(fSum) + 100); 
		withTax(form);
		}
		if (form.co[1].checked == true) {
		setCookie('ShiP',s_method[i].price,exp);
		//form.finalTax.value = currency(parseFloat(fSum)); 
		withoutTax(form);
		}
	break;
	}
      }
     }
	

// CHANGE TO YOUR STATE SALES TAX. CA TAX IS 8.25% 


	function withTax(form){
	var ship;
	ship = parseFloat(getCookie("ShiP"));
	form.finalTax.value =currency(grandTotal *8.25/100 + grandTotal + ship); 

	}
	
	function withoutTax(form){
	var ship;
	ship = parseFloat(getCookie("ShiP"));
      //    form.finalTax.value =0;

	form.finalTax.value =currency(grandTotal + ship);


	}

    function empty(){
       if(orderNum == 0){
          alert("\n\nYour cart is already empty!\n\n");
       }else{
           orderNum = 0;
           alert("\nYour cart has been emptied!\n");
       }
   }



function paypalCheckOut(){
	var Gtotal;
	var tax ;
	var finalSum;
	var item_detail;
	Gtotal = 0;
	item_detail='';
	for(var i = 1; i <= orderNum; i++){ 
	item_detail+= order[i].totQ+' ';
	item_detail+= prodID[order[i].Indx].name+' at ';
	item_detail+= prodID[order[i].Indx].price+'|';
	Gtotal+=parseFloat(order[i].totSum);
	}
	//item_detail+='(shipping)';
	
	
	finalSum = currency(((Gtotal * 8.25/100) + Gtotal));
	tax=currency(Gtotal * 8.25/100);
	cWin = parent.document;
	cWin.open;
	cWin.write("<FORM ACTION=\"https://www.paypal.com/cgi-bin/webscr\" METHOD=\"POST\" onsubmit=parent.setShipping(this," +  tax + ")>");
        cWin.write("<b>Shipping Method:</b><SELECT NAME = 'shipSelection' onChange = 'sUpate(this.form," +  finalSum + ")'>");

//EDIT SHIPPING METHOD HERE!

        for(var i=1; i <= s_method.length;i++){
	cWin.write("<option value='"+s_method[i].name+"'>");
	cWin.write(s_method[i].name);
	cWin.write("</option>");
	}
        cWin.write("</Select>");
	cWin.write("<br><b>Purchase Total = $</b><INPUT TYPE =text SIZE = 15 NAME =finalTot value=\""+finalSum+"\"> included sales tax & shipping fee.<br>"); 
	cWin.write("<input type=image SRC=\"http://images.paypal.com/images/x-click-but03.gif\" NAME=\"submit\" ALT=\"Make payments with PayPal - it's fast, free and secure!\"><font size=-1>Please select a suitable shipping method before sending to Paypal</font>") 
	cWin.write("<INPUT TYPE=\"hidden\" NAME=\"cmd\" VALUE=\"_xclick\">");
	cWin.write("<INPUT TYPE=\"hidden\" NAME=\"business\" VALUE=\"iscsoftware@programmer.net\">");
	cWin.write("<INPUT TYPE=\"hidden\" NAME=\"return\" VALUE=\"\">");
	cWin.write("<input type=hidden name=item_name value=\""+item_detail+"\">");
	cWin.write("<INPUT TYPE=\"hidden\" NAME=\"amount\" value=\""+finalSum+"\">");
	cWin.write("</form>");
	cWin.close;
}

function setShipping(objform,fsum)
{

	objform.item_name.value=objform.item_name.value+" (shipping : "+objform.shipSelection.options[objform.shipSelection.selectedIndex].text+")(tax : "+fsum+")";
	objform.amount.value=objform.finalTot.value;
}
