﻿function topMenuLinkMouseOver(link)
{
    //alert("Over")
    document.getElementById(link).style.color = "#E73811";
}

function topMenuLinkMouseOut(link)
{
    //alert("Out");
    document.getElementById(link).style.color = "#8e8e8e";
}


/// 
function popImage(imageURL,imageTitle)
{ 
    // Script Source: CodeLifter.com 
    // Copyright 2003 
    // Do not remove this notice. 

    // SETUPS: 
    // =============================== 

    // Set the horizontal and vertical position for the popup 

    PositionX = 100; 
    PositionY = 100; 

    // Set these value approximately 20 pixels greater than the 
    // size of the largest image to be used (needed for Netscape) 

    defaultWidth = 500; 
    defaultHeight = 500; 

    // Set autoclose true to have the window close automatically 
    // Set autoclose false to allow multiple popup windows 

    var AutoClose = true; 

    // Do not edit below this line... 
    // ================================ 
        if (parseInt(navigator.appVersion.charAt(0))>=4)
        { 
            var isNN=(navigator.appName=="Netscape")?1:0; 
            var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;} 
            var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY; 
            var optIE='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY; 

            if (isNN){imgWin=window.open('about:blank','',optNN);} 
            if (isIE){imgWin=window.open('about:blank','',optIE);} 
            with (imgWin.document){ 
            writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>'); 
            writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){'); 
            writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}'); 
            writeln('function reSizeToImage(){');
            writeln('if (isIE){');
            writeln('window.resizeTo(100,100);'); 
            writeln('width=document.images[0].width;'); 
            writeln('height=100-(document.body.clientHeight-document.images[0].height);'); 
            writeln('window.resizeTo(width,height);}');
            writeln('if (isNN){'); 
            writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}'); 
            
            writeln('function doTitle(){document.title="'+imageTitle+'";}');
            
            writeln('function buttonalert(event)');
            writeln('{');
            writeln('    var button; ');            
            writeln('    if (event.which == null)');
            writeln('       button = (event.button < 2) ? "LEFT" : ((event.button == 4) ? "MIDDLE" : "RIGHT");');
            writeln('    else');
            writeln('       button= (event.which < 2) ? "LEFT" : ((event.which == 2) ? "MIDDLE" : "RIGHT");');
            writeln('    ');
            writeln('    if(button=="RIGHT")');
            writeln('    {');
            writeln('        event.returnValue= false;');
            writeln('        document.oncontextmenu=function(){ return dont(event)}');
            writeln('        return false;');
            writeln('    } ');
            writeln('}');
            
            writeln('function dont(event)');
            writeln('{   ');
            writeln('    if (event.preventDefault)');
            writeln('    {      ');
            writeln('        event.preventDefault();');
            writeln('    }');
            writeln('    else');
            writeln('    {      ');  
            writeln('        event.returnValue= false;');
            writeln('    }');
            writeln('    return false;');
            writeln('}');
            
            writeln('</sc'+'ript>'); 
            if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onmousedown="javascript:return buttonalert(event);"  onload="reSizeToImage();doTitle();self.focus()">') 
            else writeln('</head><body bgcolor=000000 scroll="no" onmousedown="javascript:return buttonalert(event);" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">'); 
            writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
            close(); 
        }
} 
/*============================================================================
June 29, 2006: NAFI
Global variables
============================================================================*/
var defaultAddress = "";
var defaultUrl = "";
var defaultUrlParam = "";
var winHeight = "";
var winWidth = "";

/*============================================================================
May 26, 2006: NAFI
Functions to handle control initializations
============================================================================*/


function SetDivHeight()
{
var valu;
try{
 var obj1 = document.getElementById("Defaultbody");
 var objDiv = document.getElementById("divGrid");
 valu = obj1.offsetHeight;
// objDiv.style.height = "250";
    objDiv.style.height = valu - 50;
    //alert(valu);
    return;
 
 }
 catch(Ex)
 {}
 return;
}
function BodyOnLoad()
{       
    var oType = queryString('oType');
    
    if(!IsDialog(oType)){
        // init xgrid
      //  XGridOnLoad(); // select first row of grid
    
        // init xtab
        XTabOnload(); // select first tab of tab page
    }
    
    // init form 
    //FormOnLoad();    
}

function FormOnLoad()
{   
    var oType = queryString('oType');
     
    var hfRfp = window.document.getElementById('ctl00$hfRfp');
    if(hfRfp != null && hfRfp.value != ""){
        // dialog box has different way of accessing parent!
        if(IsDialog(oType)){
            var da = window.dialogArguments;
            da.dialogRefreshParent(true);
        }
        else{
            if(!window.opener.closed)
                window.opener.location = window.opener.location;
        }
        hfRfp.value = "";        
    }

    var hfMsg = window.document.getElementById("ctl00$hfMsg");
    if(hfMsg != null && hfMsg.value != ""){
        alert(hfMsg.value);
        hfMsg.value = "";
    }

    // applicable to only dialog window close, others please use CloseWindow()
    var hfCwin = window.document.getElementById("ctl00$hfCwin");
    if(hfCwin != null && hfCwin.value != ""){
        window.close();
    }    
}

function ValidationSummaryHeight(itemCount){
    itemCount /= 2;
    var height = (16*itemCount);
    height += (itemCount == 0)? 0 : 10;
    return height;
}

// cancel changes on add/edit/view page
function CancelForm()
{ 
    var yn = window.confirm("This will cancel all the changes. Do you want to continue?");
    if( yn == 1){
        window.document.aspnetForm.reset();
    }
}

function DeleteRecord()
{
    var yn = window.confirm("This will delete selected record(s). Do you want to continue?");
     if( yn == 1){
        __doPostBack('ctl00$mnuPageToolbar','Delete');
    }
}

function DeletePage()
{
    var yn = window.confirm("This will delete the selected Page. Do you want to continue?");
     if( yn == 1){
        __doPostBack('ctl00$mnuPageToolbar','Delete Page');
    }
}

function DeleteSubPage()
{
    var yn = window.confirm("This will delete the selected Sub Page. Do you want to continue?");
     if( yn == 1){
        __doPostBack('ctl00$mnuPageToolbar','Delete Sub Page');
    }
}

function CancelRecord()
{
    var yn = window.confirm("This will cancel selected record(s). Do you want to continue?");
     if( yn == 1){
        __doPostBack('ctl00$mnuPageToolbar','Delete');
    }
}

function DeleteRecordClient()
{
    var yn = window.confirm("This will delete selected record(s). Do you want to continue?");
    if( yn == 1){
       return true;
    }
    return false;
}

function AcceptPayment()
{
    var yn = window.confirm("This will accept selected payment(s). Do you want to continue?");
    if( yn == 1){
        __doPostBack('ctl00$mnuPageToolbar','Save');
    }   
}
function ValidateOrderPaymentFields()
{
    //debugger;
    var yn = window.confirm("This will accept selected payment(s). Do you want to continue?");
    if(yn == 1)
    {
        var grid = document.getElementById("ctl00_AdminContentPlaceHolder_gvOrderPaymentStatus");
        
        var rows = grid.getElementsByTagName("TR");
        var cells;
        var chkBox;
        var errorMsg = "";
        for(var i = 1; i < rows.length; i++)
        {
            cells = rows[i].getElementsByTagName("input");
            
            if(cells[0].checked == true)
            {
                if(cells[1].value == "")
                {
                    errorMsg += "Receipt No\n";
                }
                if(cells[2].value == "")
                {
                    errorMsg += "Receipt Date\n";
                }
                if(cells[3].value == "")
                {
                    errorMsg += "Bank Name\n";
                }
//                if(cells[4].value == "")
//                {
//                    errorMsg += "Branch\n";
//                }
                
                if( errorMsg != "" )
                {
                    alert("Please enter values in following required fields\n\n" + errorMsg);
                    return;
                }
            }
            
        }
        
        __doPostBack('ctl00$mnuPageToolbar','Save');
    }
    
    //return false;
    
}


function PrintDocument(strid)
{
try
{
 alert('Hi i am here');
 var prtContent = document.getElementById(strid);
 var WinPrint = window.open('','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0,resizable=yes');
 WinPrint.document.write("<link type=\"text/css\" rel=\"stylesheet\" href=\"../App_Themes/Default/tdstyle.css\" />");
// var obj = document.getElementById("ctl00_cphPage_hfIsPrint");
// var ContentValue = prtContent.innerHTML;
// var objdf= document.getElementById("ctl00$cphPage$HiddenField1") ;
// var valobj = Number(objdv.value) -1;
// var objdi = "ctl00_cphPage_gdvAccount_" + objdf.value.toString();
// obj.value = "1";
 WinPrint.document.write(prtContent.innerHTML);
 WinPrint.document.close();
 WinPrint.focus();
 WinPrint.print();
 WinPrint.close();
// obj.value = "0";
 }
 catch(ex)
 {}
 //prtContent.innerHTML=strOldOne;
}

function DeleteSingleRecord()
{
    var yn = window.confirm("This record will be deleted. Do you want to continue?");
    if( yn == 1){
        __doPostBack('ctl00$mnuPageToolbar','Delete');
    }
}

function GridSelectAll(thisBox, gridControl, checkBoxColIndex, controlIndex)
 { 
   xState=thisBox.checked;
   
    var rows = gridControl.getElementsByTagName("TR");
    for(i = 0; i < rows.length; i++)
    {
        var col = rows[i].getElementsByTagName("TD")[checkBoxColIndex];
        if(col != undefined)
        {
            var checkBox = col.getElementsByTagName("Input")[controlIndex];
            if(checkBox != undefined)
            {
                checkBox.checked = xState;
            }
        }
    }
 }

function SelectUnselectAll(thisBox, gridControlId, checkBoxColIndex, controlIndex)
 {     
    gridControl = document.getElementById(gridControlId);
    
   xState=thisBox.checked;
   
    var rows = gridControl.getElementsByTagName("TR");
    for(i = 0; i < rows.length; i++)
    {
        var col = rows[i].getElementsByTagName("TD")[checkBoxColIndex];
        if(col != undefined)
        {
            var checkBox = col.getElementsByTagName("Input")[controlIndex];
            if(checkBox != undefined)
            {
                checkBox.checked = xState;
            }
        }
    }
 }

 function GridSelectAllOldMethod(spanChk){

   // Added as ASPX uses SPAN for checkbox
   var oItem = spanChk.children;
   var theBox= (spanChk.type=="checkbox") ? 
        spanChk : spanChk.children.item[0];
   xState=theBox.checked;
   elm=theBox.form.elements;

   for(i=0;i<elm.length;i++)
     if(elm[i].type=="checkbox" && 
              elm[i].id!=theBox.id)
     {
       //elm[i].click();
       if(elm[i].checked!=xState)
         elm[i].click();
       //elm[i].checked=xState;
     }
 }
 
function GridSelectAllColumn(spanChk, chkName){

   // Added as ASPX uses SPAN for checkbox
   var oItem = spanChk.children;
   var theBox= (spanChk.type=="checkbox") ? 
        spanChk : spanChk.children.item[0];
   xState=theBox.checked;
   elm=theBox.form.elements;

   for(i=0;i<elm.length;i++)
     if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
     {
        if(elm[i].id.indexOf(chkName) > -1){
            if(elm[i].checked != xState){
            elm[i].click();
            }
        }
     }
 }

function GridSetPermission(spanChk){

   // Added as ASPX uses SPAN for checkbox
   var oItem = spanChk.children;
   var theBox= (spanChk.type=="checkbox") ? 
        spanChk : spanChk.children.item[0];
   var xState=theBox.checked;
   var baseId = theBox.id.substring(0, theBox.id.lastIndexOf("_")+1 );
   var viewBox = document.getElementById(baseId + "chkView");
   var addBox = document.getElementById(baseId + "chkAdd");
   var deleteBox = document.getElementById(baseId + "chkDelete");
   var updateBox = document.getElementById(baseId + "chkUpdate");
   
   if(theBox.id.indexOf("chkView") > -1){
        if(!theBox.checked){
            addBox.checked = false;
            updateBox.checked = false;
            deleteBox.checked = false;
        }
   }else{
        if(theBox.checked)
            viewBox.checked = true;
   }
 }

function SetSelectedIds(gridControl, checkBoxControl, checkBoxColIndex, controlIndex, hiddenFieldControl)
{
    hiddenFieldControl.value = "";
    var rows = gridControl.getElementsByTagName("TR");
    for(i = 0; i < rows.length; i++)
    {
        var col = rows[i].getElementsByTagName("TD")[checkBoxColIndex];
        if(col != undefined)
        {
            var checkBox = col.getElementsByTagName("Input")[controlIndex];
            if(checkBox != undefined)
            {
                if(checkBox.checked == true)
                {
                    if(hiddenFieldControl.value != "")
                    {
                        hiddenFieldControl.value = hiddenFieldControl.value+",";                        
                    }
                    hiddenFieldControl.value = hiddenFieldControl.value+checkBox.value;                        
                }
            }
        }
    }
}

function SetSelectedItems(gridControlId, checkBoxControl, checkBoxColIndex, controlIndex, hiddenFieldId)
{   
    gridControl = document.getElementById(gridControlId);
    hiddenFieldControl = document.getElementById(hiddenFieldId);
    hiddenFieldControl.value = "";
    var rows = gridControl.getElementsByTagName("TR");
    for(i = 0; i < rows.length; i++)
    {
        var col = rows[i].getElementsByTagName("TD")[checkBoxColIndex];
        if(col != undefined)
        {
            var checkBox = col.getElementsByTagName("Input")[controlIndex];
            if(checkBox != undefined)
            {
                if(checkBox.checked == true)
                {
                    if(hiddenFieldControl.value != "")
                    {
                        hiddenFieldControl.value = hiddenFieldControl.value+",";                        
                    }
                    hiddenFieldControl.value = hiddenFieldControl.value+checkBox.value;                        
                }
            }
        }
    }
}

function NoEntry(e, textControl)
{
    if (typeof e == 'undefined') 
    {
        e = window.event;        
    }
    
    var unicode = e.charCode ? e.charCode : e.keyCode;
    
    if (unicode==9) //allows tab
    {
        textControl.value = "";
        return true;
    }
    if (unicode==8) //allows backspace
    {
        textControl.value = "";
        return false;
    }
    if (unicode != 8)
    {        
        alert("Please use the Calendar button.");
        textControl.value = "";
        return false;
    }
}    

// window close button on title tool bar
function CloseWindow()
{
    window.close();
}

function OpenWindow(pageUrl, oType, oId, pType, pId)
{
    var url = pageUrl + '?oType=' + oType + '&oId=' + oId + '&pType=' + pType + '&pId=' + pId;
        
    // modal dialog boxes
    if(IsDialog(oType)){
        var da = new daChild();
        window.showModelessDialog(url, da, GetDialogSize(oType) + DIALOG_OPTION);
    }else{
        var oWin = window.open(url, "", WINDOW_OPTION);
        oWin.moveTo(0,0);
        oWin.resizeTo(screen.availWidth,screen.availHeight);
    }   
}

function IsDialog(oType)
{
    if(oType == 218 || oType == 219 || oType == 220 || oType == 221 || oType == 222 || oType == 223 || oType == 224){
        return true;
    }

    return false;
}

function GetDialogSize(oType)
{
    var size = "";
    
    if(oType == 219){
        size = "dialogHeight: 500px;dialogWidth: 450px;";
    }else if(oType == 220){ 
        size = "dialogHeight: 500px;dialogWidth: 600px;";
    }else if(oType == 221 || oType == 222){
        size = "dialogHeight: 350px;dialogWidth: 700px;";
    }else if(oType == 218){
        size = "dialogHeight: 300px;dialogWidth: 450px;";
    }else if(oType == 223 || oType == 224){
        size = "dialogHeight: 500px;dialogWidth: 600px;";
    }
    
    return size;
}

function daChild()
{
     this.dialogRefreshParent = dialogRefreshParent;
}

function dialogRefreshParent(refresh)
{
    if(refresh){
        var oType = queryString('oType');
        var oId = queryString('oId');
        var pType = queryString('pType');
        var pId = queryString('pId');
        var hfoId = window.document.getElementById("ctl00$hfoId");

        if(oType == "false"){
            oType = 0;
        }

        if(hfoId != null && hfoId.value != ""){
            oId = hfoId.value;
        }    
        
        if(pType == "false"){
            pType = 0;
        }
        
        if(pId == "false"){
            pId = 0;
        }
            
        var url = window.location.protocol + '//' + window.location.host + window.location.pathname + '?oType=' + oType + '&oId=' + oId + '&pType=' + pType + '&pId=' + pId;

        window.location = url; //window.location;
    }
}

/*============================================================================
August 29, 2006: NAFI
Functions to change url of iframe
============================================================================*/

function OpenProductPage(obj) // for ContactmanageUI Page (Used by Grid dblclick)
{   
    var objtr = document.getElementById(obj);
    var objalltd = objtr.getElementsByTagName("TD");
    var objName = objalltd[0].innerHTML;
    var url = "../Inventory/ProductBaseUI.aspx?oType=217&oId=" + objName + "&pType=0&pId=0" ;
    var wpage = window.open(url,"", "menubar=0,toolbar=0,location=0,status=1, title='amir',scrollbars=1,resizable=1,width=850,height=600");        
}

function OpenAccountPage(obj) // for ContactmanageUI Page (Used by Grid dblclick)
{
    var objtr = document.getElementById(obj);
    var objalltd = objtr.getElementsByTagName("TD");
    var obj = objalltd[0].innerHTML;
    var objName = objalltd[1].innerHTML;
    var url = "../CRM/AccountContactUI.aspx?NavigateId=" + obj;
    var url1 = "../Contact/_AccountContactUI.aspx?NavigateIdF=" + url + "&TitleF=Contacts : " + objName + "&ContactId=" + obj;
    var wpage = window.open(url1,"", "menubar=0,toolbar=0,location=0,status=0, title='amir',scrollbars=0,resizable=1,width=930,height=600");        

}

function AddProductToShoppingCart(obj) // for admin side sales order(add a product to shopping cart on double click)
{   
    var objtr = document.getElementById(obj);
    var objalltd = objtr.getElementsByTagName("TD");
    var orderUomId = objalltd[2].innerHTML;
    document.getElementById("ctl00_cphPage_hfSelectedProducts").value = orderUomId;
    __doPostBack('ctl00$cphPage$mnuSecondToolbar','Add');
}

function SelectContactAndContinue(obj) // for admin side sales order (select a contact on double click)
{   
    var objtr = document.getElementById(obj);
    var objalltd = objtr.getElementsByTagName("TD");
    var contactId = objalltd[0].innerHTML;
    document.getElementById("ctl00_cphPage_hfSelectedId").value = contactId;
    __doPostBack('ctl00$mnuPageToolbar','Next');
}

function OpenImageLinkPage(obj)
{
    var objtr = document.getElementById(obj);
    var objalltd = objtr.getElementsByTagName("TD");
    var objId = objalltd[0].innerHTML;
    var url = "../Site/SiteImageLinkUI.aspx?NavigateId=" + objId+"&oType=9249&oId=0";
    var wpage = window.open(url,"", "menubar=0,toolbar=0,location=0,status=1, title='amir',scrollbars=1,resizable=1,width=850,height=600");        

}

function OpenInvoiceBanner(obj)
{
    var objtr = document.getElementById(obj);
    var objalltd = objtr.getElementsByTagName("TD");
    var objId = objalltd[0].innerHTML;
    var url = "../Site/SiteInvoiceBannerUI.aspx?NavigateId=" + objId+"&oType=9249&oId=0";
    var wpage = window.open(url,"", "menubar=0,toolbar=0,location=0,status=1, title='amir',scrollbars=1,resizable=1,width=850,height=600");        

}

function OpenOrderPage(obj) // for ContactmanageUI Page (Used by Grid dblclick)
{
    
    var objtr = document.getElementById(obj);
    var objalltd = objtr.getElementsByTagName("TD");
    var objName = objalltd[1].innerHTML;
    var objId = objName.substr(2,objName.length);
    var url = "../Site/SiteManageSalesOrderUI.aspx?OrderID=" + objId;
    var wpage = window.open(url,"", "menubar=0,toolbar=0,location=0,status=1, title='amir',scrollbars=1,resizable=1,width=850,height=600");        

}

function OpenOrderPageFromRewardPoint(obj) // for ContactmanageUI Page (Used by Grid dblclick)
{
    var objtr = document.getElementById(obj);
    var objalltd = objtr.getElementsByTagName("TD");
    var objName = objalltd[0].innerHTML;
    var objId = objName.substr(2,objName.length);
    var url = "../Site/SiteManageSalesOrderUI.aspx?OrderID=" + objId;
    var wpage = window.open(url,"", "menubar=0,toolbar=0,location=0,status=1, title='amir',scrollbars=1,resizable=1,width=850,height=600");        

}

function OpenGiftVoucherDetailPage(obj) // for Contact/SiteGiftVoucherListUI.aspx Page (Used by Grid dblclick)
{
    
    var objtr = document.getElementById(obj);
    var objalltd = objtr.getElementsByTagName("TD");
    var objName = objalltd[1].innerHTML;
    var url = "../Site/SiteGiftVoucherDetails.aspx?GVCode=" + objName;
    var wpage = window.open(url,"", "menubar=0,toolbar=0,location=0,status=1, title='amir',scrollbars=1,resizable=1,width=850,height=600");        

}
function GetPageUrl()  // for Contact Page(Details/Information)
{
//var url = "../CRM/AccountContactUI.aspx?NavigateId=" + DisplayPageUrl;
     var ifrmPage = GetElementByTagId("CurrentPageID","IFRAME");
     //var oSrc = queryStringC("NavigateIdF");
      var oSrc = "../CRM/AccountContactUI.aspx?NavigateId=" + document.getElementById("hfContactId").value;
//      var objUrl = document.getElementById("hfUrl");
      
  //    if(objUrl.value == "0")
    //  {
      // objUrl.value = oSrc;
      // }
//     return oSrc;   
    ifrmPage.src = oSrc;
}

function GetUrlForAll(obj)
{
  var ifrmPage = GetElementByTagId("CurrentPageID","IFRAME");
   var oSrc;
   if(obj == "Orders")
   {
     oSrc = "../Contact/ContactOrderListUI.aspx?ContactId=" + document.getElementById("hfContactId").value;
     ifrmPage.src = oSrc;
   }
   
   if(obj == "Gift Voucher")
   {
     oSrc = "../Contact/SiteGiftVoucherListUI.aspx?ContactId=" + document.getElementById("hfContactId").value;
     ifrmPage.src = oSrc;
   }
   if(obj == "Reward points history")
   {
     oSrc = "../Contact/RewardPointContactUI.aspx?ContactId=" + document.getElementById("hfContactId").value;
     ifrmPage.src = oSrc;
   }
    return;    
}

function OpenPage(url){
    var ifrmPage = GetElementByTagId("ifrmPage","IFRAME");
    ifrmPage.src = url;
}


function OpenAccount(obj)
{
    var objtr = document.getElementById(obj);
    var objalltd = objtr.getElementsByTagName("TD");
    var obj = objalltd[0].innerHTML;
    var url = "AccountContactUI.aspx?NavigateId=" + obj;
    window.open(url,"", "menubar=0,toolbar=0,location=0,status=1,scrollbars=0,resizable=1,width=850,height=600");
    //OpenNavPage(url);
}
function OpenMassEmail()
{
 var obj = document.getElementById("ctl00$cphPage$hfEmailAddress");
 
 var url = "mailto:" + obj.value;
 window.open(url);
 //OpenNavPage(url);
}
function OpenNavPage(url){
    var ifrmPage = document.getElementById("ifrmPage");//parent.frames[0];
    ifrmPage.src = url;
}
function RedirectPage(url){
    window.location.href = url;
}

function OpenNavbar(id){
    var ifrmNavigation = document.getElementById("ifrmNavigation");
    ifrmNavigation.src = "Navigation.aspx?mId=" + id;
}

function OpenNavbarLeft(id){
    var ifrmNavigation = document.getElementById("MyFrame");
    ifrmNavigation.src = id;
}

/*============================================================================
May 26, 2006: NAFI
Functions to open new windows
============================================================================*/

           
 
          

/*============================================================================
May 26, 2006: NAFI
Functions to find controls in aspx page. On final render all asp control
IDs are added a prefix. So, these functions will find the control regardless
of the prefix!
============================================================================*/

function GetElementByTagClass(tagClass, tagName){
    var nodes = document.body.getElementsByTagName(tagName);
    for(i=0; i < nodes.length; i++){
        var node = nodes[i];
        if(node.className == tagClass){
            return node;
        }
    }
    
    return null;
}

function GetElementByTagId(tagId, tagName){
    var nodes = document.body.getElementsByTagName(tagName);
    for(i=0; i < nodes.length; i++){
        var node = nodes[i];
        var nodeId = node.id;
        if(nodeId.indexOf(tagId) > -1){
            return node;
        }
    }
    
    return null;
}

/*============================================================================
May 26, 2006: NAFI
Functions to handle query string in javascript, these are copied from web 
resource, I could not make head and tail of the following code. we have to 
have our own version of these functions later!
============================================================================*/

function PageQuery(q) {
if(q.length > 1) this.q = q.substring(1, q.length);
else this.q = null;
this.keyValuePairs = new Array();
if(q) {
for(var i=0; i < this.q.split("&").length; i++) {
this.keyValuePairs[i] = this.q.split("&")[i];
}
}
this.getKeyValuePairs = function() { return this.keyValuePairs; }
this.getValue = function(s) {
for(var j=0; j < this.keyValuePairs.length; j++) {
if(this.keyValuePairs[j].split("=")[0] == s)
return this.keyValuePairs[j].split("=")[1];
}
return false;
}
this.getParameters = function() {
var a = new Array(this.getLength());
for(var j=0; j < this.keyValuePairs.length; j++) {
a[j] = this.keyValuePairs[j].split("=")[0];
}
return a;
}
this.getLength = function() { return this.keyValuePairs.length; } 
}
function queryString(key){
var page = new PageQuery(window.location.search); 
return unescape(page.getValue(key)); 
}




function CheckEnter(event)
{   
    if(event.keyCode == 13 || event.keyCode == 10)
    {  
        document.getElementById("ctl00_AdminContentPlaceHolder_cmdFind").focus();           
        document.getElementById("ctl00_AdminContentPlaceHolder_cmdFind").click();
    }
}
    
function ClientCheckEnter(event)
{   
    if(event.keyCode == 13 || event.keyCode == 10)
    {  
        document.getElementById("ctl00_ClientContentPlaceHolder_cmdFind").focus();           
        document.getElementById("ctl00_ClientContentPlaceHolder_cmdFind").click();
    }
}
   
   
      
    function ChangePage()
    {
        var valueObj = document.getElementById("tbPage");
        var obj = "Page$" + valueObj.value;
        __doPostBack('ctl00$cphPage$gdvAccount',obj);
    }
    
  

// for changing the page
       function ChangePageContactOrder()
    {
        var valueObj = document.getElementById("tbPage");
        var obj = "Page$" + valueObj.value;
        __doPostBack('ctl00$cphPage$gdvContactOrderList',obj);
    }


    /* -----  For Reward Point  ---------- */
    
    function checkEnterPage_RewardPoint(sText,valueObject)
    {   
      var objMaxRecord = document.getElementById("ctl00_cphPage_HfTotalRecord_RewardPointContact");
      var curno = Number(valueObject);
      var maxno = Number(objMaxRecord.value);
        if(curno <= maxno)
        {
        
        if( sText.charCodeAt(0)==13 )
        {  
            if(Number(valueObject) >= 1)
            {
             var obj = "Page$" + valueObject;
             __doPostBack('ctl00$cphPage$gdvRewardPointContact',obj);
            }
         }
         }
       return false;
      }

       function ChangePageGiftVoucherContact() // for gift voucher
    {
        var valueObj = document.getElementById("tbPage");
        var obj = "Page$" + valueObj.value;
        __doPostBack('ctl00$cphPage$gdvAccount',obj);
    }
    
  /* -----  For Manage Product  ---------- */
    
    function checkEnterPage_ManageProduct(sText,valueObject)
    {   
      var objMaxRecord = document.getElementById("ctl00_cphPage_HfTotalRecord_ManageProduct");
      var curno = Number(valueObject);
      var maxno = Number(objMaxRecord.value);
        if(curno <= maxno)
        {
        
        
        if( sText.charCodeAt(0)==13 )
        {  
            if(Number(valueObject) >= 1)
            {
             var obj = "Page$" + valueObject;
             var objbtn = document.getElementById("btnGo");
             objbtn.focus();
            }
         }
        
        
            ////////        if( sText.charCodeAt(0)==13 )
            ////////        {  
            ////////            if(Number(valueObject) >= 1)
            ////////            {
            ////////             var obj = "Page$" + valueObject;
            ////////             __doPostBack('ctl00$cphPage$gdvManageProduct',obj);
            ////////            }
            ////////         }
         }
       return false;
      }

     function ChangePageManageProduct() // for gift voucher
    {
        var valueObj = document.getElementById("tbPage");
        var obj = "Page$" + valueObj.value;
        __doPostBack('ctl00$cphPage$gdvManageProduct',obj);
    }
    
    

    function CheckInput(event,ctrId)
    {   
//        if(event.keyCode == 13 || event.keyCode == 10)
//        {  
//            document.getElementById(ctrId).focus();           
//            //document.getElementById(ctrId).click();
//        }
        var sText = String.fromCharCode(event.keyCode);
        if( sText.charCodeAt(0)==13 || sText.charCodeAt(0)==10 )
        {  
             if(navigator.appName == "Microsoft Internet Explorer")
             {                  
                document.getElementById(ctrId).focus();                
             }
             else
             {
                return false;
             }
        }
        else
        {
            return true;
        }
    }
    
    function CheckInputForMaster(event,ctrId)
    {   
        var sText = String.fromCharCode(event.keyCode);
        
        if( sText.charCodeAt(0) == 13 || sText.charCodeAt(0) == 10 )
        {  
             if(navigator.appName == "Microsoft Internet Explorer")
             {  
                if( document.getElementById(ctrId) ) 
                {
                    document.getElementById(ctrId).focus();
                    document.getElementById(ctrId).click();
                    return false;
                }
                else
                {
                    alert("Object not found");
                    return false;   
                }
             }
             else
             {
                return false;
             }
        }
        else
        {
            return true;
        }
    }
    
    function RestrictCharacters(event)
    {   
       var key = event.keyCode;
       //alert(key);
       //debugger;
        //allow digits but not the special characters with shift+<digits>
//        if(key >= 48 && key <= 57)
//        {
//            if(event.shiftKey == true)
//                return false;
//            else
//                return true;
//        }
        //allow alphabets
//        else if((key >= 65 && key <= 90))
//        {
//            return true;
//        }
        //32 = space, 8 = backspace, 9 = tab, 46 = delete, 37 = left arrow, 39 = right arrow
//        else if(key == 32 || key == 8 || key == 9 || key == 46 || key == 37 || key == 39)
//        {
//            return true;
//        }
//        else if(key == 106 || key == 107 || key == 109 || key == 111)
//        {
//            return false;
//        }
        //return false;
        //22 = ", 25 = %, 26 = &, 58 = :, 60 = <, 62 = >, 92 = \, ?
        //alert(key);
//        if(key == 60 || key == 62 || key == 92)
//        {
//            return false;
//        }
        //alert(key);
        //'/' = 191, '[' = 219, ']' = 221, '\' = 220
        if(key == 191 || key == 219 || key == 221 || key == 220)
            return false;
        //holding shift
        //'"' = 222, ':' = 186, '%' = 53, '?' = 191, '&' = 55, '<' = 188, '>' = 190, '#' = 51, '|' = 220, '*' = 56
        if(event.shiftKey == true)
        {
            if(key == 222 || key == 186 || key == 53 ||key == 55 || key == 188 || key == 190 || key == 191 || key == 51 || key == 220 || key == 56)
                return false;
        }
        return true;
    }
function adjustArtistImage(oImage, src)
{
    //debugger;
    var STANDARD_WIDTH = 102;
    var STANDARD_HEIGHT = 70;
    
    var width = oImage.width;
    var height = oImage.height;
    
    if (oImage.width > STANDARD_WIDTH && oImage.height > STANDARD_HEIGHT)
    {
        width = STANDARD_WIDTH;
        height = Math.ceil((parseInt(oImage.height) / parseInt(oImage.width)) * STANDARD_WIDTH);
    }
    else if (oImage.width >= STANDARD_WIDTH && oImage.height < STANDARD_HEIGHT)
    {
        width = STANDARD_WIDTH;
        height = Math.ceil((parseInt(oImage.height) / parseInt(oImage.width)) * STANDARD_WIDTH);
    }
    else if (oImage.width < STANDARD_WIDTH && oImage.height >= STANDARD_HEIGHT)
    {
         width = Math.ceil((parseInt(oImage.width) / parseInt(oImage.height)) * STANDARD_HEIGHT);
         height = STANDARD_HEIGHT;
    }
    else if (oImage.width < STANDARD_WIDTH && oImage.height < STANDARD_HEIGHT)
    {
        width = oImage.width;
        height = oImage.height;
    }
    
    var image = new Image();
    image.src = src;
    image.width = width;
    image.height = height;
    
    return image;
}


function SetFeaturedArt(gridControlId, checkBoxControl, checkBoxColIndex, controlIndex, hiddenFieldId)
{   
    gridControl = document.getElementById(gridControlId);
    hiddenFieldControl = document.getElementById(hiddenFieldId);
    hiddenFieldControl.value = "";
    var rows = gridControl.getElementsByTagName("TR");
     var c= 0;
    for(i = 0; i < rows.length; i++)
    {
        var col = rows[i].getElementsByTagName("TD")[checkBoxColIndex];
        if(col != undefined)
        {
            var checkBox = col.getElementsByTagName("Input")[controlIndex];
            if(checkBox != undefined)
            {
                if(checkBox.checked == true)
                {
                  c++;
                    if(c > 5)
                    {
                        alert("You can not select more than 5 products.");
                        checkBox.checked = false;
                        return;
                    }
                    if(hiddenFieldControl.value != "")
                    {
                        hiddenFieldControl.value = hiddenFieldControl.value+",";                        
                    }
                    hiddenFieldControl.value = hiddenFieldControl.value+checkBox.value;                        
                }
            }
        }
    }
}