﻿var xmlHttp
var m_Price;
var m_Qty;

function numnoenter()
{
    if ((window.event && window.event.keyCode < 48 || window.event.keyCode > 57))
	    window.event.keyCode = 0;
    		
    return !(window.event && window.event.keyCode == 13);
}

var orgprice = 0;
function calc_price(qty)
{
    if (orgprice == 0)
        orgprice = document.getElementById('ctl00_ContentMain_order_price').innerHTML;
        
    document.getElementById('ctl00_ContentMain_order_price').innerHTML = (orgprice * qty).toFixed(2);
}
    
function AddToOrder(ItemID, price, mPrice, ConfigID)
{
    if (ItemID.length==0)
    { 
        return false;
    }
    m_Price = mPrice;
    m_Qty = document.getElementById('tbOrderQty').value;
    xmlHttp = null;
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        document.location.href = 'OrderList.aspx?redirect=1&add=' + ItemID + '&Qty=' + m_Qty + '&Price=' + price + '&Title=' +document.getElementById('lblTitle').innerHTML;
        return false;
    }
        
    document.getElementById('loadingblue').style.display = 'block';
    var url="OrderList.aspx?add=" + ItemID;
    url=url+"&Qty="+m_Qty;
    url=url+"&Price="+price;
    url=url+"&ConfigID="+ConfigID;
    url=url+"&Title="+document.getElementById('ctl00_ContentMain_lblTitle').innerHTML;
    url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=cartAddChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    
    return false;
}

function cartAddChanged() 
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    { 
        
        document.getElementById("ctl00_lblOrderList").innerHTML=xmlHttp.responseText;
        document.getElementById('loadingblue').style.display = 'none';
        document.getElementById('order_added_qty').innerHTML = m_Qty;
        document.getElementById('order_added_price').innerHTML = (m_Price / 100).toFixed(2);
        document.getElementById('order_added_totalprice').innerHTML = (m_Qty * (m_Price / 100)).toFixed(2);
        document.getElementById('order_added').style.display = 'block';
        Timer_Start();
        document.getElementById('mymodulemid').className = 'moduleflash';
        xmlHttp.close;
    }
}

function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

var TimerID = 0;
var Counter = 4;

function UpdateTimer()
{
    if (Counter <= 0)
    {
        Timer_Stop();
        document.getElementById('order_added').style.display = 'none';
        document.getElementById('mymodulemid').className = 'modulemiddle';
    }
    else
    {
        document.getElementById('order_added_closein').innerHTML = '('+Counter+')';
        Counter--;
        TimerID  = setTimeout("UpdateTimer()", 1000);
    }
}

function OrderOk()
{
    document.getElementById('order_added').style.display = 'none';
    document.getElementById('mymodulemid').className = 'modulemiddle';
}

function Timer_Start()
{
    TimerID  = setTimeout("UpdateTimer()", 1000);
    if (TimerID)
        document.getElementById('order_added_closein').innerHTML = '(5)';
}

function Timer_Stop()
{
   if(TimerID)
   {
      clearTimeout(TimerID);
      TimerID = 0;
      Counter = 4;
      document.getElementById('order_added_closein').innerHTML = '';
   }
}

var Stills = false;

function GetStills(ItemID, lnkObj)
{
    if (Stills)
    {
        xmlHttp.abort();
        lnkObj.className = 'nostills';
        document.getElementById('loadingblue').style.display = 'none';
        document.getElementById('stillscontent').innerHTML = '';
        Stills = false;
        return;
    }
    xmlHttp = null;
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert('Your browser doesnt support java XML object, please update');
        return;
    }
    Stills = true;
    document.getElementById('loadingblue').style.display = 'block';
    var url="GetStills.aspx?ItemID=" + ItemID;
    url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=GetStillsChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function GetStillsChanged()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    { 
        document.getElementById('stillscontent').innerHTML = xmlHttp.responseText;
        document.getElementById('btnPicture').className = 'stills';
        document.getElementById('loadingblue').style.display = 'none';
        xmlHttp.close;
    }
}
var orgHeight = 0;
function checkContentHeight()
{
    return;
    if (orgHeight == 0)
    {
        if (document.getElementById('ctl00_pnContent').clientHeight == 0)
            orgHeight = document.getElementById('ctl00_pnContent').offsetHeight;
        else
            orgHeight = document.getElementById('ctl00_pnContent').clientHeight;
    }
    var stillHeight;
    if (document.getElementById('stillscontent').clientHeight == 0)
        stillHeight = document.getElementById('stillscontent').offsetHeight;
    else
        stillHeight = document.getElementById('stillscontent').clientHeight;

    document.getElementById('ctl00_pnContent').style.height = (orgHeight + stillHeight) + 'px';
}

var Show = true;
function ShowStills(obj)
{
    if (Show)
    {
        document.getElementById('ctl00_ContentMain_lblStills').style.display = 'block';
        document.getElementById('btnPicture').className = 'stills';
    }
    else
    {
        document.getElementById('ctl00_ContentMain_lblStills').style.display = 'none';
        document.getElementById('btnPicture').className = 'nostills';
    }
        
    Show = !Show;   
}