﻿// JScript File

//Funciton for setting the status of all the checkboxes with the name specified by the 
//second parameter on click of the checkbox specified by the first parameter 
function checkAll(obj,itemCheckBoxName)
{
    var arrControls=document.getElementsByTagName("input");
    
        for(var i=0;i<arrControls.length;i++)
        {
            
            
            if(arrControls[i].name.indexOf(itemCheckBoxName)>-1)
            {
                if(obj.checked==true)
                    arrControls[i].checked=true;
                else
                    arrControls[i].checked=false;
            }
        }
}

function checkAll1(obj,itemCheckBoxName,gridName)
{
    var arrControls=document.getElementsByTagName("input");
    
    for(var i=0;i<arrControls.length;i++)
    {
        if(arrControls[i].name.indexOf(itemCheckBoxName)>-1 && arrControls[i].name.indexOf(gridName)>-1)
        {
            if(obj.checked==true)
                arrControls[i].checked=true;
            else
                arrControls[i].checked=false;
        }
    }
}



function unCheck(obj,checkallName)
{
    if(obj.checked==false)
    {
        var arrControls=document.getElementsByTagName("input");
        for(var i=0;i<arrControls.length;i++)
        {
            if(arrControls[i].name.indexOf(checkallName)>-1)
            {
                arrControls[i].checked=false;
                
            }
        }
    }
   
}


function CheckDelete(itemCheckBoxName)
{
    var arrControls=document.getElementsByTagName("input");
    var count=0;
    var recCount=0;
        for(var i=0;i<arrControls.length;i++)
        {
            
            if(arrControls[i].name.indexOf(itemCheckBoxName)>-1)
            {
                recCount=recCount + 1;
                if(arrControls[i].checked==true)
                count=count+1;
            }
        }
        if(recCount==0)
        {
            alert("No records available");
            return false;
        }
        if(count==0 && recCount>0) 
        {
            alert("Please select at least one record to delete.");
            return false;
        }
        else
        {
            if(window.confirm("Are you sure to delete the record(s)?")==false)
                return false;
            else
                return true;   
        }
            
            
    return true;
}



function CheckUplaodfeed(itemCheckBoxName) {
    var arrControls = document.getElementsByTagName("input");
    var count = 0;
    var recCount = 0;
    for (var i = 0; i < arrControls.length; i++) {

        if (arrControls[i].name.indexOf(itemCheckBoxName) > -1) {
            recCount = recCount + 1;
            if (arrControls[i].checked == true)
                count = count + 1;
        }
    }
    if (recCount == 0) {
        alert("No records available");
        return false;
    }
    if (count == 0 && recCount > 0) {
        alert("Please select at least one record to uplaod feed.");
        return false;
    }
    return true;
}
///Author :         Shatabdi Dey
/// Added on Date : 13 May 2008

function CheckCategoryProductLink(itemCheckBoxName)
{
    var arrControls=document.getElementsByTagName("input");
    var count=0;
        for(var i=0;i<arrControls.length;i++)
        {
            
            if(arrControls[i].name.indexOf(itemCheckBoxName)>-1)
            {
                if(arrControls[i].checked==true)
                count=count+1;
            }
        }
        
        if(count==0)
        {
            alert("Please select at least one Category for the Product");
            return false;
        }
        else
        {            
                return true;   
        }
            
            
    return true;
}


function approveRecords(itemCheckBoxName)
{
    var arrControls=document.getElementsByTagName("input");
    var count=0;
    var recCount=0;
    
    for(var i=0;i<arrControls.length;i++)
    {
        
        if(arrControls[i].name.indexOf(itemCheckBoxName)>-1)
        {
            recCount=recCount+ 1;
            if(arrControls[i].checked==true)
            count=count+1;
        }
    }
    
    if(recCount==0)
    {
        alert("No records available.");
        return false;
    }
    if(count==0 && recCount>0)
    {
        alert("Please select at least one record.");
        return false;
    }
    else
    {
        if(window.confirm("Are you sure to approve these records?")==false)
            return false;
        else
            return true;   
    }
            
            
    return true;
}

function rejectRecords(itemCheckBoxName)
{
    var arrControls=document.getElementsByTagName("input");
    var count=0;
    var recCount=0;
        for(var i=0;i<arrControls.length;i++)
        {
            
            if(arrControls[i].name.indexOf(itemCheckBoxName)>-1)
            {
                recCount=recCount+ 1;
                if(arrControls[i].checked==true)
                count=count+1;
            }
        }
        
        if(recCount==0)
        {
            alert("No records available.");
            return false;
        }
        if(count==0 && recCount>0)
        {
            alert("Please select at least one record.");
            return false;
        }
        else
        {
            if(window.confirm("Are you sure to reject these record(s)?")==false)
                return false;
            else
                return true;   
        }
            
            
    return true;
}


function activateRecords(itemCheckBoxName)
{
    var arrControls=document.getElementsByTagName("input");
    var count=0;
    var recCount=0;
    
    for(var i=0;i<arrControls.length;i++)
    {
        
        if(arrControls[i].name.indexOf(itemCheckBoxName)>-1)
        {
            recCount=recCount+ 1;
            if(arrControls[i].checked==true)
            count=count+1;
        }
    }
    
    if(recCount==0)
    {
        alert("No records available.");
        return false;
    }
    if(count==0 && recCount>0)
    {
        alert("Please select at least one record.");
        return false;
    }
    else
    {
        if(window.confirm("Are you sure to activate these records?")==false)
            return false;
        else
            return true;   
    }
            
            
    return true;
}

function deactivateRecords(itemCheckBoxName)
{
    var arrControls=document.getElementsByTagName("input");
    var count=0;
    var recCount=0;
    
    for(var i=0;i<arrControls.length;i++)
    {
        
        if(arrControls[i].name.indexOf(itemCheckBoxName)>-1)
        {
            recCount=recCount+ 1;
            if(arrControls[i].checked==true)
            count=count+1;
        }
    }
    
    if(recCount==0)
    {
        alert("No records available.");
        return false;
    }
    if(count==0 && recCount>0)
    {
        alert("Please select at least one record.");
        return false;
    }
    else
    {
        if(window.confirm("Are you sure to inactivate these records?")==false)
            return false;
        else
            return true;   
    }
            
            
    return true;
}

function setInStock(itemCheckBoxName)
{
    var arrControls=document.getElementsByTagName("input");
    var count=0;
    var recCount=0;
    
    for(var i=0;i<arrControls.length;i++)
    {
        
        if(arrControls[i].name.indexOf(itemCheckBoxName)>-1)
        {
            recCount=recCount+ 1;
            if(arrControls[i].checked==true)
            count=count+1;
        }
    }    
    if(recCount==0)
    {
        alert("No records available.");
        return false;
    }
    if(count==0 && recCount>0)
    {
        alert("Please select at least one record.");
        return false;
    }
    else
    {
        if(window.confirm("Are you sure to set the status of selected products to In Stock?")==false)
            return false;
        else
            return true;   
    }
            
            
    return true;
}

function setOutOfStock(itemCheckBoxName)
{
    var arrControls=document.getElementsByTagName("input");
    var count=0;
    var recCount=0;
    
    for(var i=0;i<arrControls.length;i++)
    {
        
        if(arrControls[i].name.indexOf(itemCheckBoxName)>-1)
        {
            recCount=recCount+ 1;
            if(arrControls[i].checked==true)
            count=count+1;
        }
    }
    
    if(recCount==0)
    {
        alert("No records available.");
        return false;
    }
    if(count==0 && recCount>0)
    {
        alert("Please select at least one record.");
        return false;
    }
    else
    {
        if(window.confirm("Are you sure to set the status of selected products to Out Of Stock?")==false)
            return false;
        else
            return true;   
    }
            
            
    return true;
}




function CheckStatusModified(itemCheckBoxName,msg,confirmMsg)
{
    
    var arrControls=document.getElementsByTagName("input");
    var count=0;
        for(var i=0;i<arrControls.length;i++)
        {
            
            if(arrControls[i].name.indexOf(itemCheckBoxName)>-1)
            {
                if(arrControls[i].checked==true)
                count=count+1;
            }
        }
        
        if(count==0)
        {
            alert(msg);
            return false;
        }
        else
        {
            if(window.confirm(confirmMsg)==false)
                return false;
            else
                return true;   
        }
            
            
    return true;
}


function ChangePrice(obj) {
    if(obj.selectedIndex!=0)
    {
        var objlblProPrice=document.getElementById("ctl00_contentWorkingArea_lblProPriceInCurrency");
        var objlblListPrice=document.getElementById("ctl00_contentWorkingArea_lblListPriceInCurrency");
        var originalProPrice=document.getElementById("ctl00_contentWorkingArea_hdnProPrice").value;
        var originalListPrice = document.getElementById("ctl00_contentWorkingArea_hdnListProPrice").value;
        var originalushandle = document.getElementById("ctl00_contentWorkingArea_lblushandle");

        
        var currencyParts=obj.options[obj.selectedIndex].value.split('~');
        var newProPrice= "(~" + currencyParts[0] +  "&nbsp;" + Math.round((originalProPrice * currencyParts[1]) * 100)/100 + ")";
        var newListPrice = "(~" + currencyParts[0] + "&nbsp;" + Math.round((originalListPrice * currencyParts[1]) * 100) / 100 + ")";

        if (objlblProPrice != null) 
        {
        	objlblProPrice.innerHTML = newProPrice;
        }
        if (objlblListPrice != null) 
        {
        	objlblListPrice.innerHTML = newListPrice;
        }
        

        
        //originalushandle.innerHTML = "Please note, this transactions is handled in U.S. Dollars. Prices in other currencies are shown for reference only.";
        originalushandle.innerHTML = "Please note, this transactions is handled in <b>" + document.getElementById("ctl00_contentWorkingArea_htxtcurr").value + "</b>. Prices in other currencies are shown for reference only.";


        var objlblWPrice = document.getElementById("ctl00_contentWorkingArea_lblwholepriceInCurrency");
        var originalwprice = document.getElementById("ctl00_contentWorkingArea_hwprice").value;
        var newWPrice = "(~" + currencyParts[0] + "&nbsp;" + Math.round((originalwprice * currencyParts[1]) * 100) / 100 + ")";
        if (objlblWPrice != null) 
        {
            objlblWPrice.innerHTML = newWPrice;    
        }
        
        
//      var objLabel=document.getElementById("ctl00_contentWorkingArea_lblProPrice");
//      var originalPrice=document.getElementById("ctl00_contentWorkingArea_hdnProPrice").value;
//      var currencyParts=obj.options[obj.selectedIndex].value.split('~');
//      var newPrice= "<b>" + currencyParts[0] + "</b>" + "&nbsp;" + Math.round((originalPrice * currencyParts[1]) * 100)/100;
        //      objLabel.innerHTML=newPrice;

        ajaxFunction(obj.options[obj.selectedIndex].value);
    }
}



function ajaxFunction(cid) {
    
    var xmlHttp;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e) {
        // Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                alert("Your browser does not support AJAX!");
                return false;
            }
        }
    }
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            //alert(xmlHttp.responseText);
            //document.getElementById("ctl00_ContentPlaceHolder1_div2").innerHTML = xmlHttp.responseText;
        }
    }
    xmlHttp.open("GET", "currencyid.aspx?cid=" + cid, true);
    xmlHttp.send(null);
}



function ChangePage(pageToShow,pageToHide,mode)
{
    
    document.getElementById("ctl00_contentWorkingArea_" + pageToShow).style.display="";
    document.getElementById("ctl00_contentWorkingArea_" + pageToHide).style.display="none";   
    if(mode=="Next")
    {
        document.getElementById("ctl00_txtSearch").focus();
        document.getElementById("ctl00_contentWorkingArea_ddlCardType").focus();
    }
    else
    {
        document.getElementById("ctl00_txtSearch").focus();
        document.getElementById("ctl00_contentWorkingArea_txtBillingAddress").focus();        
    }
    return false; 
}


function showHideCreditCardDetails(obj,divId)
{
    if(obj.id.indexOf('optCC')>-1)
        document.getElementById(divId).style.display='';
    else if(obj.id.indexOf('optMO')>-1 || obj.id.indexOf('OptC')>-1)
    {
        document.getElementById(divId).style.display='none';
    }
}

function showHidePayOptions(obj,divPayById,divCreditCardDetails,divOtherInfo)
{
    if(obj.id.indexOf('optPay')>-1)
    {
        document.getElementById(divId).style.display='';
        document.getElementById(divCreditCardDetails).style.display='';
        document.getElementById(divOtherInfo).style.display='';
    }
    else if(obj.id.indexOf('optVoucher')>-1) 
    {
        document.getElementById(divId).style.display='none';
        document.getElementById(divCreditCardDetails).style.display='none';
        document.getElementById(divOtherInfo).style.display='none';
        
    }
}

function copyBillingAddressToShippingAddress(oChk)
{
    if (oChk.checked)
    {
        document.getElementById('ctl00_contentWorkingArea_txtShipAddress').value=document.getElementById('ctl00_contentWorkingArea_txtBillAddress').value
        document.getElementById('ctl00_contentWorkingArea_ddlShipCountry').selectedIndex=document.getElementById('ctl00_contentWorkingArea_ddlBillCountry').selectedIndex
        document.getElementById('ctl00_contentWorkingArea_txtShipState').value=document.getElementById('ctl00_contentWorkingArea_txtBillState').value
        document.getElementById('ctl00_contentWorkingArea_txtShipCity').value=document.getElementById('ctl00_contentWorkingArea_txtBillCity').value
        document.getElementById('ctl00_contentWorkingArea_txtShipZipCode').value=document.getElementById('ctl00_contentWorkingArea_txtBillZipCode').value
        document.getElementById('ctl00_contentWorkingArea_txtShipPhone').value=document.getElementById('ctl00_contentWorkingArea_txtBillPhone').value
        document.getElementById('ctl00_contentWorkingArea_txtShipFax').value=document.getElementById('ctl00_contentWorkingArea_txtBillFax').value
    }
    else
    {
        document.getElementById('ctl00_contentWorkingArea_txtShipAddress').value="";
        document.getElementById('ctl00_contentWorkingArea_ddlShipCountry').selectedIndex=0;
        document.getElementById('ctl00_contentWorkingArea_txtShipState').value="";
        document.getElementById('ctl00_contentWorkingArea_txtShipCity').value="";
        document.getElementById('ctl00_contentWorkingArea_txtShipZipCode').value="";
        document.getElementById('ctl00_contentWorkingArea_txtShipPhone').value="";
        document.getElementById('ctl00_contentWorkingArea_txtShipFax').value="";
    }
}


function OnPwdYESNO(txtCntrl,rdoCntrl)
{
    var _obj = document.getElementById(txtCntrl)
    if (_obj)
    {
        _obj = document.getElementById(rdoCntrl)
        _obj.checked=true;
    }
    return true;
}


function showConfirmOnCheckOut()
{
    var result=window.confirm("Are you sure to check out!");
    if(result==true)
        return true;
    else
        return false;
}

function showConfirmOnDelete()
{
    var result=window.confirm("Are you sure to delete!");
    if(result==true)
        return true;
    else
        return false;
}


