﻿// JScript File

function addToCart(product,product_name,qty,price,store,image,product_id)
{
    document.form1.product.value = product;
    document.form1.product_name.value = product_name; 
    document.form1.qty.value = qty;
    document.form1.price.value = price;
    document.form1.store.value = store; 
    document.form1.img.value = image; 
    document.form1.product_id.value = product_id; 
    document.form1.action.value = "updatecart"; 
    document.form1.submit(); 
}

function openWin(url)
{
    if (url == '1')
    {
        var newWin = window.open('http://betting.ladbrokes.com/en/horse-racing', '', '','');
    }
    if (url == '2')
    {
        var newWin = window.open('http://www.justbg.com/', '', '','');
    }
}
        
function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;  // if the style.display value is blank we try to figure it out here

  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function updateCart()
{
    document.form1.action.value = "update";
    document.form1.submit(); 
}

function updateProduct()
{
    document.form1.action.value = "updateproduct";
    document.form1.submit(); 
}

function ProcessSubmit()
{
    document.form1.action.value = "processsubmit";
    document.form1.submit(); 
}

function TrackingSubmit()
{
    document.form1.action.value = "trackingsubmit";
    document.form1.submit(); 
}

function UpdateOrder()
{
    document.form1.action.value = "updateorder";
    document.form1.submit(); 
}

function UpdateCustomer()
{
    document.form1.action.value = "updatecustomer";
    document.form1.submit(); 
}

function UpdateComplete()
{
    document.form1.action.value = "updatecomplete";
    document.form1.submit(); 
}

function hide(which) 
{
    var hide = new Array();
    hide = document.getElementsByName(which);
    
    for (i=0; i<hide.length; i++) {
      hide[i].style.display = 'none';
    }
}

function show(which) 
{
    var hide = new Array();
    hide = document.getElementsByName(which);
    
    for (i=0; i<hide.length; i++) {
      hide[i].style.display = 'inline';
    }
}

function placeOrder(obj)
{
    if (checkPaymentForm())
    {
        //hide(document.form1.placeOrder);  
        //show(document.form1.processing);
        //obj.src='../images/processing.gif';
        //obj.disabled=true;
        //obj.style.cursor='default'; 
        toggleLayer('ordering');
        toggleLayer('hiddenImage');
        continueProcessing();
    } 
    else
    {
        //obj.src='../images/button_submit_order.gif'; 
        //obj.disabled=false;
        //document.form1.placeOrder.disabled=false;
        return false;
    } 
}

function goToSignUp()
{
    document.form1.action.value = "signup";
    document.form1.submit(); 
}

function finishSignUp()
{
    document.form1.action.value = "finishsignup";
    document.form1.submit(); 
}

function continueProcessing()
{
    document.form1.action.value = "process";
    document.form1.submit(); 
}

function removeCart(index)
{
    document.form1.action.value = "remove";
    document.form1.remove_item.value = index;
    document.form1.submit(); 
}

function copyBillingToShipping()
{
    document.form1.shipping_first_name.value = document.form1.billing_first_name.value;
    document.form1.shipping_last_name.value = document.form1.billing_last_name.value;
    document.form1.shipping_company_name.value = document.form1.billing_company_name.value;
    document.form1.shipping_address_one.value = document.form1.billing_address_one.value;
    document.form1.shipping_address_two.value = document.form1.billing_address_two.value;
    document.form1.shipping_city.value = document.form1.billing_city.value;
    document.form1.shipping_state.value = document.form1.billing_state.value;
    document.form1.shipping_zip_code.value = document.form1.billing_zip_code.value;
    document.form1.shipping_phone_number.value = document.form1.billing_phone_number.value;
}

function continueToPayment()
{
   if (checkAddressForm())
   {
        document.form1.action.value = "payment";
        document.form1.submit(); 
   } 
   else
   {
        return false;
   }
}

function checkPaymentForm()
{
    var goodForm = true;
   
    if (document.form1.cc_number.value == '')
    {
          flagFormField(document.form1.cc_number);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.cc_number);
    }  
    
    if (document.form1.cc_expiration_month.value == '')
    {
          flagFormField(document.form1.cc_expiration_month);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.cc_expiration_month);
    }  
    
    if (document.form1.cc_expiration_year.value == '')
    {
          flagFormField(document.form1.cc_expiration_year);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.cc_expiration_year);
    }  
    
    if (document.form1.cc_security.value == '')
    {
          flagFormField(document.form1.cc_security);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.cc_security);
    }
    
    return goodForm;         
}
 
function checkAddressForm()
{
    var goodForm = true;
    
    if (document.form1.billing_first_name.value == '')
    {
          flagFormField(document.form1.billing_first_name);
          goodForm = false; 
    } 
    else
    {
          unFlagFormField(document.form1.billing_first_name);
    }   
    
    if (document.form1.billing_last_name.value == '')
    {
          flagFormField(document.form1.billing_last_name);
          goodForm = false; 
    }
    else  
    {
          unFlagFormField(document.form1.billing_last_name);
    }   
       
    if (document.form1.billing_address_one.value == '')
    {
          flagFormField(document.form1.billing_address_one);
          goodForm = false; 
    }  
    else 
    {
          unFlagFormField(document.form1.billing_address_one);
    }   
        
    if (document.form1.billing_city.value == '')
    {
          flagFormField(document.form1.billing_city);
          goodForm = false; 
    } 
    else 
    {
          unFlagFormField(document.form1.billing_city);
    }   
   
    if (document.form1.billing_state.value == '')
    {
          flagFormField(document.form1.billing_state);
          goodForm = false; 
    }  
    else 
    {
          unFlagFormField(document.form1.billing_state);
    }   
     
    if (document.form1.billing_zip_code.value == '')
    {
          flagFormField(document.form1.billing_zip_code);
          goodForm = false; 
    } 
    else 
    {
          unFlagFormField(document.form1.billing_zip_code);
    }   
   
    if (document.form1.billing_phone_number.value == '')
    {
          flagFormField(document.form1.billing_phone_number);
          goodForm = false; 
    }  
    else 
    {
          unFlagFormField(document.form1.billing_phone_number);
    }   
     
    if (document.form1.billing_email_address.value == '')
    {
          flagFormField(document.form1.billing_email_address);
          goodForm = false; 
    } 
    else 
    {
          unFlagFormField(document.form1.billing_email_address);
    }   
   
    if (document.form1.shipping_first_name.value == '')
    {
          flagFormField(document.form1.shipping_first_name);
          goodForm = false; 
    }  
    else 
    {
          unFlagFormField(document.form1.shipping_first_name);
    }   
     
    if (document.form1.shipping_last_name.value == '')
    {
          flagFormField(document.form1.shipping_last_name);
          goodForm = false; 
    } 
    else 
    {
          unFlagFormField(document.form1.shipping_last_name);
    }   
   
    if (document.form1.shipping_address_one.value == '')
    {
          flagFormField(document.form1.shipping_address_one);
          goodForm = false; 
    }  
    else 
    {
          unFlagFormField(document.form1.shipping_address_one);
    }   
     
    if (document.form1.shipping_city.value == '')
    {
          flagFormField(document.form1.shipping_city);
          goodForm = false; 
    } 
    else 
    {
          unFlagFormField(document.form1.shipping_city);
    }   
   
    if (document.form1.shipping_state.value == '')
    {
          flagFormField(document.form1.shipping_state);
          goodForm = false; 
    }  
    else 
    {
          unFlagFormField(document.form1.shipping_state);
    }   
     
    if (document.form1.shipping_zip_code.value == '')
    {
          flagFormField(document.form1.shipping_zip_code);
          goodForm = false; 
    } 
    else 
    {
          unFlagFormField(document.form1.shipping_zip_code);
    }   
   
    if (document.form1.shipping_phone_number.value == '')
    {
          flagFormField(document.form1.shipping_phone_number);
          goodForm = false; 
    }  
    else 
    {
          unFlagFormField(document.form1.shipping_phone_number);
    }   
     
    if (goodForm)  
    { 
        return true;
    }
    else
    {
        document.getElementById('error_msg').style.visibility = 'visible'; 
        return false;
    }   
}

function flagFormField(formField)
{
	formField.style["border"] = "1px solid red";
	formField.style["background"] = "#FFFCCB";
}

function unFlagFormField(formField)
{
	formField.style["border"] = "1px solid #999";
	formField.style["background"] = "#FFFFFF";
}