/*
(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 windowMove=0;

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);
}

function findLocally(noQtyMsg,noOptionsMsg, pid) {


	var fUrl='/findlocally.do?itemID='+pid;

    	var bretValue;
    	var thisFrm=document.mainForm;
    	
   	// alert(thisFrm);
	bretValue=validateProductSelection(noQtyMsg, noOptionsMsg,thisFrm, 1);
	//alert(bretValue);
	thisFrm.submit();
   
}

     
function addtoFLBasket(){
    parent.document.getElementById('mainForm').submit();

}


function findLocalStore(pid, submitFrom, noOptionsMsg, isFormSubmit){
	var zipcode = document.getElementById('postalCode').value;
	//alert(zipcode);
	 if(submitFrom=='findStore' && ( trimAll(zipcode)=='' || trimAll(zipcode).length<5 )){
		alert('Please enter a valid zip code.');
		if (isFormSubmit ==1)
			return false;
	}else{	
		var bOptionsChanged= false;
		var iOptionsNotChanged=0;
		
		var form = document.getElementById('mainForm');
		   for(var i = 0; i < form.length; i++) {
			var field = form.elements[i];
			if(field.name.indexOf("option")>=0 && field.type == "select-one"){
				var selIndex = field.selectedIndex;
				optionVal = field.options[selIndex].value;
				if (optionVal == "0"){ //if no option is selected
					//do nothing
					iOptionsNotChanged++;
				}else{
					bOptionsChanged=true;
				}
			}

		   }
		   //alert("bOptionsChanged");
		   //alert(iOptionsNotChanged);
		   //alert(bOptionsChanged);
		   
		   var bProceed=true;
		   if(bOptionsChanged){           //option has been select in modal window
		   	if (iOptionsNotChanged>0){  //one or more option is not selected
		   		//alert(noOptionsMsg);
		   		bProceed=false;
		   	}
		   }
		   //alert("bProceed");
		   //alert(bProceed);
		   
		   if (bProceed){
		   	var options="";
		   	var optionVal="";
		   	if( !bOptionsChanged){
		   		//alert("from hidden field");
				options = document.getElementById("hiddendisplayOption").value;
			}else{
				   for(var i = 0; i < form.length; i++) {
					var field = form.elements[i];
					if(field.name.indexOf("option")>=0 && field.type == "select-one"){
						var selIndex = field.selectedIndex;
						optionVal = field.options[selIndex].value;
						//alert(optionVal);
						if(options!="")
							options += ":";
						options = options +optionVal;
					}

				   }
			}
			  //alert(document.getElementById('mainForm').distance.value);
			 var distance = document.getElementById('mainForm').distance.value;
			
			 var fUrl="/findlocally.do?method=findLocally&submitFrom="+submitFrom +"&itemID="+pid+"&zipcode="+zipcode+"&distance="+distance+"&FLOptions="+options;
			 document.getElementById('mainForm').action=fUrl;
			//416 pixels wide by 664 pixels tall.  After a search by zip code is executed the window should resize itself to 815 pixels wide by 664 pixels 
			/*if(windowMove==0)
				window.moveBy(-200,0);
    			window.resizeTo(851,664);
      			*/
			 window.location.href=fUrl;
		  } //bProceed
		  
		 
	}			
}
       
function findLocallyPP(){
	 var fUrl="/category/customer+service/privacy+policy.do";
	 parent.window.location.href=fUrl;
}

function numberOnly(evt){
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57)){
			return false;
	}
	 return true;
}
function closeThis(){
var parentURL=parent.window.location.href;
parent.window.location.href=parentURL;

}

function redirectPrivacyP(){

parent.window.location.href="/category/customer+service/privacy+policy.do";

}
function tafContinue(fUrl){
			//var fUrl="/tellafriendView.do?method=continueBrowse";
			 document.getElementById('mainForm').action=fUrl;
			document.getElementById('mainForm').submit();
}
function tafCancel(fUrl){
			 //var fUrl="/tellafriendView.do?method=cancel";
			 document.getElementById('mainForm').action=fUrl;
			document.getElementById('mainForm').submit();
}
function tafEdit(fUrl){
			 //var fUrl="/tellafriendView.do?method=edit";
			document.getElementById('mainForm').action=fUrl;
			document.getElementById('mainForm').submit();
}
function tafSend(fUrl){
			 //var fUrl="/tellafriend.do?method=send";
			 document.getElementById('mainForm').action=fUrl;
			 document.getElementById('tafPricingInfo').value=document.getElementById('tafPriceInfo').innerHTML;
			 document.getElementById('mainForm').submit();

}
function tafPreview2(fUrl){
			 //var fUrl="/tellafriend.do?method=preview";
			// alert(fUrl);
			 document.getElementById('mainForm').action=fUrl;
			document.getElementById('mainForm').submit();
}

function tafClose(url){
	var hhost=document.getElementById('headerHost').value;
	document.getElementById('mainForm').action=hhost+url;
	document.getElementById('mainForm').target="_parent";
	document.getElementById('mainForm').submit();

}


function tafPrivacyP(){
	
	var hhost=document.getElementById('headerHost').value;
	document.getElementById('mainForm').action=hhost+"/category/customer+service/privacy+policy.do";
	document.getElementById('mainForm').target="_parent";
	document.getElementById('mainForm').submit();
}

function findQVLocalPop(pid){
      var win = top.Windows.focusedWindow;
      if (win.cancelCallback) 
	top.Dialog.cancelCallback();      
      else if (win.okCallback) 
	top.Dialog.okCallback();
      else
	top.Windows.close(top.Windows.focusedWindow.getId());
	    
	NTGS_Pop('664','851','','','/findlocally.do?itemID='+pid,'','','','no');
}

 
