﻿function handleKeyDownEvent(event)
{
    var element = document.getElementById("SeachBox");
    if(element != null)  //in case the textbox is selected and have default text, and mouse is out, clear the textbox value
    {
        var value = element.value;
        if (value.toString() == "Search...")
            element.value = "";
    }
    
    if (!event) 
        var event = window.event;

    var keyCode = (event.which === undefined) ? event.keyCode : event.which;
    if(keyCode == 13) //13 is 'Enter' key stroke
    {
        searchItem();
        
        if (event.stopPropagation)      //for IE
            event.stopPropagation();
        else if(window.event)           //for FF, Chrome, Opera
            window.event.cancelBubble = true;
        
        if (event.preventDefault)
            event.preventDefault();     //for IE
        else 
            event.returnValue = false;  //for FF, Chrome, Opera
    }
}

function searchItem() 
{
    var element = document.getElementById("SeachBox");
    if(element != null)
    {
        var value = element.value;
        if (value != null && value.toString().length > 1 && value.toString() != "Search...")
            window.location = '/Search.aspx?item='+value;
    }
}
function editSearchItem(val)
{
    var element = document.getElementById("SeachBox");
    if(element != null)
    {
        var inputValue = element.value;
        if(val == true)
        {
            if(inputValue.toString().length == 0)
            {
                element.value = "Search...";
                element.style.color = "#AAAAAA";
            }
            else if(inputValue.toString() == "Search...")
                element.style.color = "#AAAAAA";
            else
                element.style.color = "#4B4B4B";
        }
        else
        {
            element.style.color = "#4B4B4B";
            if(inputValue.toString() == "Search...")
                element.value = "";
        }
    }
}
function showSample(objButton,objDiv)
{ 
    if(document.getElementById(objDiv).style.display=="inline")
    {
	    document.getElementById(objDiv).style.display="none";
	    document.getElementById(objButton).value="+";
    }
    else 
    {
	    document.getElementById(objDiv).style.display="inline";
	    document.getElementById(objButton).value="-";	
    }
} 
function showTab(obj1, obj2)
{
    document.getElementById(obj1).className = "selected";
    document.getElementById(obj2).style.display = "block";    
}
function hideTab(obj1, obj2)
{
    document.getElementById(obj1).className = "";
    document.getElementById(obj2).style.display = "none";	
}
function mangle(s1,s2) 
{ 
    location='mailto:'+s2+'@'+s1; 
}
function printPage() 
{
    if (window.print) 
    {
        printpage = confirm('Print this Page?');
        if (printpage) 
            window.print();
   }
}
function checkEmail(email)
{
    if (email.indexOf("@") == -1 ||
        email.indexOf(".") == -1)
    {
        alert("Please use a valid email address");
        return false;
    }
    if 
    (
        (email.indexOf("@gmail.") != -1) ||
        (email.indexOf("@yahoo.") != -1) ||
        (email.indexOf("@hotmail.") != -1) ||
        (email.indexOf("@mailinator.") != -1) ||
        (email.indexOf("@rocketmail.") != -1) ||
        (email.indexOf("@googlemail.") != -1) ||
        (email.indexOf("@free.") != -1) ||
        (email.indexOf("@msn.") != -1) ||
        (email.indexOf("@rediffmail.") != -1) ||
        (email.indexOf("@live.") != -1)
    )
    {
        alert("Please use a corporate email address");
        return false;
    }
    return true;
}



function CartTabHover(productTab, selected)
{
    var tab = document.getElementById(productTab);
    if(tab != null)
    {
        if(selected)
            tab.setAttribute("class", "TabSelected");
        else
            tab.setAttribute("class", "Tab");
            
    }
}

function CartHighlight(productTab)
{
    var mainTab = document.getElementById('ProductTab');
    var accTab = document.getElementById('AccessoriesTab');
    var extraTab = document.getElementById('BundlesTab');
    mainTab.setAttribute("class", "CartTab");
    accTab.setAttribute("class", "CartTab");
    extraTab.setAttribute("class", "CartTab");
    
    var tab = document.getElementById(productTab);
    
    if(tab != null)
    {
        tab.setAttribute("class", "CartTabSelected");    
    }
}

function confirmRemoveProduct(mainProduct) {
    var txt;
    if(mainProduct)
        txt = 'Remove main product from cart? This action will remove all items from cart';
    else
        txt = 'Remove product from cart?';    
    if(confirm(txt)) {
        return true;
    }
    else {
        return false;
    }
}

function changeTitle(dropdownName, textName)
{
    var dropdown     = document.getElementById(dropdownName.toString());
    var otherTextbox = document.getElementById(textName.toString());
    
    if(dropdown == null || otherTextbox == null)
        return;

    var myindex  = dropdown.selectedIndex;
    var SelValue = dropdown.options[myindex].value;
    
    if(SelValue == 'Other')
        otherTextbox.style.visibility = 'visible';
    else
        otherTextbox.style.visibility = 'hidden';
}


