﻿function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
var http_request = false;
function ProcessStaticUpdates(url, parameters) 
{
  http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
     http_request = new XMLHttpRequest();
     if (http_request.overrideMimeType) {
        http_request.overrideMimeType('text/xml');
     }
  } else if (window.ActiveXObject) { // IE
     try {
        http_request = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
        try {
           http_request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
     }
  }
  if (!http_request) {
     alert('Cannot create XMLHTTP instance');
     return false;
  }
  http_request.onreadystatechange = onreturnFromProcessStaticUpdates;
  http_request.open('GET', url + parameters, true);
  http_request.send(null);
}

function onreturnFromProcessStaticUpdates() 
{
    if (http_request.readyState == 4) 
    {
        if (http_request.status == 200) 
        {
            var htmlPos, str;            
            htmlPos = http_request.responseText.indexOf('<html>');
            str = http_request.responseText.substr(0,htmlPos);
            var temp = new Array();
            temp = str.split(';');
            document.getElementById("fntShoppingCartItems").innerHTML = '&nbsp;&nbsp;&nbsp;&nbsp;' + temp[0];
            document.getElementById("fntShoppingCartTotal").innerHTML = '&nbsp;&nbsp;&nbsp;' + temp[1];
           // document.getElementById("fntCustomerName").innerHTML = temp[2] + '&nbsp;';
           // document.getElementById("fntLogOutBtn").innerHTML = temp[3];
            //document.getElementById("ctl00_fntLastViewedItems").innerHTML = temp[4];
            if(temp[5] != null)
                if(temp[5] == "refresh")
                    window.location.href=window.location.href; 
           // if(temp[0] != "0 items")
           //     document.getElementById("fntCkOut").innerHTML = "<a href='http://localhost:4730/classic/ShoppingCart/'>Proceed to Checkout</a>";
        }
        else 
        {
            alert('There was a problem with the request.');
        }
    }
}
function init()
{
//    var URL;
//    var index;
//    if(!document.URL.toLowerCase().match("localhost"))
//    {
//        if((document.URL.toLowerCase().match("/member/")) || (document.URL.toLowerCase().match("/shoppingcart/")))
//        {
//            if(document.URL.toLowerCase().match("/member/"))
//            {
//                index = document.URL.toLowerCase().lastIndexOf("/member/");
//                URL = document.URL.substr(index, document.URL.length)
//                URL = 'https://secure.MySecurityCameraShop.com' + URL;
//                //alert(URL);
//            }
//            if(document.URL.toLowerCase().match("/shoppingcart/"))
//            {
//                index = document.URL.toLowerCase().lastIndexOf("/shoppingcart/");
//                URL = document.URL.substr(index, document.URL.length)
//                URL = 'https://secure.MySecurityCameraShop.com' + URL;
//                //alert(URL);
//            }
//            if(document.URL.toLowerCase().match("http://"))
//            {
//                window.location.href = URL;
//                //alert('secure');
//            }
//        }
//        else
//        {
//            if(document.URL.toLowerCase().match("https://"))
//            {
//                index = document.URL.toLowerCase().lastIndexOf("MySecurityCameraShop.com");
//                URL = document.URL.substr(index, document.URL.length)
//                URL = 'http://www.' + URL;
//                window.location.href = URL;
//            }
//        }
//            
//    }
}
function btnBuyClick(IMC)
{
    if(document.getElementById('ctl00_Content_ddlItemRelated') == null)
        location.href='http://www.MySecurityCameraShop.com/shoppingcart/default.aspx?IMC=' + IMC;
    else
    {
        var array = new Array();
        array = document.getElementById('ctl00_Content_ddlItemRelated').value.split(';');
        location.href='http://www.MySecurityCameraShop.com/shoppingcart/default.aspx?IMC=' + array[0];
    }
}
function redirect(URL)
{
    location.href = URL;
}
function redirectShoppingCart()
{
    //location.href = 'https://secure.MySecurityCameraShop.com/shoppingcart/';
    location.href = 'http://www.MySecurityCameraShop.com/shoppingcart/';
}
function redirectMember()
{
    //location.href = 'https://secure.MySecurityCameraShop.com/Member/';
    location.href = 'http://www.MySecurityCameraShop.com/Member/';
}

function updatePrice(ddlValue)
{
    var array = new Array();
    array = ddlValue.split(';');
    var array2 = new Array();
    array2 = array[1].split('.');
    var array4 = new Array();
    var array5 = new Array();
    var array6 = new Array();
    
    document.getElementById('ctl00_Content_lblPriceInt').innerHTML = '$'+array2[0];
    document.getElementById('ctl00_Content_lblPriceDes').innerHTML = array2[1].substr(0,2);
    document.getElementById('smallImg').src = 'http://www.MySecurityCameraShop.com/Images/Items_Thumbnail/' + array[2];
    document.getElementById('lbImg').href = '';
    document.getElementById('lbImg').href = 'http://www.MySecurityCameraShop.com/Images/Items/' + array[2];
    document.getElementById('ctl00_Content_lblIMC').innerHTML = array[3];
    array4 = array[4].split('.');
    document.getElementById('ctl00_Content_lblRegularPrice').innerHTML = '$' + array4[0] + '.' + array4[1].substring(0,2);
    var priceDiff = array[4] - array[1];
    array6 = priceDiff.toString().split('.');
    priveDiff = array6[0] + '.' + ((array6[1] == null)? '00' : array6[1]);
    var priceDiffPrecent = (priceDiff / array[4]) * 100;
    array5 = priceDiffPrecent.toString().split('.');
    document.getElementById('ctl00_Content_lblYouSave').innerHTML = '$' + array6[0] + '.' + ((array6[1] == null)? '00' : array6[1]) + ' (' + array5[0] + '%)';
    document.getElementById('ctl00_Content_lblName2').innerHTML = array[5];
    document.getElementById('ctl00_Content_lblName').innerHTML = array[5];
    document.getElementById('spnBcItemName').innerHTML = array[5];
    

}
init();
MM_preloadImages();

