/*
(C) Copyright MarketLive. 2006. All rights reserved.
MarketLive is a trademark of MarketLive, Inc.
Warning: This computer program is protected by copyright law and international treaties.
Unauthorized reproduction or distribution of this program, or any portion of it, may result
in severe civil and criminal penalties, and will be prosecuted to the maximum extent
possible under the law.
*/
var win = null;
function flyopen(width, height){

    width = (width && !isNaN(width))? width:null;
    height = (height && !isNaN(height))? height:null;
    var winURL = (arguments[2])? arguments[2]:null;
    var winName = (arguments[3])? arguments[3]:"generic";

	//only launch the window if we've got a width, height and url
	if (width && height && winURL){
        var ieIncrement = ((navigator.appName+"").indexOf("Netscape") == -1)? 15:0;
        eval(winName+"=window.open('"+ winURL +"','"+ winName +"','resizable=yes,scrollbars=yes,width="+ (width + ieIncrement) +",height="+ (height + ieIncrement) +",top=5,left=75')");
        eval("window."+ winName +".focus()");
	}
}
function flyOverlay(url,wwidth,wheight,wresize,wshow,whide) {
	// Reuse the existing window if it is already created on this page.
	if(win ==null) {
		win = new Window({className:'pqv',width:wwidth,height:wheight,zIndex:10000,resizable:wresize,showEffect:wshow,hideEffect:whide,wiredDrag:true,minimizable:false,maximizable:false,effectOptions:{duration: 0.5}});
	}
	
	// Get the window HTML content using AJAX.
	win.setAjaxContent(url, {method: 'get'}, true);
	win.showCenter(true);
	//win.setDestroyOnClose();
}

function redirectNow(url){
   		window.location.href=url;
  }
  function redirectToOpener(url){
 //alert(url);
     		//parent.document.location=url;
     		parent.window.location.href=url;
     		
  }
    function redirectEditToOpener(url){
    parent.window.location=url;
	//   alert(window.name);
	//   alert(url);
   document.getElementById(window.name).closeP();
       		//parent.document.location=url;
       		//parent.window.location.href=url;
       		
  }
function submitNow(frm){
var tmp=(frm.catalogSourceCode.value).length;
		if(tmp == 0)
			alert("Please enter Catalog Dept Number");
		else	
			frm.submit();
}
 function submitBasketFreeProductNow(){
		var codeval = document.basketFreeProductForm.catalogSourceCode.value;
		var URL="/basketFreeProduct.do?method=submit&catalogSourceCode=" + codeval;
		flyOverlay(URL,600,400,true,Effect.Appear,Effect.Fade);
 }
 function submitBasketSurvey(){
 		var URL="/basketSurvey.do";
 		flyOverlay(URL,600,400,true,Effect.Appear,Effect.Fade);
 }
 
 function submitBillAddressNow(url){
	 var frm = document.forms['checkoutForm'].elements;
	 var ind = frm['qasAddressSearchForm.moniker'].selectedIndex;
	 var selected = frm['qasAddressSearchForm.moniker'].options[ind].value;
	 var finalSelectedURL=url+"&qasAddressSearchForm.moniker="+selected;
	 // finalSelectedURL="/basket.do";
	//alert('1'+finalSelectedURL);
			window.location.href=finalSelectedURL;
      		
  }
  function submitAccntAddressNow(url){
  	 var frm = document.forms['accountRegisterForm'].elements;
  	 var ind = frm['qasAddressSearchForm.moniker'].selectedIndex;
  	 var selected = frm['qasAddressSearchForm.moniker'].options[ind].value;
  	 var finalSelectedURL=url+"&qasAddressSearchForm.moniker="+selected;
  	 //alert('2'+finalSelectedURL);
  			window.location.href=finalSelectedURL;
  }
  function submitAccntRangeAddress(url,selectedMoniker){
    	 var finalSelectedURL=url+"&qasAddressSearchForm.moniker="+selectedMoniker;
      // parent.document.location.href=finalSelectedURL;
      //alert('3'+finalSelectedURL);
      window.location.href=finalSelectedURL;
  }
  function submitBillRangeAddress(url,selectedMoniker){
      	 var finalSelectedURL=url+"&qasAddressSearchForm.moniker="+selectedMoniker;
        // window.location.href=finalSelectedURL;
        //alert('4'+finalSelectedURL);
        parent.document.location=finalSelectedURL;
  }
	function submitAccntAddressBack(url){
		//alert('url:'+url);
		//alert('parent.window.location.href:'+parent.window.location.href);
		//alert('usethis indix:'+ (url.indexOf('useThis=true')));
		if(parent.window.location.href.indexOf('checkout/billing.do') > 5 && url.indexOf('useThis=true') == -1){
			//alert('/checkout/billing.do?method=view');
			parent.document.location = '/checkout/billing.do?method=view';
		}else{
			var finalSelectedURL=url+"&qasAddressSearchForm.moniker=null";
			//window.location.href=finalSelectedURL;
			//alert('5'+finalSelectedURL);
			parent.document.location=finalSelectedURL;
		}
	}
  
   function validateSourceCode(){
        	var sourceCode = document.getElementById('sourceCode');
            if(trimAll(sourceCode.value)==''){
            	alert('Please enter a Coupon Code');
            }else{
    		document.getElementById('mainForm').action='/basket.do?method=update';
    		document.getElementById('mainForm').submit();
    	}
      }
       function validateDeptCode(){
          	var catalogDeptNumber = document.getElementById('catalogDeptNumber');
              if(trimAll(catalogDeptNumber.value)==''){
              	alert('Please enter a Dept Number');
              }else{
      		document.getElementById('mainForm').action='/basket.do?method=update';
      		document.getElementById('mainForm').submit();
      	}
    }
    
    function qasPartialBillAddressSubmit(url){
    	//alert("in qasPartialBillAddressSubmit");
      	 var frm = document.forms['checkoutForm'].elements;
      	 var selected = frm.buildNumber.value;
      	  //  alert(selected);
      	  //alert(url);
		if(selected=='' || selected == null){
			alert('Please enter a additional address info');
		}else{
	  			var finalSelectedURL=url+"&street3="+selected;
	  			//alert('6'+finalSelectedURL);
	  			//window.location.href=finalSelectedURL;
	  			parent.document.location=finalSelectedURL;
		}	
  }
   function qasPartialBillRangeAddressSubmit(url,selectedMoniker){
        	 var frm = document.forms['checkoutForm'].elements;
        	 var selected = frm.buildNumber.value;
        	  //  alert(selected);
        	  //alert(url);
  		if(selected=='' || selected == null){
  			alert('Please enter a additional address info');
  		}else{
  	  			var finalSelectedURL=url+"&street3="+selected+"&qasAddressSearchForm.moniker="+selectedMoniker;;
  	  			//alert(finalSelectedURL);
  	  			//window.location.href=finalSelectedURL;
  	  			//alert('7'+finalSelectedURL);
  	  			parent.document.location=finalSelectedURL;
  		}	
  }
  
  function qasPartialAccntRangeAddressSubmit(url,selectedMoniker){
          	 var frm = document.forms['accountRegisterForm'].elements;
          	 var selected = frm.buildNumber.value;
          	  //  alert(selected);
          	  //alert(url);
    		if(selected=='' || selected == null){
    			alert('Please enter a additional address info');
    		}else{
    	  			var finalSelectedURL=url+"&street3="+selected+"&qasAddressSearchForm.moniker="+selectedMoniker;;
    	  			//alert('7'+finalSelectedURL);
    	  			window.location.href=finalSelectedURL;
    		}	
  }