﻿// JScript File
/* Form Validation Script for Shopping Cart Listing
Developed By	: Pooja Verma   
Date			: April 23, 2008 
Message			: Functions for the listing of Shopping Cart
*/

function SelectAll(obj)
{
    var strGridName=document.getElementById("ctl00_ContentPlaceHolder1_gdvCart");
    return CheckAll(obj,strGridName);
}

function validate()
 { 
    //return ValidateGreaterThanZero();
    var selectedBoxes = ""; 
    lblgrid = document.getElementById('ctl00_ContentPlaceHolder1_gdvCart');
    var inputTags = lblgrid.getElementsByTagName("input"); 
    var tagsLength = inputTags.length; 
    for(var i=0;i<tagsLength ;i++)
    { 
       if(inputTags[i].checked==true)
       {
           selectedBoxes ="1"; 
       }
    } 
    if(selectedBoxes.length>0)
    {
            return window.confirm("Are you sure you want to update quantity?");
    }
    else
    {
        alert("Please select the item(s) you want to update!");
        return false;
    }
 }

function GreaterThanZero(obj)
{
       if(obj.value !='')
       {
           
           var temp= obj;
           if((isNaN(obj.value) == true) || (obj.value <= 0))
			    { 		
				    alert('Quantity Must be Numeric and Greater Than Zero.');
				    obj.select();
				   
				    return false; 
		 	    }
		}
}




function ValidateGreaterThanZero()
{

    for (elementCounter=0; elementCounter< document.forms[0].elements.length; elementCounter++)
        {
        
            if (document.forms[0].elements[elementCounter].type == 'checkbox'  && document.forms[0].elements[elementCounter].name.indexOf('chkBox') > -1)
            {
            
                if(document.forms[0].elements[elementCounter].checked == true)
               {
                    for(innerCounter=0; innerCounter<document.forms[0].elements.length; innerCounter++)
                    {
                        
                        if(document.forms[0].elements[innerCounter].type=='text' && document.forms[0].elements[innerCounter].name.indexOf('txtPurchase')>-1)
                        {
                          
                                if(document.forms[0].elements[innerCounter].value <= 0)
                                {
                                    alert('Quantity should be greater than Zero');
                                    return false;
                                }
                            
                        }
                    }
                }        
            }           
        }              
 }
                
                            

function CheckOutValidate()
{
    var rules = new Array();
    rules[0]='ctl00_ContentPlaceHolder1_txtCouponCode|required|Please enter Coupon Code';

    if(rules.length>0)
    {
        return performCheck('aspnetForm', rules, 'classic');
    }
}


function remove()
 {
    var selectedBoxes = ""; 
    lblgrid = document.getElementById('ctl00_ContentPlaceHolder1_gdvCart');
    var inputTags = lblgrid.getElementsByTagName("input"); 
    var tagsLength = inputTags.length; 
    for(var i=0;i<tagsLength ;i++)
    { 
       if(inputTags[i].checked==true)
           selectedBoxes ="1"; 
    } 
    if(selectedBoxes.length>0)
    {
      return window.confirm("Are you sure you want to remove item from the cart?");
      
    }
    else
    {
        alert("Please select the item(s) you want to remove!");
        return false;
    }
 }


function keypress(e)
{
    if ([e.keyCode||e.which]==8) //this is to allow backspace
    return true;
    if ([e.keyCode||e.which]==9) //this is to allow tab
    return true;
//    if ([e.keyCode||e.which]==46) //this is to allow period
//    return true;
    if ([e.keyCode||e.which] < 48 || [e.keyCode||e.which] > 57)
    e.preventDefault? e.preventDefault() : e.returnValue = false;
}

function ValidateCouponCode()
{
    var obj = document.getElementById('ctl00_ContentPlaceHolder1_hdnCouponCodes');
    var strCouponCodes = obj.value;
    var index=-1;
    var arrCouponCodes = strCouponCodes.split(',');
    if(document.getElementById('ctl00_ContentPlaceHolder1_txtCouponCode').value!= '')
    { 
        for(counter=0;counter<arrCouponCodes.length;counter++)
        {
            if(document.getElementById('ctl00_ContentPlaceHolder1_txtCouponCode').value == arrCouponCodes[counter])
            {
                
                index = counter;
               
            }
        }
       }
        else
        {
            return true;
        }
        
    
    if(index < 0)
    {
        alert('Please enter valid Coupon Code!');
        return false;
    }
    return true;
}
 function opendetail(purchaseId)
    {
        newwindow=window.open("productdetailpopup.aspx?puid=" +purchaseId,"name","toolbar=0, width=750, height=520, top=50, scrollbars=1, menubar=0,resizable=0");
        
    }