﻿
(function ($) {
    var map = new Array();
    $.Watermark = {
        ShowAll: function () {
            for (var i = 0; i < map.length; i++) {
                if (map[i].obj.val() == "") {
                    map[i].obj.val(map[i].text);
                    map[i].obj.css("color", map[i].WatermarkColor);
                } else {
                    map[i].obj.css("color", map[i].DefaultColor);
                }
            }
        },
        HideAll: function () {
            for (var i = 0; i < map.length; i++) {
                if (map[i].obj.val() == map[i].text)
                    map[i].obj.val("");
            }
        }
    }

    $.fn.Watermark = function (text, color) {
        if (!color)
            color = "#aaa";
        return this.each(
			function () {
			    var input = $(this);
			    var defaultColor = input.css("color");
			    map[map.length] = { text: text, obj: input, DefaultColor: defaultColor, WatermarkColor: color };
			    function clearMessage() {
			        if (input.val() == text)
			            input.val("");
			        input.css("color", defaultColor);
			    }

			    function insertMessage() {
			        if (input.val().length == 0 || input.val() == text) {
			            input.val(text);
			            input.css("color", color);
			        } else
			            input.css("color", defaultColor);
			    }

			    input.focus(clearMessage);
			    input.blur(insertMessage);
			    input.change(insertMessage);

			    insertMessage();
			}
		);
    };
})(jQuery);
$(document).ready(function () {

    $(".searchtext").Watermark("Enter search word(s)");
    $("#emailAddr").Watermark("Enter email address");
    $("a.showdiv").click(function (e) {
        $("div.paymentoption").hide();
        $("#" + $(this).attr("rel")).toggle();

        $("a.showdiv").toggleClass("active")
        e.preventDefault();

    });

    $("#dropdownlink").click(function (e) {
        $("#dropdownul").toggle();
        e.preventDefault();
    });

    $("#dropdownul li a").click(function (e) {
        var selection = $(this).text();
        if (selection == "Description") {
            $("#ProductSearchBy").val(2)
        }
        else {
            $("#ProductSearchBy").val(1)
        }

        $(this).text($("#dropdownlink").text());
        $("#dropdownlink").text(selection);
        $("#dropdownul").toggle();
        e.preventDefault();
    });

    $("addtocartsubmit").click(function (e) {
        $("#prodinfoform").submit();
        e.preventDefault();
    });

    $("#searchProducts").click(function (e) {

        var searchtext = $("txtsearch").val();

        if (searchtext == "") {
            e.preventDefault();
        }

        $("#searchForm").submit();



        e.preventDefault();



    });


    $("div.footer_inner").addClass("bottombodybg");

});

function dosubmit()    
{
    var bmodify   = document.getElementById("modifybasket")	;    
    var bcheckout = document.getElementById("checkout");
    bcheckout.value = ""
    bmodify.value = "modifybasket";
    document.basketform.submit();	
}

function RedirectToAddADDress (lvalue,stockid,dropdownnum,needurlrewrite,rewritedesc)
   {
     //var opttype = document.getElementById('slopttype1').value
     //alert(opttype)
    // alert("hh")
     var new_url="" ;
     var addparam ="" ;
     for( var i = 1 ; i <= dropdownnum ; i++)
     {
      
      var attribtype = "slopttype"+i ;
      attribtype = "document.getElementById('"+attribtype+"').value" ;
      attribtypeval = eval(attribtype)
      
      if (attribtypeval=="D")
      {
        var Prodattribname = "Attrib"+i ;
        var Prodattribevalname = "document.getElementById('"+Prodattribname+"').selectedIndex" ;
        selIndex= eval(Prodattribevalname) ;
        
        Prodattribevalname = "document.getElementById('"+Prodattribname+"').options["+selIndex+"].value" ;
        var selIndexvalue = eval(Prodattribevalname) 
      
      }//if (attribtypeval=="D")
      
      if (attribtypeval=="R")
      {
        attribradio = eval("prodinfoform.Attrib"+i+".length") ;
        j = attribradio
        
        for (k=0; k<j; k++)
        {
            radiochecked = eval("prodinfoform.Attrib"+i+"["+k+"].checked") ;
             if (radiochecked)
             {
                selIndexvalue = eval("prodinfoform.Attrib"+i+"["+k+"].value") ;               
             }
        }
      
      } //if (attribtypeval=="R")

      if (i==1)
        {
        addparam = selIndexvalue
        }
        else
        {
        addparam = addparam + "|"+selIndexvalue
        }
     }
  
    if (needurlrewrite==1)
		{
		new_url = "<%=session('insecureurl')%>"+"productinfo/" + stockid + "/" + rewritedesc + "/" + addparam
		}
	else
		{	
	    new_url = "prodinfo.asp?number="+stockid+"&opt="+addparam
		}
    //alert(new_url)
    //alert(addparam)
    window.location=new_url;

}

function ShowAddtionalImage(storeurl,itemcode)
{
   page_url = storeurl + 'ShowAdditionalImg.asp?number='+itemcode ;                        
   popupWin = window.open(page_url, '', 'scrollbars,resizable,width=700,height=650');
}                
function displaythis(what)
		{
		
		var baddtocart = document.getElementById('addtocart')
		var bwishlist   = document.getElementById('addtowishlist')
		var bgiftlist   = document.getElementById('addtowishlist')

		 if (what.value =="cart")
		     {	
			   baddtocart.value="addtocart" ;
			   bwishlist.value="" ; 
			 }	
		 if (what.value=="wishlist")
			 {
			   baddtocart.value="" ;
			   bwishlist.value="addtowishlist" ; 
			 }
			  if (what.value=="giftlist")
			 {
			   baddtocart.value="" ;
			   bwishlist.value="addtogiftreg" ; 
			 }

}
function CheckForEmpty(inputstr)
{
  if(inputstr.length == 0)
    return true ;
    
  for( var i = 0 ; i <  inputstr.length ; i++)
  {
   var onechar = inputstr.charAt(i) ;
   if( onechar != " ")
     return false ;
 
  }
  
 return true ;
	
}
 function IsPosInteger(inputval)
 { 
  inputstr = inputval.toString() ;
   for( x = 0 ; x <inputstr.length; x++)
    {
	  var onechar = inputstr.charAt(x) ;
	  if( onechar < "0" || onechar > "9" )	        
	    	return false;	  	
	}
   return true;
 
 }
  
 function isDate(sDate) {
    var scratch = new Date(sDate);
    if (scratch.toString() == "NaN" || scratch.toString() == "Invalid Date") {
        //alert("Not a Date");
        return false;
    } else {
        return true;
    }
}

	function Process() 
	{	
	    var dropdownnum = document.getElementById('MaxAttriboption').value ;
	    
	    var NonSkuinputtxt = document.getElementById('maxNONSkuOption').value ;
	    
	    if (NonSkuinputtxt>0)
	    {
	    
	        for( var i = 1 ; i <= NonSkuinputtxt ; i++)
	        {
	        
	         var attribtype = "NonSkuslopttype"+i ;
	            attribtype = "document.getElementById('"+attribtype+"').value" ;	
	            attribtypeval = eval(attribtype) 
	            //alert(attribtypeval)    
	           
			   
	           if (attribtypeval=="T")
	           {
	            var NonSkuText = "NonSkusvaltype"+i ; 
	                NonSkuTextType = "document.getElementById('"+NonSkuText+"').value" ;	
	                NonSkuTextTypeVal = eval(NonSkuTextType) 
	                //alert(NonSkuTextTypeVal)  
					/* 
	                if (NonSkuTextTypeVal=="N")
	                {
	                 //check for integer value
	                 var NONSkuInput = "NonSkuAttribtext"+i ;
	                    NONSkuInputVal = "document.getElementById('"+NONSkuInput+"').value" ;	
	                    NONSkuInputValue = eval(NONSkuInputVal) 	                    
	                    //alert(NONSkuInputValue)
	                    if (CheckForEmpty(NONSkuInputValue)==false)
	                    {
	                        if (IsPosInteger(NONSkuInputValue)==false)
	                        {
	                            var NOnSkutitle = "NonSkuAttribTitle"+i ;
	                            NOnSkutitleVal = "document.getElementById('"+NOnSkutitle+"').value" ;	
	                            NOnSkutitleValue = eval(NOnSkutitleVal) 
	                            
	                            alert("Enter Integer Value for '" + NOnSkutitleValue +"'") ;
	                            return false ;
	                        }
	                    }
	                	} //if (NonSkuTextTypeVal=="N")
					*/
					
	                
	               if (NonSkuTextTypeVal=="D")
	               {
	                //check for Date value
	                var NONSkuInput = "NonSkuAttribtext"+i ;
	                NONSkuInputVal = "document.getElementById('"+NONSkuInput+"').value" ;
	                NONSkuInputValue = eval(NONSkuInputVal) 
	                //alert(NONSkuInputValue)
	                if (CheckForEmpty(NONSkuInputValue)==false)
	                {
	                    if (isDate(NONSkuInputValue)==false)
	                    {
                           var NOnSkutitle = "NonSkuAttribTitle"+i ;
                               NOnSkutitleVal = "document.getElementById('"+NOnSkutitle+"').value" ;	
	                           NOnSkutitleValue = eval(NOnSkutitleVal) 

	                           alert("Must Enter Date for '" + NOnSkutitleValue +"'") ;
	                           return false ;
	                    }
	                }
	               
	               } //if (NonSkuTextTypeVal=="D")
	           }
	              
	        
	        }
	    
	    }
	    
	    
	    if (dropdownnum > 0)
	    {
	        alertstring =""
	        var notallselected = false ;	
	        var notallradioselected=false ;       
	        for( var i = 1 ; i <= dropdownnum ; i++)
	        {
	            var attribtype = "slopttype"+i ;
	            attribtype = "document.getElementById('"+attribtype+"').value" ;	
	            attribtypeval = eval(attribtype)            
	            if (attribtypeval=="D")
	                {
	                    var Prodattribname = "Attrib"+i ;
	                    var Prodattribevalname = "document.getElementById('"+Prodattribname+"').selectedIndex" ;
	                    selIndex= eval(Prodattribevalname) ;	        	                   
	                    if (selIndex==0)
	                    {
	                         var Skutitle = "SkuAttribTitle"+i ;
                               SkutitleVal = "document.getElementById('"+Skutitle+"').value" ;	
	                           SkutitleValue = eval(SkutitleVal) 
	                           notallselected=true 	
	                           alertstring = alertstring + "Select Option for '" + SkutitleValue + "'\n"
	                           //alert("Select Option for '" + SkutitleValue +"'") ;
	                           //return false ;    
	                                   
	                           
	                       
	                    }
    	        } //if (attribtypeval=="D")
    	        
    	        
    	        if (attribtypeval=="R")
    	        {
    	            var checkforradio = "noradio"+i ;
    	            var checkforradio = "document.getElementById('"+checkforradio+"').value" ;
    	            var checkforradioval = eval(checkforradio)
    	            //alert(checkforradioval)
    	            if (checkforradioval==0)
    	            {
    	                notallradioselected=true ;
    	            }
    	            if (checkforradioval==1)
    	            {
    	                notallradioselected=true
    	                attribradio = eval("prodinfoform.Attrib"+i+".length") ;
    	                j = attribradio ;
    	               
    	               if (j == null)
						{
							j= 0 ;
						}
						
						if (j==0)
						{
							radiochecked = eval("prodinfoform.Attrib"+i+".checked") ;
							//alert(radiochecked) ;
							if (radiochecked)
							{
								notallradioselected=false
							}
						}
						else
						{
							for (k=0; k<j; k++)
							{
								radiochecked = eval("prodinfoform.Attrib"+i+"["+k+"].checked") ;
								if (radiochecked)
								{
									notallradioselected=false
									
								}		                                                           
							}
						}	
	                    
	                    if (notallradioselected==true)
	                    {
	                      var Skutitle = "SkuAttribTitle"+i ;
                               SkutitleVal = "document.getElementById('"+Skutitle+"').value" ;	
	                           SkutitleValue = eval(SkutitleVal) 
	                           notallselected=true 	
	                           alertstring = alertstring + "Select Option for '" + SkutitleValue + "'\n"
	                    }      	            
    	              }
    	                  	              
    	            
    	        } //if (attribtypeval=="R")
	        
	        } // if dropdown > 0
	        
	       if (notallselected)
	       {
	         alert(alertstring) ;
	         return false ;
	       }
	        //if (notallselected || notallradioselected)
	        if (notallradioselected)	    	        
	            {
	                alert("Please select all options");
	                //alert(alertstring) ;
	                return false ;
	            }
	          //return true ;
	          //return false ;
	    }

	   
	   
	   
	    return true ;
	
	}
	
function extractNumber(obj, decimalPlaces, allowNegative,beforedecimal)
{
	var temp = obj.value;
	
	// avoid changing things if already formatted correctly
	var reg0Str = '[0-9]*';
	if (decimalPlaces > 0) {
		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
	} else if (decimalPlaces < 0) {
		reg0Str += '\\.?[0-9]*';
	}
	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
	reg0Str = reg0Str + '$';
	var reg0 = new RegExp(reg0Str);
	if (reg0.test(temp)) return true;

	// first replace all non numbers
	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');

	if (allowNegative) {
		// replace extra negative
		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		var reg2 = /-/g;
		temp = temp.replace(reg2, '');
		if (hasNegative) temp = '-' + temp;
	}
	
	if (decimalPlaces != 0) {
		var reg3 = /\./g;
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			// keep only first occurrence of .
			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
			reg3Right = reg3Right.replace(reg3, '');
			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
		}
	}
	
	//temp = temp.substring(0,3) ;
	obj.value = temp ;
}
function blockNonNumbers(obj, e, allowDecimal, allowNegative,maxbeforedecimal)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	
	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	retval = true ;
	if (maxbeforedecimal > 0)
	{
		temp = obj.value ;
		
		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		var reg2 = /-/g;
		temp = temp.replace(reg2, '');
		
		if (temp.length >= maxbeforedecimal)
		{
			retval=false ;
			return retval ;				
		}
	}

	return isFirstN || isFirstD || reg.test(keychar);

}

function displaythis(what)    
		{
		var bcheckout = document.getElementById("checkout");
		var bmodify   = document.getElementById("modifybasket");
		if (what.value =="checkout")
		    {
		        bcheckout.value = "checkout"
		        bmodify.value = ""		  
		    }
		if (what.value =="modify")
		    {
		        bcheckout.value = ""
		        bmodify.value = "modifybasket"	
		    }		 
		 }
	//-->hiding

		 function getObject(obj) {
		     var theObj;
		     if (document.all) {
		         if (typeof obj == "string") {
		             return document.all(obj);
		         } else {
		             return obj.style;
		         }
		     }
		     if (document.getElementById) {
		         if (typeof obj == "string") {
		             return document.getElementById(obj);
		         } else {
		             return obj.style;
		         }
		     }
		     return null;
		 }

		 function Contchar(exittxt, texto) {
		     var exittxtObj = getObject(exittxt);
		     exittxtObj.innerHTML = texto;
		 }

		 function state_Change() {
		     // if xmlhttp shows "loaded"
		     if (xmlhttp.readyState == 4) {
		         // if "OK"
		         if (xmlhttp.status == 200) {
		             // ...some code here...
		         }
		         else {
		             alert("Problem retrieving XML data")
		         }
		     }
		 }

		 function Get_allstates(countrycode) {

		     xmlhttp = null;
		     var new_url = "Get_stateonly.asp?code=" + countrycode;

		     // code for Mozilla, etc.
		     if (window.XMLHttpRequest) {
		         xmlhttp = new XMLHttpRequest()
		     }
		     // code for IE
		     else if (window.ActiveXObject) {
		         //xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		         xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		     }
		     if (xmlhttp != null) {
		         xmlhttp.onreadystatechange = state_Change
		         xmlhttp.open("GET", new_url, false)
		         xmlhttp.send(null)
		     }
		     else {
		         alert("Your browser does not support XMLHTTP.")
		     }

		 }


		 function addOption(selectbox, text, value) {
		     var optn = document.createElement("OPTION");
		     optn.text = text;
		     optn.value = value;
		     selectbox.options.add(optn);
		 }


		 function Fixbcountry(ccode, whichone) {
		     var bbstate = document.getElementById('txtstate')
		     var btxtstatelabel = document.getElementById('txtstatelabel')
		     var bstlabel = document.getElementById('bstatelabel')
		     var bcountylabel = document.getElementById('bukcounty')
		     var bcountydrop = document.getElementById('txtcounty')
		     var bZiplabel = document.getElementById('bzipcodelabel')
		     var bbstate1 = bbstate.length;
		     //var bbstateval = bbstate.value ;    
		     // first remove all
		     for (i = bbstate1 - 1; i >= 0; i--) {
		         //bbstateval = bbstate.options[i].value        
		         bbstate.remove(i);

		     }
		     var bbaddr3 = document.getElementById('addr3')

		     if (ccode == "073") {
		         bbaddr3.style.display = '';
		         btxtstatelabel.style.display = 'none';
		         bcountydrop.style.display = '';
		         bcountylabel.style.display = '';
		         bZiplabel.innerHTML = "Postal Code";
		     }
		     else {

		         if ((ccode == "001") || (ccode == "034")) {//Now add only US/Canada States
		             Get_allstates(ccode);
		             var answer = xmlhttp.responseText;
		             allanswer = answer.split(";");
		             listloaded = true
		             for (i = 0; i < allanswer.length - 1; i++) {
		                 btstr1 = allanswer[i];

		                 btstr2 = btstr1.split("-");
		                 btstcode = btstr2[0];
		                 btstcodeName = btstr2[1];
		                 addOption(bbstate, btstcodeName, btstcode);
		             }
		             var printthis = ((ccode == "034") ? "Province" : "State")
		             bstlabel.innerHTML = printthis;
		         }
		         else {
		             addOption(bbstate, 'INTERNATIONAL', 'INT');
		             bstlabel.innerHTML = "State";
		         }
		         bbaddr3.style.display = 'none';
		         btxtstatelabel.style.display = '';
		         bcountydrop.style.display = 'none';
		         bcountylabel.style.display = 'none';

		         var printthis1 = (((ccode == "034") || (ccode == "073")) ? "Postal Code" : "Zip Code")
		         bZiplabel.innerHTML = printthis1;

		     }

		 }
		 function validateForm(billtophonereq) {

		     //var checkforcountrydrop = document.getElementById('whatbcountrytype')

		     //if (checkforcountrydrop !=null)
		     {
		         var bcountrysel = document.getElementById('billtocountry').selectedIndex;
		         var bcountryselval = document.getElementById('billtocountry').options[bcountrysel].value;
		     }
		     // else
		     {
		         //     bcountryselval=document.getElementById('billtocountry').value ;
		     }

		     var haserror = false

		     Contchar('bfname', '')
		     Contchar('blname', '')
		     Contchar('baddr1', '')
		     Contchar('bcity', '')
		     Contchar('bstate', '')
		     Contchar('bzip', '')
		     Contchar('bemail', '')
		     Contchar('bpwd', '')
		     Contchar('bpwd2', '')




		     // Begin Required Field Check
		     if (custinfoform.txtfirstname.value == "") {
		         Contchar('bfname', '(Required)')
		         haserror = true
		     }
		     if (custinfoform.txtlastname.value == "") {
		         Contchar('blname', '(Required)')
		         haserror = true
		     }
		     if (custinfoform.txtaddress1.value == "" && custinfoform.txtaddress2.value == "") {
		         Contchar('baddr1', '(Required)')
		         haserror = true
		     }
		     if (custinfoform.txtcity.value == "") {
		         Contchar('bcity', '(Required)')
		         haserror = true
		     }
		     if ((custinfoform.txtstate.value == "") && (bcountryselval != "073")) {
		         Contchar('bstate', '(Required)')
		         haserror = true
		     }
		     if (custinfoform.txtzipcode.value == "") {
		         Contchar('bzip', '(Required)')
		         haserror = true
		     }
		     if (custinfoform.txtphone.value == "" && billtophonereq == 1) {
		         Contchar('bphone', '(Required)')
		         haserror = true
		     }


		     if (custinfoform.txtemail.value == "") {
		         Contchar('bemail', '(Required)')
		         haserror = true
		     }

		     var bbphone = custinfoform.txtphone.value;

		     //var regex = /\s+/;
		     //bbphone = bbphone.replace(regex,'')
		     bbphone = bbphone.replace(/ /g, '')
		     bbphone = bbphone.replace(/-/g, '')
		     bbphone = bbphone.replace(/\(/g, '')
		     bbphone = bbphone.replace(/\)/g, '')

		     //bbphone = bbphone.replace(/^\s+|\s+$/g,"");
		     if (bbphone.length > 0) {
		         regex = /^[0-9]+$/;
		         testresult = regex.test(bbphone);
		         if (testresult == false) {
		             Contchar('bphone', '(Invalid Phone Number)')
		             haserror = true
		         }
		         else {
		             Contchar('bphone', '')
		         }

		     }

		     if (custinfoform.txtemail.value.length != 0 && !/^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/.test(custinfoform.txtemail.value)) {
		         Contchar('bemail', 'Invalid Email Address')
		         haserror = true
		     }


		     if (custinfoform.txtregpassword.value.length < 4) {
		         Contchar('bpwd', '\(password must be at least 4 characters)')
		         haserror = true
		     }
		     if (custinfoform.txtregpassword.value !== custinfoform.txtregpassword2.value) {
		         Contchar('bpwd2', '(Both passwords do not match; please retype your password in both fields)')
		         haserror = true
		     }




		     if (haserror)
		         return false;

		     return true;
		 }

		 function RedirectToAddADDress(page) {
		     var new_url = page;
		     if ((new_url != "") && (new_url != null))
		     //document.basketform.submit();
		         window.location = new_url;
		 }
		 function openlearnmore() {
		     popupWin = window.open('learnmore.asp', '', 'scrollbars,resizable,width=500,height=450');

		 }
		 function openlearnmore1() {
		     popupWin = window.open('learnmore1.asp', '', 'scrollbars,resizable,width=400,height=350');

		 }
		 function changeship() {
		     {
		         for (var i = 0; i < document.checkoutform.txtshiplist.length; i++) {
		             if (document.checkoutform.txtshiplist[i].checked) {
		                 var rad_val = document.checkoutform.txtshiplist[i].value;
		                 //alert(rad_val);
		                 window.location = "changeshipping.asp?shipmethod=" + rad_val;
		             }
		         }
		     }

		 }

		 function Contchar(entrytxt, exittxt, texto, maxchars) {
		     var entrytxtObj = getObject(entrytxt);
		     var exittxtObj = getObject(exittxt);
		     var longitud = maxchars - entrytxtObj.value.length;
		     if (longitud <= 0) {
		         longitud = 0;
		         texto = '<span class="disable"> ' + texto + ' </span>';
		         entrytxtObj.value = entrytxtObj.value.substr(0, maxchars);
		     }
		     exittxtObj.innerHTML = texto.replace("{CHAR}", longitud);
		 }
		 function makePOSTRequest(params) {
		     //alert(params)
		     //var new_url="SaveCheckoutInfo.asp" ;
		     if (window.XMLHttpRequest) {
		         xmlhttp = new XMLHttpRequest()
		     }
		     // code for IE
		     else if (window.ActiveXObject) {
		         xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		     }

		     if (xmlhttp != null) {
		         xmlhttp.onreadystatechange = state_Change
		         xmlhttp.open("POST", "SaveCheckoutInfo.asp", false);
		         xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		         //xmlhttp.setRequestHeader("Content-type", "text/xml");
		         xmlhttp.setRequestHeader("Content-length", params.length);
		         xmlhttp.setRequestHeader("Connection", "close");
		         xmlhttp.send(params);
		         setTimeout('', 5000);
		     }
		     else {
		         alert("Your browser does not support XMLHTTP.")
		     }

		 }
		 function state_Change() {
		     // if xmlhttp shows "loaded"
		     if (xmlhttp.readyState == 4) {
		         //alert(PPxmlhttp.statusText)
		         // if "OK"
		         if (xmlhttp.status == 200) {
		             // ...some code here...
		         }
		         else {
		             alert("Problem retrieving XML data")
		         }
		     }
		 }
		 function Process() {

		     var p_type = document.getElementById("payment_type").value;

		     if (p_type == "Credit Card") {

		         var myCardNo = document.getElementById("txtcc_number").value;
		         var myCardType = document.getElementById("cc_type").value;
		         var cctypesplit = myCardType.split("/", 2)[1]

		         if (myCardNo.length == 0) {
		             alert("Please enter Card Number")
		             return false;

		         }

		         if (cctypesplit.length > 0) {

		             retval = checkCreditCard(myCardNo, cctypesplit)
		             if (retval == false) {
		                 alert("Invalid Card Number")
		                 return false;
		             }
		         }

		     }

		     if (p_type == "PP") {
		         //save all these values..
		         poststr = ""
		         var hasskey = document.getElementById("whatsourcekey");

		         //source key
		         if (hasskey != null) {
		             var skeysel = document.getElementById('whatsourcekey').selectedIndex;
		             var skeyselvalue = document.getElementById('whatsourcekey').options[skeysel].value;
		             poststr = "skeysel=" + encodeURI(skeyselvalue)
		         }
		         else {
		             poststr = "skeysel="
		         }

		         //ship ahead
		         var isRadioPresent = document.getElementById('ship_ahead');

		         if (isRadioPresent != null) {
		             var ship_aheadRadioLength = checkoutform.ship_ahead.length;
		             j = ship_aheadRadioLength;
		             for (k = 0; k < j; k++) {
		                 radiochecked = checkoutform.ship_ahead[k].checked;

		                 if (radiochecked) {
		                     radiocheckedValue = checkoutform.ship_ahead[k].value;
		                 }
		             }
		         }
		         else {
		             radiocheckedValue = 0;
		         }

		         //shipping instr
		         var hasordermemo = document.getElementById("ordermemo");
		         if (hasordermemo != null) {
		             var ordermemoval = hasordermemo.value;
		         }
		         else {
		             var ordermemoval = ""
		         }


		         // order hold date		
		         var hasorderhold = document.getElementById("orderhold");
		         if (hasorderhold != null) {
		             var orderholdval = hasorderhold.value;
		         }
		         else {
		             var orderholdval = "";
		         }


		         //Order comments
		         var hasmemofield1 = document.getElementById("memo_field1");
		         if (hasmemofield1 != null) {
		             var memo_field1Val = hasmemofield1.value;
		         }
		         else {
		             var memo_field1Val = "";
		         }

		         var hasmemofield2 = document.getElementById("memo_field2");
		         if (hasmemofield2 != null) {
		             var memo_field2Val = hasmemofield2.value;
		         }
		         else {
		             var memo_field2Val = "";
		         }

		         var hasmemofield3 = document.getElementById("memo_field3");
		         if (hasmemofield3 != null) {
		             var memo_field3Val = hasmemofield3.value;
		         }
		         else {
		             var memo_field3Val = "";
		         }

		         var poststr = poststr +
					"&Ship_aheadflag=" + radiocheckedValue +
                    "&orderholddt=" + encodeURI(orderholdval) +
					"&ordermemo1=" + encodeURI(memo_field1Val) +
					"&ordermemo2=" + encodeURI(memo_field2Val) +
					"&ordermemo3=" + encodeURI(memo_field3Val) +
					"&orderfullfill=" + encodeURI(ordermemoval)

		         //alert(poststr);
		         makePOSTRequest(poststr);


		         //sandbox
		         //document.checkoutform.action='https://www.sandbox.paypal.com/cgi-bin/webscr'		

		         //live
		         document.checkoutform.action = 'https://www.paypal.com/cgi-bin/webscr'

		         return true;

		     }

		     return true;
		 }

		 var panes = new Array();

		 function setupPanes(containerId, defaultTabId) {
		     // go through the DOM, find each tab-container
		     // set up the panes array with named panes
		     // find the max height, set tab-panes to that height
		     panes[containerId] = new Array();
		     var maxHeight = 0; var maxWidth = 0;
		     var container = document.getElementById(containerId);
		     var paneContainer = container.getElementsByTagName("div")[0];
		     var paneList = paneContainer.childNodes;
		     for (var i = 0; i < paneList.length; i++) {
		         var pane = paneList[i];
		         if (pane.nodeType != 1) continue;
		         if (pane.offsetHeight > maxHeight) maxHeight = pane.offsetHeight;
		         if (pane.offsetWidth > maxWidth) maxWidth = pane.offsetWidth;
		         panes[containerId][pane.id] = pane;
		         pane.style.display = "none";
		     }
		     paneContainer.style.height = maxHeight + "px";
		     paneContainer.style.width = maxWidth + "px";
		     document.getElementById(defaultTabId).onclick();
		 }

		 function showPane(paneId, activeTab) {
		     // make tab active class
		     // hide other panes (siblings)
		     // make pane visible

		     var paytype = document.getElementById('payment_type')
		     var PaybyPoints = document.getElementById('applypoints')
		     var PaybyGC = document.getElementById('applygc')

		     if (paneId == "pane1") {
		         paytype.value = "Credit Card"
		         PaybyPoints.value = 0
		         PaybyGC.value = 0
		     }

		     if (paneId == "pane2") {
		         paytype.value = "EC"
		         PaybyPoints.value = 0
		         PaybyGC.value = 0
		     }
		     if (paneId == "pane3") {
		         paytype.value = "COD"
		         PaybyPoints.value = 0
		         PaybyGC.value = 0
		     }
		     if (paneId == "pane4") {
		         paytype.value = "Terms"
		         PaybyPoints.value = 0
		         PaybyGC.value = 0
		     }
		     if (paneId == "pane5") {
		         paytype.value = "PP"
		         PaybyPoints.value = 0
		         PaybyGC.value = 0
		     }
		     if (paneId == "pane6") {
		         paytype.value = "CK"
		         PaybyPoints.value = 1
		         PaybyGC.value = 0
		     }
		     if (paneId == "pane7") {
		         paytype.value = "CK"
		         PaybyPoints.value = 0
		         PaybyGC.value = 1
		     }


		     // work out which container this tab is part of. could also bounce on parent node
		     for (var con in panes) {
		         activeTab.blur();
		         activeTab.className = "tab-active";
		         if (panes[con][paneId] != null) { // tab and pane are members of this container
		             var pane = document.getElementById(paneId);
		             pane.style.display = "block";
		             var container = document.getElementById(con);
		             var tabs = container.getElementsByTagName("ul")[0];
		             var tabList = tabs.getElementsByTagName("a")
		             for (var i = 0; i < tabList.length; i++) {
		                 var tab = tabList[i];
		                 if (tab != activeTab) tab.className = "tab-disabled";
		             }
		             for (var i in panes[con]) {
		                 var pane = panes[con][i];
		                 if (pane == undefined) continue;
		                 if (pane.id == paneId) continue;
		                 pane.style.display = "none"
		             }
		         }
		     }
		     return false;
		 }
		 function getObject(obj) {
		     var theObj;
		     if (document.all) {
		         if (typeof obj == "string") {
		             return document.all(obj);
		         } else {
		             return obj.style;
		         }
		     }
		     if (document.getElementById) {
		         if (typeof obj == "string") {
		             return document.getElementById(obj);
		         } else {
		             return obj.style;
		         }
		     }
		     return null;
		 }
		 function extractNumber(obj, decimalPlaces, allowNegative, beforedecimal) {
		     var temp = obj.value;

		     // avoid changing things if already formatted correctly
		     var reg0Str = '[0-9]*';
		     if (decimalPlaces > 0) {
		         reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
		     } else if (decimalPlaces < 0) {
		         reg0Str += '\\.?[0-9]*';
		     }
		     reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
		     reg0Str = reg0Str + '$';
		     var reg0 = new RegExp(reg0Str);
		     if (reg0.test(temp)) return true;

		     // first replace all non numbers
		     var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
		     var reg1 = new RegExp(reg1Str, 'g');
		     temp = temp.replace(reg1, '');

		     if (allowNegative) {
		         // replace extra negative
		         var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		         var reg2 = /-/g;
		         temp = temp.replace(reg2, '');
		         if (hasNegative) temp = '-' + temp;
		     }

		     if (decimalPlaces != 0) {
		         var reg3 = /\./g;
		         var reg3Array = reg3.exec(temp);
		         if (reg3Array != null) {
		             // keep only first occurrence of .
		             //  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
		             var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
		             reg3Right = reg3Right.replace(reg3, '');
		             reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
		             temp = temp.substring(0, reg3Array.index) + '.' + reg3Right;
		         }
		     }

		     //temp = temp.substring(0,3) ;
		     obj.value = temp;
		 }
		 function blockNonNumbers(obj, e, allowDecimal, allowNegative, maxbeforedecimal) {
		     var key;
		     var isCtrl = false;
		     var keychar;
		     var reg;

		     if (window.event) {
		         key = e.keyCode;
		         isCtrl = window.event.ctrlKey
		     }
		     else if (e.which) {
		         key = e.which;
		         isCtrl = e.ctrlKey;
		     }

		     if (isNaN(key)) return true;

		     keychar = String.fromCharCode(key);

		     // check for backspace or delete, or if Ctrl was pressed
		     if (key == 8 || isCtrl) {
		         return true;
		     }


		     reg = /\d/;
		     var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
		     var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;

		     retval = true;
		     if (maxbeforedecimal > 0) {
		         temp = obj.value;

		         var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		         var reg2 = /-/g;
		         temp = temp.replace(reg2, '');

		         if (temp.length >= maxbeforedecimal) {
		             retval = false;
		             return retval;
		         }
		     }

		     return isFirstN || isFirstD || reg.test(keychar);

		 }

		 /*============================================================================*/



		 function checkCreditCard(cardnumber, cardname) {

		     // Array to hold the permitted card characteristics
		     var cards = new Array();

		     // Define the cards we support. You may add addtional card types.

		     //  Name:      As in the selection box of the form - must be same as user's
		     //  Length:    List of possible valid lengths of the card number for the card
		     //  prefixes:  List of possible prefixes for the card
		     //  checkdigit Boolean to say whether there is a check digit

		     cards[0] = { name: "V",
		         length: "13,16",
		         prefixes: "4",
		         checkdigit: true
		     };
		     cards[1] = { name: "M",
		         length: "16",
		         prefixes: "51,52,53,54,55",
		         checkdigit: true
		     };
		     cards[2] = { name: "C",
		         length: "14,16",
		         prefixes: "300,301,302,303,304,305,36,38,55",
		         checkdigit: true
		     };
		     cards[3] = { name: "CarteBlanche",
		         length: "14",
		         prefixes: "300,301,302,303,304,305,36,38",
		         checkdigit: true
		     };
		     cards[4] = { name: "A",
		         length: "15",
		         prefixes: "34,37",
		         checkdigit: true
		     };
		     cards[5] = { name: "D",
		         length: "16",
		         prefixes: "6011,650",
		         checkdigit: true
		     };
		     cards[6] = { name: "J",
		         length: "15,16",
		         prefixes: "3,1800,2131",
		         checkdigit: true
		     };
		     cards[7] = { name: "enRoute",
		         length: "15",
		         prefixes: "2014,2149",
		         checkdigit: true
		     };
		     cards[8] = { name: "Solo",
		         length: "16,18,19",
		         prefixes: "6334, 6767",
		         checkdigit: true
		     };
		     cards[9] = { name: "Switch",
		         length: "16,18,19",
		         prefixes: "4903,4905,4911,4936,564182,633110,6333,6759",
		         checkdigit: true
		     };
		     cards[10] = { name: "Maestro",
		         length: "16,18",
		         prefixes: "5020,6",
		         checkdigit: true
		     };
		     cards[11] = { name: "VisaElectron",
		         length: "16",
		         prefixes: "417500,4917,4913",
		         checkdigit: true
		     };

		     // Establish card type
		     var cardType = -1;
		     for (var i = 0; i < cards.length; i++) {

		         // See if it is this card (ignoring the case of the string)
		         if (cardname.toLowerCase() == cards[i].name.toLowerCase()) {
		             cardType = i;
		             break;
		         }
		     }

		     // If card type not found, report an error
		     if (cardType == -1) {
		         ccErrorNo = 0;
		         return false;
		     }

		     // Ensure that the user has provided a credit card number
		     if (cardnumber.length == 0) {
		         ccErrorNo = 1;
		         return false;
		     }

		     // Now remove any spaces from the credit card number
		     cardnumber = cardnumber.replace(/\s/g, "");

		     // Check that the number is numeric
		     var cardNo = cardnumber
		     var cardexp = /^[0-9]{13,19}$/;
		     if (!cardexp.exec(cardNo)) {
		         ccErrorNo = 2;
		         return false;
		     }

		     // Now check the modulus 10 check digit - if required
		     if (cards[cardType].checkdigit) {
		         var checksum = 0;                                  // running checksum total
		         var mychar = "";                                   // next char to process
		         var j = 1;                                         // takes value of 1 or 2

		         // Process each digit one by one starting at the right
		         var calc;
		         for (i = cardNo.length - 1; i >= 0; i--) {

		             // Extract the next digit and multiply by 1 or 2 on alternative digits.
		             calc = Number(cardNo.charAt(i)) * j;

		             // If the result is in two digits add 1 to the checksum total
		             if (calc > 9) {
		                 checksum = checksum + 1;
		                 calc = calc - 10;
		             }

		             // Add the units element to the checksum total
		             checksum = checksum + calc;

		             // Switch the value of j
		             if (j == 1) { j = 2 } else { j = 1 };
		         }

		         // All done - if checksum is divisible by 10, it is a valid modulus 10.
		         // If not, report an error.
		         if (checksum % 10 != 0) {
		             ccErrorNo = 3;
		             return false;
		         }
		     }

		     // The following are the card-specific checks we undertake.
		     var LengthValid = false;
		     var PrefixValid = false;
		     var undefined;

		     // We use these for holding the valid lengths and prefixes of a card type
		     var prefix = new Array();
		     var lengths = new Array();

		     // Load an array with the valid prefixes for this card
		     prefix = cards[cardType].prefixes.split(",");

		     // Now see if any of them match what we have in the card number
		     for (i = 0; i < prefix.length; i++) {
		         var exp = new RegExp("^" + prefix[i]);
		         if (exp.test(cardNo)) PrefixValid = true;
		     }

		     // If it isn't a valid prefix there's no point at looking at the length
		     if (!PrefixValid) {
		         ccErrorNo = 3;
		         return false;
		     }

		     // See if the length is valid for this card
		     lengths = cards[cardType].length.split(",");
		     for (j = 0; j < lengths.length; j++) {
		         if (cardNo.length == lengths[j]) LengthValid = true;
		     }

		     // See if all is OK by seeing if the length was valid. We only check the 
		     // length if all else was hunky dory.
		     if (!LengthValid) {
		         ccErrorNo = 4;
		         return false;
		     };

		     // The credit card is in the required format.
		     return true;
		 }

		 /*============================================================================*/

		 var weekend = [0, 6]; var weekendColor = "#e0e0e0"; var sShowWeekend = 1; var gNow = new Date(); var ggWinCal; var DAYS_OF_WEEK = 7; gNow = new Date(gNow.getFullYear(), gNow.getMonth(), gNow.getDate());
		 var DayOfWeek = new Array('S', 'M', 'T', 'W', 'T', 'F', 'S');
		 Calendar.Months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
		 Calendar.DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
		 Calendar.lDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

		 function Calendar(p_item, p_WinCal, p_month, p_year, p_format) {
		     if ((p_month == null) && (p_year == null)) return;
		     if (p_WinCal == null)
		         this.gWinCal = ggWinCal;
		     else
		         this.gWinCal = p_WinCal;

		     if (p_month == null) {
		         this.gMonthName = null;
		         this.gMonth = null;
		     } else {
		         this.gMonthName = Calendar.get_month(p_month);
		         this.gMonth = new Number(p_month);
		     }

		     var vUserDate = eval("window.document." + p_item + ".value");
		     this.gYear = p_year;
		     this.gFormat = p_format;
		     this.gReturnItem = p_item;
		     this.SelectedDate = vUserDate;
		 }

		 Calendar.get_month = Calendar_get_month;
		 Calendar.get_daysofmonth = Calendar_get_daysofmonth;
		 Calendar.calc_month_year = Calendar_calc_month_year;

		 function Calendar_get_month(monthNo) {
		     return Calendar.Months[monthNo];
		 }

		 function Calendar_get_daysofmonth(monthNo, p_year) {
		     if ((p_year % 4) == 0) {
		         if ((p_year % 100) == 0 && (p_year % 400) != 0) return Calendar.DOMonth[monthNo];
		         return Calendar.lDOMonth[monthNo];
		     } else
		         return Calendar.DOMonth[monthNo];
		 }

		 function Calendar_calc_month_year(p_Month, p_Year, incr) {
		     var ret_arr = new Array();
		     if (incr == -1) { if (p_Month == 0) { ret_arr[0] = 11; ret_arr[1] = parseInt(p_Year) - 1; } else { ret_arr[0] = parseInt(p_Month) - 1; ret_arr[1] = parseInt(p_Year); } }
		     else if (incr == 1) { if (p_Month == 11) { ret_arr[0] = 0; ret_arr[1] = parseInt(p_Year) + 1; } else { ret_arr[0] = parseInt(p_Month) + 1; ret_arr[1] = parseInt(p_Year); } }
		     return ret_arr;
		 }

		 new Calendar();

		 Calendar.prototype.getMonthlyCalendarCode = function () {
		     var vCode = ""; var vHeader_Code = ""; var vData_Code = "";
		     vHeader_Code = this.cal_header();
		     vData_Code = this.cal_data();
		     vCode = vCode + vHeader_Code + vData_Code + "</TABLE>";
		     return vCode;
		 }

		 Calendar.prototype.show = function () {
		     var vCode = ""; var a = p_item;
		     this.gWinCal.document.open();
		     this.wwrite("<html><head><META HTTP-EQUIV='PRAGMA' CONTENT='NO-CACHE'><title>Calendar</title>");
		     this.wwrite("<style type='text/css'>" +
				"TABLE{ BACKGROUND-COLOR: White}" +
				"TD{ text-align: center; FONT-SIZE: 9pt;COLOR: #333333; font-family:arial;}" +
				".backclr {BACKGROUND-COLOR: #08416C}" +
				".month { font-family:arial; font-size: 10pt;FONT-WEIGHT: bold; color:#FFFFFF}" +
				".daysofweek {font-family:arial; font-size: 9pt; color:#000000}" +
				".otherday {FONT-SIZE: 9pt;COLOR: #CCCCCC;FONT-FAMILY: Arial, Helvetica, sans-serif;}" +
				"A.arrow {font-family:arial; font-size: 10pt;  color:#FFFFFF; text-decoration: none;}" +
				"A.day {FONT-SIZE: 9pt;COLOR: #000000;FONT-WEIGHT: bold; FONT-FAMILY: Arial, Helvetica, sans-serif;text-decoration: none;}" +
				"A.day:hover {FONT-SIZE: 9pt;COLOR: #000000;FONT-WEIGHT: bold; BACKGROUND-COLOR: #CCCCCC; FONT-FAMILY: Arial, Helvetica, sans-serif;text-decoration: none;}" +
				"</style>");
		     this.wwrite("<SCR" + "IPT  language='JavaScript1.1'  src='createAjaxObj.js' type='text/javascript'></sc" + "ript>");
		     this.wwrite("</head>");
		     this.wwrite("<body text='black' topmargin='12' leftmargin='5' marginwidth='5' marginheight='8'>");
		     var prevMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, -1);
		     var prevMM = prevMMYYYY[0];
		     var prevYYYY = prevMMYYYY[1];
		     var vSpacer = "<img src='images/clear.gif' border='0' width='25' height='1'>";
		     var nextMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, 1);
		     var nextMM = nextMMYYYY[0];
		     var nextYYYY = nextMMYYYY[1];
		     this.wwrite("<TABLE border='0' CELLSPACING='0' CELLPADDING='1'>");
		     this.wwrite("<TR class='backclr'><td>" + vSpacer + "</td><td>" + vSpacer + "</td><td>" + vSpacer + "</td><td>" + vSpacer + "</td><td>" + vSpacer + "</td><td>" + vSpacer + "</td><td>" + vSpacer + "</td></tr>");
		     this.wwrite("<TR class='backclr'>");
		     ((this.gMonth <= gNow.getMonth() && this.gYear <= gNow.getFullYear()) ? this.wwrite("<TD><img src='images/clear.gif' border='0'></TD>") :
		this.wwrite("<TD><A class='arrow' HREF=\"" + "javascript:window.opener.Build('" + this.gReturnItem + "', '" + prevMM + "', '" + prevYYYY + "', '" + this.gFormat + "');" +
			"\"><<<\/A></TD>"));
		     this.wwrite("<TD class='month' colspan='5'>" + this.gMonthName + "&nbsp;" + this.gYear + "</TD>");
		     this.wwrite("<TD><A class='arrow' HREF=\"" + "javascript:window.opener.Build('" + this.gReturnItem + "', '" + nextMM + "', '" + nextYYYY + "', '" + this.gFormat + "');" +
		"\">>><\/A></TD>");
		     vCode = this.getMonthlyCalendarCode();
		     this.wwrite(vCode);
		     this.wwrite("<br>");
		     this.wwrite("<center>");
		     this.wwrite("<a class='daysofweek' href=\"javascript:self.close();\">Close<\/a>");
		     this.wwrite("</center>");
		     this.wwrite("</body></html>");
		     this.gWinCal.document.close();
		 }

		 Calendar.prototype.wwrite = function (wtext) {
		     this.gWinCal.document.writeln(wtext);
		 }

		 Calendar.prototype.wwriteA = function (wtext) {
		     this.gWinCal.document.write(wtext);
		 }

		 Calendar.prototype.cal_header = function () {
		     var vCode = "";
		     for (index = 0; index < DAYS_OF_WEEK; index++) {
		         vCode = vCode + "<TD class='daysofweek' height='10'>" + DayOfWeek[index] + "</TD>";
		     }
		     vCode = "<TR>" + vCode + "</TR>";
		     vCode = vCode + "<TR><TD colspan='7' BGCOLOR='#CCCCCCC'><img src='images/clear.gif' height='1' border='0'></TD></TR>";
		     return vCode;
		 }

		 Calendar.prototype.cal_data = function () {
		     var vDate = new Date();
		     vDate.setDate(1);
		     vDate.setMonth(this.gMonth);
		     vDate.setFullYear(this.gYear);
		     var vFirstDay = vDate.getDay();
		     var vDay = 1;
		     var vLastDay = Calendar.get_daysofmonth(this.gMonth, this.gYear);
		     var vOnLastDay = 0;
		     var vCode = "";
		     var vFlowDate = new Date();

		     vCode = vCode + "<TR>";
		     for (i = 0; i < vFirstDay; i++) {
		         vCode = vCode + "<TD "; if (sShowWeekend != 1) vCode = vCode + this.write_weekend_string(i);
		         vCode = vCode + ">&nbsp;</TD>";
		     }

		     for (j = vFirstDay; j < 7; j++) {
		         vFlowDate = new Date(this.gYear, this.gMonth, vDay);

		         if (sShowWeekend == 1) {
		             vCode = vCode + "<TD  " + this.format_cell(vDay) + ">";
		             if (vFlowDate < gNow) { vCode = vCode + "<FONT COLOR='#808080'>" + vDay + "</FONT>"; }
		             else {
		                 vCode = vCode + "<A class='day' HREF='#' " +
					"onClick=\"self.opener.document." + this.gReturnItem + ".value='" +
		                 //this.format_data(vDay) + "';window.close(); "+((need_submit==true) ? "self.opener.document.basketform.submit();" : " ")+ " \">" + vDay +
					this.format_data(vDay) + "';window.close(); " + ((need_submit == true) ? "javascript:Changeshipdate(" + p_item_id + ",'" + this.format_data(vDay) + "');" : " ") + "\">" + vDay +
				"</A></TD>";
		             }
		         }
		         else {

		             vCode = vCode + "<TD " + this.format_cell(vDay) + " " + this.write_weekend_string(j) + ">" + (this.isWeekend(j) ? (vDay + "</TD>") :
				(((vFlowDate < gNow) ? "<FONT COLOR='#808080'>" + vDay + "</FONT>" :
				"<A  class='day' HREF='#' " +
					"onClick=\"self.opener.document." + this.gReturnItem + ".value='" +
		             //this.format_data(vDay) + "';window.close(); "+((need_submit==true) ? "self.opener.document.basketform.submit();" : " ")+ "\">" + vDay +
					this.format_data(vDay) + "';window.close(); " + ((need_submit == true) ? "javascript:Changeshipdate(" + p_item_id + ",'" + this.format_data(vDay) + "');" : " ") + "\">" + vDay +
				"</A>") +
				"</TD>"));
		         }
		         vDay = vDay + 1;
		     }
		     vCode = vCode + "</TR>";

		     for (k = 2; k < 7; k++) {
		         vCode = vCode + "<TR>";

		         for (j = 0; j < 7; j++) {
		             vFlowDate = new Date(this.gYear, this.gMonth, vDay);
		             if (sShowWeekend == 1) {
		                 vCode = vCode + "<TD " + this.format_cell(vDay) + ">";
		                 if (vFlowDate < gNow) {
		                     vCode = vCode + "<FONT COLOR='#808080'>" + vDay + "</FONT>";
		                 }
		                 else {
		                     vCode = vCode + "<A  class='day'  HREF='#' onClick=\"self.opener.document." + this.gReturnItem + ".value='" +
		                     //this.format_data(vDay) + "';window.close(); "+((need_submit==true) ? "self.opener.document.basketform.submit();" : " ")+"\">" + vDay + "</A>";
							this.format_data(vDay) + "';window.close(); " + ((need_submit == true) ? "javascript:Changeshipdate(" + p_item_id + ",'" + this.format_data(vDay) + "');" : " ") + "\">" + vDay + "</A>";
		                 }
		                 vCode = vCode + "</TD>";
		             }

		             else {
		                 vCode = vCode + "<TD " + this.format_cell(vDay) + " " + this.write_weekend_string(j) + ">" + (this.isWeekend(j) ? (vDay) :
		                 //( (vFlowDate < gNow) ? "<FONT COLOR='#808080'>" + vDay + "</FONT>" : "<A  class='day'  HREF='#' onClick=\"self.opener.document." + this.gReturnItem + ".value='" +	this.format_data(vDay) + "';window.close(); "+((need_submit==true) ? "self.opener.document.basketform.submit();" : " ")+"\">" + vDay +	"</A>"));
				((vFlowDate < gNow) ? "<FONT COLOR='#808080'>" + vDay + "</FONT>" : "<A  class='day'  HREF='#' onClick=\"self.opener.document." + this.gReturnItem + ".value='" + this.format_data(vDay) + "';window.close(); " + ((need_submit == true) ? "javascript:Changeshipdate(" + p_item_id + ",'" + this.format_data(vDay) + "');" : " ") + "\">" + vDay + "</A>"));
		                 vCode = vCode + "</TD>";

		             }
		             vDay = vDay + 1;

		             if (vDay > vLastDay) {
		                 vOnLastDay = 1;
		                 break;
		             }
		         }
		         if (j == 6)
		             vCode = vCode + "</TR>";
		         if (vOnLastDay == 1)
		             break;
		     }
		     for (m = 1; m < (7 - j); m++) { vCode = vCode + "<TD class='otherday'><img src='images/clear.gif' width='1' border='0'></TD>"; }
		     return vCode;
		 }

		 Calendar.prototype.format_cell = function (vday) {
		     if ((this.SelectedDate.length == 0) || (!validateUSDate(this.SelectedDate))) return "''";
		     var vUSDate = new Date(this.SelectedDate);
		     var vUSDay = vUSDate.getDate();
		     var vUSMonth = vUSDate.getMonth();
		     var vUSYear = vUSDate.getFullYear();
		     if (vday == vUSDay && this.gMonth == vUSMonth && this.gYear == vUSYear) return " BGCOLOR='#9D9D9D' ";
		     else return ' ';
		 }
		 Calendar.prototype.write_weekend_string = function (vday) {
		     var i;
		     for (i = 0; i < weekend.length; i++) {
		         if (vday == weekend[i])
		             return (" BGCOLOR=\"" + weekendColor + "\"");
		     }
		     return ' ';
		 }

		 Calendar.prototype.isWeekend = function (vday) {
		     var i;
		     for (i = 0; i < weekend.length; i++) {
		         if (vday == weekend[i])
		             return true;
		     }
		     return false;
		 }


		 Calendar.prototype.format_data = function (p_day) {
		     var vData;
		     var vMonth = 1 + this.gMonth;
		     vMonth = (vMonth.toString().length < 2) ? "0" + vMonth : vMonth;
		     var vMon = Calendar.get_month(this.gMonth).substr(0, 3).toUpperCase();
		     var vFMon = Calendar.get_month(this.gMonth).toUpperCase();
		     var vY4 = new String(this.gYear);
		     var vY2 = new String(this.gYear.substr(2, 2));
		     var vDD = (p_day.toString().length < 2) ? "0" + p_day : p_day;

		     vData = vMonth + "\/" + vDD + "\/" + vY4;
		     return vData;
		 }

		 function Build(p_item, p_month, p_year, p_format) {
		     var p_WinCal = ggWinCal;
		     gCal = new Calendar(p_item, p_WinCal, p_month, p_year, p_format);
		     gCal.show();
		 }

		 function show_calendar() {
		     /*
		     sShowWeekend = arguments[0];
		     p_item = arguments[1];
		     if (arguments[2] == null)
		     p_month = new String(gNow.getMonth());
		     else
		     p_month = arguments[3];
		     if (arguments[3] == "" || arguments[3] == null)
		     p_year = new String(gNow.getFullYear().toString());
		     else
		     p_year = arguments[3];
		     if (arguments[3] == null)
		     p_format = "MM/DD/YYYY";
		     else
		     p_format = arguments[4];
		     */
		     sShowWeekend = 0;
		     p_item = arguments[0];
		     p_month = new String(gNow.getMonth());
		     p_year = new String(gNow.getFullYear().toString());
		     p_format = "MM/DD/YYYY";

		     p_string = new String(p_item);
		     p_basket_string = p_string.substr(0, 10);

		     p_item_id = arguments[1]

		     need_submit = false;

		     if (arguments[1] == null) {
		         need_submit = false;
		     }
		     else {
		         need_submit = true;
		     }

		     /*
		     if (p_basket_string == "basketform")
		     {
		     need_submit= true ;
		     }
		     */



		     vWinCal = window.open("", "CalendarDemo", "width=200,height=195,status=no,resizable=no,top=200,left=200");
		     //vWinCal = window.open("", "CalendarDemo", "width=500,height=500,status=no,resizable=no,top=200,left=200");
		     vWinCal.opener = self;
		     vWinCal.focus();
		     ggWinCal = vWinCal;
		     Build(p_item, p_month, p_year, p_format);
		 }

		 function validateUSDate(strValue) {
		     var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
		     if (!objRegExp.test(strValue)) return false; else {
		         var strSeparator = strValue.substring(2, 3); var arrayDate = strValue.split(strSeparator);
		         var arrayLookup = { '01': 31, '03': 31, '04': 30, '05': 31, '06': 30, '07': 31, '08': 31, '09': 30, '10': 31, '11': 30, '12': 31 }
		         var intDay = parseInt(arrayDate[1]); if (arrayLookup[arrayDate[0]] != null) { if (intDay <= arrayLookup[arrayDate[0]] && intDay != 0) return true; } var intYear = parseInt(arrayDate[2]); var intMonth = parseInt(arrayDate[0]); if (((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <= 28)) && intDay != 0) return true;
		     } return false;
		 }

