﻿// JScript File

String.prototype.trim = function() 
{ 
    return this.replace(/^\s+|\s+$/, ''); 
};

function enableDisableVal(status)
{
    //alert(Page_Validators);
    // alert(Page_Validators.length + "'" + status + "'");
    if(Page_Validators != 'undefined')
    {
        for(var i=0; i < Page_Validators.length; i++)
        {
            Page_Validators[i].enabled = status;
        }
    }
}
function enterAction(src, e, dest)
{
    var node = (e.target) ? e.target : ((e.srcElement) ? e.srcElement : null);
    if(e.keyCode == 13)
	{
	    var srcId = src.name.replace(/_/ig,'$')
	    // alert(src.name.replace(/_/ig,'$') + '--' + node.name);
	    if(typeof(node.name) != 'undefined' && (node.name == srcId))
		{
	        //alert(node.name);
	        if(Page_Validators)
            {
                for(var i = 0; i < Page_Validators.length; i++)
                {
                    Page_Validators[i].enabled = false;
                }
            }
            // document.getElementById("ctl00_imgSearchButton").focus();
	        __doPostBack("ctl00$btnSearchBack","");
	    }
	}
}

function checkLeftSearch(src1, obj, errorMsg)
{
    // src1.type = "image";
    var txt = document.getElementById(obj);
    if(txt.value.trim() == "")
    {
        alert(errorMsg);
        return false;
    }
    else
    {   
        // __doPostBack('ctl00$btnSearchBack','');
        return true;
    }
}

// Function Use for Displaying search criteria in advance search.
function displaySearchOptions(sObj,dObj)
{
    var panel = document.getElementById(dObj);
    if(panel.style.display == "none")
    {
        panel.style.display = "block";
        sObj.style.display = "none";
    }
    else
    {
        panel.style.display = "none";
    }
}

// Validation of Advance Search Page for All fields. [Start Here]
function ValidateSearch(objTxt,lowest,highest)
{
    var from = document.getElementById(lowest);
    var to = document.getElementById(highest);
    var txt = document.getElementById(objTxt);
    
    if(txt.value == "")
    {
        alert("Please enter search text.");
        return false;
    }
    else
    {
        if(from.value != "" && to.value == "")
	    {
	        alert('Please enter price To!');
	        return false;
	    }  
	    else if(to.value != "" && from.value == "")
	    {
	        alert('Please enter price From!');
	        return false;
	    } 
	    else if(to.value != "" && from.value != "")
	    {
		    if(!isNaN(from.value) && !isNaN(to.value))
		    {
			    if(parseFloat(from.value) > parseFloat(to.value))
			    {
				    alert('From price should be less then To price!');
				    return false;
			    }
			    else
				    return true;
		    }
		    else
		    {
			    alert('Please Enter Correct Price Value!');
			    return false;
		    }
	    }
	    else
	    {
	        if(from.value == "0")
	            from.value = 1;
	        return true;
	    }
	}    
}
// [End Here]

// Hide Error Display in Product List.
function hideErrorMsg(obj)
{
    var div = document.getElementById(obj);
    div.style.display = "none";
}

// Function that will check the quantity in Product Detail & Shopping Cart Page.
function checkQuantity(obj)
{
    var qty = document.getElementById(obj);
        
    if(qty.value != "")
    {
        if(isNaN(qty.value) == false)
        {
            if(parseInt(qty.value) <= 0)
            {
                qty.value = 1;
                alert("Quantity must be more than Zero.");
                return false;
            }
            else
                return true;
        }
        else
        {
            alert("Please Enter only Numeric Value in Quantity Field.");
            return false;
        }
    }
    else
    {
        alert("Please Enter Quantity.");
        return false;
    }
    
}

// This code will use for Enable/disable State at registration.
function clearStateVal()
{
    var drp = document.getElementById("ctl00_CPH1_drpMCUSXintSta0");
    var txt = document.getElementById("ctl00_CPH1_txtother");
    var chk = document.getElementById("ctl00_CPH1_chkother");
    
    if(drp.value == "")
	{
	    txt.value="";
		txt.disabled=true;
		chk.checked=false;
		return;
	}
	
	if(drp.value > 0)
	{
		txt.value="";
		txt.disabled=true;
		chk.checked=false;
	}
	else if(drp.value == 0)
	{
		txt.value="";
		txt.disabled=false;
		chk.checked=true;
	}
}
function setStateVal(obj)
{
    var txt = document.getElementById("ctl00_CPH1_txtother");
    var drp = document.getElementById("ctl00_CPH1_drpMCUSXintSta0");
	if(obj.checked)
	{
		txt.disabled=false;
		drp.value = "0"
	}
	else
	{
		drp.value = "";
		txt.disabled = true;
		txt.value="";
	}
}
// Enable/disable End here

// Validating Payment Field at Pro Method of Payment.
<!--
function mod10( cardNumber ) 
{ 
	// LUHN Formula for validation of credit card numbers.
	var ar = new Array( cardNumber.length );
	var i = 0,sum = 0;

   	for( i = 0; i < cardNumber.length; ++i ) 
	{
    	ar[i] = parseInt(cardNumber.charAt(i));
    }
    
	for( i = ar.length -2; i >= 0; i-=2 ) 
	{ 
		// you have to start from the right, and work back.
    	ar[i] *= 2;		// every second digit starting with the right most (check digit)
   		if( ar[i] > 9 ) ar[i]-=9;	// will be doubled, and summed with the skipped digits.
   	}	// if the double digit is > 9, ADD those individual digits together 

   	for( i = 0; i < ar.length; ++i ) 
	{
    	sum += ar[i];	// if the sum is divisible by 10 mod10 succeeds
   	}
   	return (((sum%10)==0)?true:false);	 	
}

function expired( month, year ) 
{
   	var now = new Date();	// this function is designed to be Y2K compliant.
   	var expiresIn = new Date(year,month,0,0,0);		// create an expired on date object with valid thru expiration date
   	expiresIn.setMonth(expiresIn.getMonth()+1);		// adjust the month, to first day, hour, minute & second
                                                    //	of expired month
   	if(now.getTime() < expiresIn.getTime()) 
   	{
   	    return false;
   	}
    return true;	// then we get the miliseconds, and do a long integer comparison
}

function validateCard(cardNumber,cardType,cardMonth,cardYear,cardCode) 
{
//    if(ship.value.length == 0)
//    {
//        alert("Please Select Shipping Service.");
//        return false;        
//    }
    if(cardType.length == 0)
	{
	    alert("Please select card type.");
	    return false;
	}
  	if( cardNumber.length == 0 ) 
	{
		//most of these checks are self explanitory
    	alert("Please enter valid card number.");
    	return false;				
    }
    for( var i = 0; i < cardNumber.length; ++i ) 
	{	
		// make sure the number is all digits.. (by design)
        var c = cardNumber.charAt(i);

   		if( c < '0' || c > '9' ) 
		{
        	alert("Please enter valid card number. Use only digits. do not use spaces or hyphens.");
        	return false;
        }
    }
    
	var length = cardNumber.length;		//perform card specific length and prefix tests
	
   	switch( cardType ) 
	{
    	case 'a':
			if( length != 15 ) 
			{
             	alert("Please Enter Valid American Express Card Number.");
                return false;
            }
            var prefix = parseInt( cardNumber.substring(0,2));
   			if( prefix != 34 && prefix != 37 ) 
			{
            	alert("Please Enter Valid American Express Card Number.");
                return false;
            }
        break;
        case 'd':
			if( length != 16 ) 
			{
             	alert("Please Enter Valid Discover Card Number.");
                return false;
            }
            var prefix = parseInt( cardNumber.substring(0,4));
			if( prefix != 6011 ) 
			{
            	alert("Please Enter Valid Discover Card Number.");
                return false;
            }
        break;
        case 'm':
			if( length != 16 ) 
			{
             	alert("Please Enter Valid MasterCard Number.");
                return false;
            }
            var prefix = parseInt( cardNumber.substring(0,2));
			if( prefix < 51 || prefix > 55) 
			{
            	alert("Please Enter Valid MasterCard Number.");
                return false;
            }
        break;
        case 'v':
			if( length != 16 && length != 13 ) 
			{
            	alert("Please Enter Valid Visa Card Number.");
                return false;
            }
            var prefix = parseInt( cardNumber.substring(0,1));
			if( prefix != 4 ) 
			{
            	alert("Please Enter Valid Visa Card Number.");
                return false;
            }
        break;
    }
    
	if( !mod10( cardNumber ) ) 
	{ 	
		// run the check digit algorithm
        alert("Sorry! this is not a valid credit card number.");
        return false;
    }
    if( expired( cardMonth, cardYear ) ) 
	{	
		// check if entered date is already expired.
        alert("Sorry! The Expiration Date you have Entered would make this Card Invalid.");
        return false;
    }
    if (cardCode == "")
	{
		alert("Please enter 3 or 4 digit security code.");
        return false;
	}
	else
	{
		 for( var i = 0; i < cardCode.length; ++i ) 
		{	
			var c = cardCode.charAt(i);
			if( c < '0' || c > '9' ) 
			{
				alert("Please enter valid 3 or 4 digit security code number. Use only digits.");
				return false;
			}
		}
	}
	return true;	// at this point card has not been proven to be invalid
}

function createBookmark()
{
	var url = window.location.href;
	var title = document.title; //"Physicians Formula";
	if(window.sidebar)
		window.sidebar.addPanel(title,url, "");
	else if(window.external)
		window.external.AddFavorite(url,title);
	else if(window.opera && window.print)
		return true;
	else
	    alert("Please hit Ctrl + D to bookmark this page.");
}
//-->