﻿
var divHideTimerId;

function ShowProductAddButton(bId) {
    document.getElementById(bId).style.visibility = 'visible';
}

function HideProductAddButton(bId) {
    document.getElementById(bId).style.visibility = 'hidden';
}

function ConfirmItemDelete(itemName)
{
    if (confirm('Do you wish to remove ' + itemName + ' from your shopping cart?'))
        return true
    return false;
}

function RedirectAfterSendRequest(urlVal, id) 
{
    document.getElementById(id).style.visibility = 'visible';
    setTimeout("RedirectPage('" + urlVal + "');", 5000);
}

function RedirectPage(urlVal) {
    self.parent.location.href = urlVal;
}
 
function DisplaySummaryAfterAdding(pname, id) {
    ShowDivControl(id);
    divHideTimerId = setTimeout("HideDivControl('" + id + "');", 3000);
}

function DisplaySummaryOnLoad(id) {
    ShowDivControl(id);
    divHideTimerId = setTimeout("HideDivControl('" + id + "');", 1500);
}

function RedirectToReviewSubmit() {
    clearTimeout(divHideTimerId);
    return true;
}

function HideDivControl(id) {
    clearTimeout(divHideTimerId);
    var cdiv = document.getElementById(id);
    cdiv.style.visibility = 'hidden';
    return false;
}

function ShowDivControl(id) {
    clearTimeout(divHideTimerId);
    var cdiv = document.getElementById(id);
    cdiv.style.visibility = 'visible';
    return false;
}

function CartOnMouseOut(id) {
    divHideTimerId = setTimeout("HideDivControl('" + id + "');", 1500);
}

function CartOnMouseOver(id) {
    clearTimeout(divHideTimerId);
    ShowDivControl(id);
}

function CartOnBlur(id) {
    clearTimeout(divHideTimerId);
    HideDivControl(id);
}

function ValidateCustomerInfo(id1, id2, id3, id4, id5) 
{
    document.getElementById(id1).className = 'textbox';
    document.getElementById(id2).className = 'textbox';
    document.getElementById(id3).className = 'textbox';
    document.getElementById(id4).className = 'textbox';
    document.getElementById(id5).className = 'textbox';
    
    if(trim(document.getElementById(id1).value) == '') {
        document.getElementById(id1).className = 'blanktextbox'; 
        alert('Enter Name'); document.getElementById(id1).focus();
        return false; 
    }
    
    if (trim(document.getElementById(id2).value) == '') {
        document.getElementById(id2).className = 'blanktextbox';
        alert('Enter Company Name'); document.getElementById(id2).focus();
        return false;
    }

    if (trim(document.getElementById(id3).value) == '') {
        document.getElementById(id3).className = 'blanktextbox';
        alert('Enter Address'); document.getElementById(id3).focus();
        return false;
    }
    
    if (trim(document.getElementById(id4).value) == '') {
        document.getElementById(id4).className = 'blanktextbox'; 
        alert('Enter Phone Number'); document.getElementById(id4).focus();
        return false;
    }
    if (trim(document.getElementById(id5).value) == '') {
        document.getElementById(id5).className = 'blanktextbox'; 
        alert('Enter E-mail'); document.getElementById(id5).focus();
        return false;
    }

    var hasAT = false, hasDOT = false;
    var cAT = 0;
    var cusemail = trim(document.getElementById(id5).value);
    for (var i = 0; i < cusemail.length; i++) 
    {
        if (cusemail.charAt(i) == '@')
        { hasAT = true; cAT++; }
        if (hasAT == true && cusemail.charAt(i) == '.')
        { hasDOT = true; }
    }
    if (hasAT == false || hasDOT == false || cAT != 1) {
        document.getElementById(id5).className = 'blanktextbox';
        alert('Enter valid E-mail'); document.getElementById(id5).focus();
        return false;
     }
    
    return true;
}

function trim(str) 
{
    str = str.replace(/^\s+/, '');
    for( var i = str.length-1; i > 0; i-- ) 
    {
        if( /\S/.test( str[i] ) ) 
        {
            str = str.substring( 0, i+1 );
            break;
        }
    }
    return str;
}
