﻿   
 //THIS FUNCTION WILL FILL ALL THE VALUES IN THE OTHER FIELDS
function fillvalues(varCount, myObject)
{
       if (myObject == '')
         {
            return ;
          }
            
       var qryStr = "itemcode=" + myObject + "&clevel=" + document.getElementById("hdCLevel").value;
       //alert(qryStr);
       $.get("Handlers/GetProductDetails.ashx?" + qryStr, function(result)
       {
            //alert(result);
            var strSplit = result.split("~~");
            if ( strSplit[0] != ' ')
            {
                document.getElementById('price_' + varCount  ).innerHTML = strSplit[0] ;
            }
            if ( strSplit[1] != ' ')
            {
                document.getElementById('spn_img_' + varCount  ).innerHTML = '<img src="' + strSplit[1] + '" style="border-width:0px;" width="75px" height="75" />';
            }
            if ( strSplit[2] != ' ')
            {
  //              alert(strSplit[2] );
                document.getElementById('min_' + varCount  ).innerHTML = strSplit[2] ;
                document.getElementById('qty_' + varCount  ).value = strSplit[2] ;
               // var myNextCount = (varCount *1) + 1;
//                alert(myNextCount );
                //document.getElementById('item_' + myNextCount  ).focus();
            }
            else
            {
                //alert('Invalid SKU');
                //document.getElementById('item_' + varCount  ).value = '';
                //document.getElementById('item_' + varCount  ).focus();
            }
            if ( strSplit[6] != ' ')
            {
                document.getElementById('desc_' + varCount  ).innerHTML = strSplit[6] ;
            }

            if ( strSplit[7] != ' ')
            {
                document.getElementById('uom_' + varCount  ).innerHTML = strSplit[8] ;
            }
            
            
            if ( strSplit[7] != ' ')
            {
                if ( isNaN(strSplit[7]))
                {}
                else
                {
                    if ( strSplit[7] > 0 )
                        document.getElementById('aqty_' + varCount  ).innerHTML = 'IN STOCK' ;
                    else
                        document.getElementById('aqty_' + varCount  ).innerHTML = 'OUT OF STOCK' ;
                }
            }
            
            
            
       });
}

//THIS FUNCTION WILL ADD THE SKU TO THE LITERAL, SO THE PAGES INSERTS INTO DB
function saveCart(myType)
{
   $.blockUI({ css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: '#000', 
            '-webkit-border-radius': '10px', 
            '-moz-border-radius': '10px', 
            opacity: .5, 
            color: '#fff' 
        } }); 
         
    var myControls;
    var ctrlName; 
    myControls =  document.getElementById('form1').elements;
    var ctrLength;
    ctrLength = myControls.length;
    var strSKU = '';
    var strQty = '';
    var mySKU = '';
    var myQty = '';
    var ctrlName1 = '';
    var qry = '';
    var boolMyError = false;
   
    
    //LOOPING THROUGH EACH CONTROL AND GETTING CORRECT FOOTER TEXTBOX
    for (var intCount=0; intCount < ctrLength; intCount++)
    {
        ctrlName = '';
        ctrlName = myControls[intCount].id;
        if (ctrlName.indexOf('item_') != -1)
        {
            if (document.getElementById(ctrlName).value != "")
            {
                    mySKU = document.getElementById(ctrlName).value;
                    ctrlName1 = ctrlName.replace('item_','qty_');
                    myQty = document.getElementById(ctrlName1).value;
                    
                    if (myQty == '')
                    {
                        myQty = 1;
                    }
                    
                    if (myQty != '' && mySKU!= '')
                    {
                        $.ajaxSetup({async:false});
                        qry = "Handlers/SaveQuickOrder.ashx?sku="+ mySKU + "&qty=" + myQty + "&type=" + myType + "&cid=" + document.getElementById('hdCID').value;
                        $.get( qry , function(result)
                        {
                        });
                    }
            }
        }
   }
   
    if (myType=="0")
    {
       window.location.href="shoppingcart.aspx";
    }
    if (myType=="1")
    {
        window.location.href="wishlist.aspx";
    }
    if (myType=="2")
    {
        window.location.href="shoppingcart.aspx";
    }
}


function checkNumeric(ip) 
{
    //alert('inside');
    var err = 0
    string = document.getElementById(ip).value ;
    var valid = "0123456789"
    var ok = "yes";
    var temp;
    for (var i=0; i< string.length; i++) 
    {
        temp = "" + string.substring(i, i+1);
        if (valid.indexOf(temp) == "-1") err = 1;
     }
     
     if (err == 1)
     {
        alert('Invalid SKU/Quantity');
        document.getElementById(ip).value='';
        //document.getElementById(ip).focus();
     }
}



function saveCartPL(myType)
{
  $.blockUI({ css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: '#000', 
            '-webkit-border-radius': '10px', 
            '-moz-border-radius': '10px', 
            opacity: .5, 
            color: '#fff' 
        } }); 
  
    var myControls;
    var ctrlName; 
    var boolProcess = false;
    myControls =  document.getElementsByTagName("*");
    var ctrLength;
    ctrLength = myControls.length;
    var getCID = '';
    var intItemCount=0;
    
    for (var intCount=0; intCount < ctrLength; intCount++)
    {
        ctrlName = '';
        ctrlName = myControls[intCount].id;
        if (ctrlName.indexOf('WOWajaxChkBX~~') != -1)
        {
            if (document.getElementById(ctrlName).checked == true)
            {
                var myQRY = ctrlName.split("~~");
                intItemCount = intItemCount + 1;
                if (intItemCount == 0)
                {
                    getCID =  myQRY[1];
                }
                qry = "Handlers/SaveQuickOrder.ashx?" + myQRY[1] + myType;
                        $.get( qry , function(result)
                        {
                            document.getElementById('divError').innerHTML = "<font color='red'>Added Successfully</font>";          
                        });
                document.getElementById(ctrlName).checked = false;
            }
        }
    }

    $.blockUI({ css: {
        border: 'none',
        padding: '15px',
        backgroundColor: '#000',
        '-webkit-border-radius': '10px',
        '-moz-border-radius': '10px',
        opacity: .5,
        color: '#fff',
        message: 'Added Successfully to your cart.'
        }
    });
    setTimeout($.unblockUI, 1000);
   
        
}

function saveCartAllPL(myType)
{
  $.blockUI({ css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: '#000', 
            '-webkit-border-radius': '10px', 
            '-moz-border-radius': '10px', 
            opacity: .5, 
            color: '#fff' 
        } }); 
  
    var myControls;
    var ctrlName; 
    var boolProcess = false;
    myControls =  document.getElementsByTagName("*");
    var ctrLength;
    ctrLength = myControls.length;
    var getCID = '';
    var intItemCount=0;
    
    for (var intCount=0; intCount < ctrLength; intCount++)
    {
        ctrlName = '';
        ctrlName = myControls[intCount].id;
        if (ctrlName.indexOf('WOWajaxChkBX~~') != -1)
        {
            
                var myQRY = ctrlName.split("~~");
                intItemCount = intItemCount + 1;
                if (intItemCount == 0)
                {
                    getCID =  myQRY[1];
                }
                qry = "Handlers/SaveQuickOrder.ashx?" + myQRY[1] + myType;
                        $.get( qry , function(result)
                        {
                                    document.getElementById('divError').innerHTML = "<font color='red'>Added Successfully</font>";
                        });
                document.getElementById(ctrlName).checked = false;
            
        }
    }
    
   setTimeout($.unblockUI, 1000);       
        
}

//This is for the pop up to open -- customized for wow.
 function MyOpenPopup (c) 
    {
        
        window.open(c,
                    'window',
                    'width=480,height=480,scrollbars=yes,status=yes');
    }

