var message1 = [];

message1["1"] = "Client-ID NOT Passed";
message1["2"] = "Item code NOT Passed";
message1["3"] = "Amount NOT Passed";
message1["4"] = "Payment Gateway NOT defined";
message1["5"] = "Company-Catalog Record Not Found";
message1["6"] = "Client Company is disabled";
message1["7"] = "Product catalog is disabled";
message1["8"] = "Please configure client service";
message1["9"] = "RFQ is not configured";
message1["10"] = "Session has been expired";
message1["11"] = "Action NOT Defined";
message1["12"] = "Item Not Found";
message1["13"] = "Item is Disabled";
message1["14"] = "Required Parameters Not Passed";
message1["15"] = "Quantity is Not Positive Numeric Value";
message1["16"] = "SiteID could pot provide encryption key";
message1["17"] = "Unable to decrypt the content recieved";
message1["18"] = "Unknown order-id from gateway";
message1["19"] = "Query has already been sent";
message1["20"] = "Template Not found";
message1["21"] = "Undefined action";
message1["22"] = "Problem with cookie-setting";
message1["23"] = "Field Size Exceeding";
message1["24"] = "Incorrect value";
message1["item_already"] = "This Item is already Present in the Enquiry Basket";
message1["itemadded"] = "Your item has been added to the Enquiry Basket";
message1["item_contains"] = "Your Enquiry Basket contains following items";
message1["item_deleted"] = "Selected items has been deleted";
message1["cart_emptied"] = "Your Enquiry Basket has been emptied";
message1["cart_updated"] = "Your Enquiry Basket has been updated";
message1["submit_enquiry"] = "<b>Carefully review the items in your Enquiry Basket below.<br>To send the enquiry please complete the form.<br>All fields marked <font COLOR='RED'>*</font> are mandatory.</b>";



function get_message(messagecode)
{
    if(messagecode == "")   {
        return;
    }
    else    {
        return eval("message1['"+messagecode+"']");
    }
}


function getCartCookie(Name)
{
    var search = Name + "="
    if (document.cookie.length > 0)
    { // if there are any cookies
        offset = document.cookie.indexOf(search)
        if (offset != -1)
        { // if cookie exists
            offset += search.length
            // set index of beginning of value
            end = document.cookie.indexOf(";", offset)
            // set index of end of cookie value
            if (end == -1) end = document.cookie.length
            return unescape(document.cookie.substring(offset, end))
        }
    }

    return "";
}


function setCartCookie(name, value)
{
    expires = new Date();
    expires.setTime (expires.getTime() + 24 * 60 * 60 * 150 * 1000);

    if (value.length > 0)
    document.cookie = name + "=" + escape(value)+ ";"+"expires=" + expires.toGMTString() + ";";
}
function add(iid, pcode, pname, referer)
{
    var myCart;

    if((cookie = getCartCookie("CART_SESSION")) > "")   {
        myCart = eval("(" + cookie + ")");

        var itemsArr = myCart[0];
        var item_exists = 0;
        for(i=0; i< itemsArr.length; i++)
        {
		if((itemsArr[i].item_id == 0) || (iid == 0))
	{
	        if(itemsArr[i].item_name == pname)  {
                myCart[1].message1 = get_message("item_already");
//                 alert(myCart[1].message1);
                item_exists=1;
                break;
            }
	}
	else
	{
            if(itemsArr[i].item_id == iid)  {
                myCart[1].message1 = get_message("item_already");
//                 alert(myCart[1].message1);
                item_exists=1;
                break;
            }
	}
        }

        if(item_exists == 0)    {

            var item = new Object();
            item.item_quantity = '';
            item.item_id = iid;
            item.item_code = pcode;
            item.item_name = pname;
            myCart[0][myCart[0].length]=item;
            myCart[1].message1 = get_message("itemadded");
        }
    }
    else
    {
        var myCart = new Array(2);
        myCart[0] = new Array();
        myCart[1] = new Object();

        var item = new Object();
        item.item_quantity = '';
        item.item_id = iid;
        item.item_code = pcode;
        item.item_name = pname;
        myCart[0][myCart[0].length]=item;
	myCart[1].message1 = get_message("itemadded");
    }

    myCart[1].referer = eval(referer);

    var myCartJSON = myCart.toJSONString();
    setCartCookie("CART_SESSION",myCartJSON);

    return true;
}
function removeitem1(i,frm)
{
    update_cart(frm);
    var myCart;
    if((cookie = getCartCookie("CART_SESSION")) > "")   {
        myCart = eval("(" + cookie + ")");

        var itemsArr = myCart[0];
        myCart[0].splice(i,1);
        myCart[1].message1 = get_message("item_deleted");

        if(itemsArr.length ==0)
        {
            myCart[1].message1 = get_message("cart_emptied");
        }

        var myCartJSON = myCart.toJSONString();
        setCartCookie("CART_SESSION",myCartJSON);
    }

    return true;
}
function removeitem(i)
{
    var myCart;
    if((cookie = getCartCookie("CART_SESSION")) > "")   {
        myCart = eval("(" + cookie + ")");

        var itemsArr = myCart[0];
        myCart[0].splice(i,1);
        myCart[1].message1 = get_message("item_deleted");

        if(itemsArr.length ==0)
        {
            myCart[1].message1 = get_message("cart_emptied");
        }

        var myCartJSON = myCart.toJSONString();
        setCartCookie("CART_SESSION",myCartJSON);
    }

    return true;
}

function update_cart(frm)
{
    var myCart;
    if((cookie = getCartCookie("CART_SESSION")) > "")   {
        myCart = eval("(" + cookie + ")");

        var itemsArr = myCart[0];
        var d=0;

        for(i=0; i< itemsArr.length; i++)
        {
            var v = eval("document."+frm+".quantity_"+i+".value");

            itemsArr[i].item_quantity = v;
	    myCart[1].message1 = get_message("cart_updated");
        }

        if(itemsArr.length == 0)
        {
            myCart[1].message1 = get_message("cart_emptied");
        }

        var myCartJSON = myCart.toJSONString();
        setCartCookie("CART_SESSION",myCartJSON);
    }

    return true;
}

function empty_cart()
{
    var myCart;

    if((cookie = getCartCookie("CART_SESSION")) > "")   {
        myCart = eval("(" + cookie + ")");

        var itemsArr = myCart[0];
        itemsArr.splice(0,itemsArr.length);

        var myCartJSON = myCart.toJSONString();
        setCartCookie("CART_SESSION",myCartJSON);
    }

    return true;
}

function isEmpty()
{
var isEmpty = false;

    if((cookie = getCartCookie("CART_SESSION")) > "")
    {
        var myCart = eval("(" + cookie + ")");
        var p = myCart[0];
        if(p.length > 0)
        {
            isEmpty = true;
        }
        else
        {
            isEmpty = false;
        }
    }
return isEmpty;
}

function checkAndUpdate(frm)
{
	update_cart(frm);
	eval("document."+frm+".action = \"cart.html\"");
	eval("document."+frm+".submit()");
}

function add_more_items(frm)
{
	update_cart(frm);
	if((cookie = getCartCookie("CART_SESSION")) > "")
    	{
		var myCart = eval("(" + cookie + ")");
		if(myCart[1].referer)
		{
			eval("document."+frm+".action = myCart[1].referer");
		}
		else
		{
eval("document."+frm+".action = \"cd-dvd-printing-encryption.html\"");
}
        }
	else
	{
eval("document."+frm+".action = \"cd-dvd-printing-encryption.html\"");
}
	eval("document."+frm+".submit()");
}

function submit_query(frm)
{
        update_cart(frm);
         eval("document."+frm+".action = \"checkout.html\"");
	      eval("document."+frm+".submit()");
}

function RegValue(FieldName) {

if(FieldName.value == 'First Name' || FieldName.value == 'Your Name' )
{
FieldName.value = '';
FieldName.className='txtf';
}
else
{
FieldName.className='txtf';
}
}
function RegValue1(FieldName) {

if(FieldName.value == '')
{
FieldName.value = 'First Name';
FieldName.className='txtfa';
}
else
{
FieldName.className='txtf';
}
}
function RegValue2(FieldName) {

if(FieldName.value == '')
{
FieldName.value = 'Your Name';
FieldName.className='txtfa';
}
else
{
FieldName.className='txtf';
}
}
function RegeValue2(FieldName) {

	if(FieldName.value == 'Last Name')
	{
	FieldName.value = '';
	FieldName.className='txtf';
	}
	else
	{
	FieldName.className='txtf';
	}
}
function RegeValue3(FieldName) {

	if(FieldName.value == '')
	{
	FieldName.value = 'Last Name';
	FieldName.className='txtfa';
	}
}

function AriaValue(FieldName)
{
	if(FieldName.value == 'Area Code')
	{
		FieldName.value = '';
		FieldName.className='txtf';
	}
	else
	{
 		FieldName.className='txtf';
	}
}
function AriaValue1(FieldName)
{
	if(FieldName.value == '')
	{
		FieldName.value = 'Area Code';
		FieldName.className='txtfa';
	}
	else
	{
		FieldName.className='txtf';
	}
}


function PhonValue(FieldName) {
	if(FieldName.value == 'Phone Number')
	{
		FieldName.value = '';
		FieldName.className='txtf';
	}
	else
	{
		FieldName.className='txtf';
	}
}
function PhonValue1(FieldName) {
	if(FieldName.value == '')
	{
		FieldName.value = 'Phone Number';
		FieldName.className='txtfa';
	}
	else
	{
		FieldName.className='txtf';
	}
}

function CellValue(FieldName) {
	if(FieldName.value == 'Mobile / Cell Phone Number' ||  FieldName.value == 'Mobile Number')
	{
	FieldName.value = '';
	FieldName.className='txtf';
	}
}
function CellValue1(FieldName) {
	if(FieldName.value == '')
	{
		FieldName.value = 'Mobile / Cell Phone Number';
		FieldName.className='txtfa';
	}
	else
	{
		FieldName.className='txtf';
	}
}
function CellValue2(FieldName) {
	if(FieldName.value == '')
	{
		FieldName.value = 'Mobile Number';
		FieldName.className='txtfa';
	}
	else
	{
		FieldName.className='txtf';
	}
}
function FaxValue(FieldName) {

	if(FieldName.value == 'Area Code')
{
FieldName.value = '';
FieldName.className='txtf';
}

else if(FieldName.value == '')
{
FieldName.value = 'Area Code';
FieldName.className='txtfa';
}

else
{
FieldName.className='txtf';
}
}


function ContValue(FieldName) {

	if(FieldName.value == 'Your Mobile / Cell Phone')
{
FieldName.value = '';
FieldName.className='txtf';
}

else if(FieldName.value == '')
{
FieldName.value = 'Your Mobile / Cell Phone';
FieldName.className='txtfa';
}

else
{
FieldName.className='txtf';
}
}


function desc1Value(FieldName) {

	if(FieldName.value == 'Your Mobile / Cell Phone')
{
FieldName.value = '';
FieldName.className='txtf';
}

else if(FieldName.value == '')
{
FieldName.value = 'Your Mobile / Cell Phone';
FieldName.className='txtfa';
}

else
{
FieldName.className='txtf';
}
}
