<!--
/*
'-------------------------------------------------
'-------------------------------------------------
'-- Purpose:
'--  common functions and shared JS  
'-- Notes:
'--  - 
'-- Author:	Mark Baxter mark@editNow.net
'-- Copyright (c) 2002 editNow.net
'-- Version:	see global.asa for versioning
'-------------------------------------------------
*/


//------------------------------------------------------------
//------------------- general --------------------------------
//------------------------------------------------------------

/*
var message="";function clickIE() {if (document.all) {(message);return false;}}function clickNS(e) {if (document.layers||(document.getElementById&&!document.all)) {if (e.which==2||e.which==3) {(message);return false;}}}if (document.layers){document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
document.oncontextmenu=new Function("return false")
onMouseover="window.status='Site Map';return true;
*/
var statusMsg = ":: NAS Technical Diving Products ::"
function st_1(msg){window.status=msg;}function st_2(msg){window.status=statusMsg;return true;}
//-- Flash
var MM_contentVersion = 5;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
		var words = navigator.plugins["Shockwave Flash"].description.split(" ");
	    for (var i = 0; i < words.length; ++i)
	    {
		if (isNaN(parseInt(words[i])))
		continue;
		var MM_PluginVersion = words[i]; 
	    }
	var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
   && (navigator.appVersion.indexOf("Win") != -1)) {
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
	document.write('on error resume next \n');
	document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
	document.write('</SCR' + 'IPT\> \n');
}
//MM_FlashCanPlay = false;
noFlashURL = "/home.asp";


function showPopup( url, w, h, offsetX, offsetY, rsze, scr,st ){
	var winLeft = (screen.width / 2) - (w/2);
	var winTop = (screen.height / 2) - (h/2);
	winLeft += offsetX;winTop += offsetY;
	var newWin;newWin = "";
	if(!newWin  || newWin.closed){
		newWin = eval('window.open(url,"newWin","resizable='+rsze+',scrollbars='+scr+',status=yes,left='+winLeft+',top='+winTop+',Width='+w+'px,Height='+h+'px")');
		newWin.focus();
		newWin.resizeTo(w,h);
		newWin.moveTo(winLeft,winTop);
	}	
}

function show_cal(obj,dt){
	window.dateField = obj;
	//alert(obj.name)
	//alert(dt)
	showPopup( '/includes/shared/popupcal.asp?currentlySetDate='+dt, 280, 340,0,0,1,0,0 );
	
	}
	
function closeMe(){top.close();}
//-- general
function cookieInfo(){showPopup( '/login/cookies.asp', 480, 470, 0, 0,1,1,1 );}
function secureInfo(){showPopup( '/store/infoSecure.asp', 480, 400, 0, 0,0,1,1 );}
function requestDetails(){showPopup( '/login/request_my_details.asp', 470, 350, -20, -20,0,0,"yes" );}
function whatsThisOrder(){showPopup( '/store/whatsThisOrder.asp', 480, 380, -20, -20,1,1,1 );}

function converter(){showPopup( '/store/converter.asp', 480, 420, 200, -150,0,0 );}
function showPriceList(){showPopup( '/store/downloads/tradePriceList.asp', 680, 520,0,0,1,1 );}
function showMailingListWin(){showPopup( '/store/mailingList.asp',470,450, 0, 0,0,0);}
function showFlagWin(){showPopup( '/flagwin.asp',500,300, 0, 0,0,0);}

function showPriceBeater( url, w, h, offsetX, offsetY, rsze, scr ){
	var winLeft = (screen.width / 2) - (w/2);
	var winTop = (screen.height / 2) - (h/2);
	winLeft += offsetX;winTop += offsetY;
	var priceBeaterWin;priceBeaterWin = "";
	if(!priceBeaterWin  || priceBeaterWin.closed){
		priceBeaterWin = eval('window.open(url,"priceBeaterWin","resizable='+rsze+',scrollbars='+scr+',status='+st+',left='+winLeft+',top='+winTop+',Width='+w+'px,Height='+h+'px")');
		priceBeaterWin.focus();
		
	}	
}
function priceBeater(id){showPriceBeater('/store/priceBeater/index.asp', 560, 420,0,0,1,1 );}

/*
function deliveryInfo(){showPopup( '/store/infoDelivery.asp', 480, 400, 0, 0,0,1,1 );}
function approvedInfo(){showPopup( '/store/infoApproved.asp', 480, 400, 0, 0,0,1,1 );}
function guaranteeInfo(){showPopup( '/store/infoGuarantee.asp', 480, 400, 0, 0,0,1,1 );}
function askZip(){showPopup( '/whatIsAZip.asp', 480, 520, -20, -20,0,1,1 );}
function unSubscribe(){showPopup( '/register/unsubscribe.asp', 450, 400, 0, 0,0,0,1 )}
function popup(win){window.open(win,'','width=480,height=200,scrollbars=no,left=200,top=100');}
function openNas(){window.open("http://www.narkedat60.com", "","scrollbars=yes,resizable=yes,toolbar=yes,location=yes,status=yes,menubar=yes,");}
function checkLogin(obj){var valid=true;if(!obj.password.value||obj.password.value.length<3){valid=false;}if(!obj.username.value||obj.username.value.length<3){valid=false;}if(valid){return true}else{return false;}}
*/
//------------------------------------------------------------
//------------------- Config ---------------------------------
//------------------------------------------------------------
/*
var currentDomain = document.domain;
if (currentDomain=="localhost") {

	var secureCheckout = 'http://localhost:2500/duckanddive/nas/checkout.asp?bs=';
	
}else{

	var secureCheckout = "https://www.verysecuresites.net/duckanddive/nas/checkout.asp?bs=";
}

function domainInfo(){alert(currentDomain);}
*/





//------------------------------------------------------------------------
//----------------- STORE -------
//------------------------------------------------------------------------
var checkoutURL = '/store/placeOrder.asp?';


function tradePriceList(){showPopup( '/store/tradePriceList.asp', 600, 480, 0, 0,0,1 );}

function confirmAddToBskt(){
	viewPopupBskt();
	/*
	strAppVersion = navigator.appVersion;
	w=350;h=130;url="/store/basket_confirmation.html";
	var winLeft = (screen.width / 2) - (w/2);var winTop = (screen.height / 2) - (h/2);
	var confirmBsktWin;confirmBsktWin = "";
	if(!confirmBsktWin  || confirmBsktWin.closed){
	*/	
		//confirmBsktWin = eval('window.open(url,"confirmBsktWin","resizable=1,scrollbars=0,status=no,left='+winLeft+',top='+winTop+',Width='+w+'px,Height='+h+'px")');
		//confirmBsktWin.focus();
	   /* if (strAppVersion.indexOf('MSIE') != -1 && strAppVersion.substr(strAppVersion.indexOf('MSIE')+5,1) > 4)
	    {
	     winstyle = "dialogWidth="+w+"px; dialogHeight:"+h+"px; center:yes";
	      window.showModelessDialog(url,null,winstyle);
		  confirmBsktWin.focus();
	    }
	    else
	    {*/

	    //}
/*
	      confirmBsktWin = eval('window.open(url,"confirmBsktWin","resizable=0,scrollbars=0,status=no,left='+winLeft+',top='+winTop+',Width='+w+'px,Height='+h+'px")');
		  confirmBsktWin.focus();		
	}	*/
	
}

function checkForm(obj){
     //-- Check that they have entered  a quantity
     if (!obj.quantity.value){
          obj.quantity.value=prompt("You forgot to include a Quantity for this item. Please enter one below.","");
          if (obj.quantity.value=="null"){
               obj.quantity.value="";
          }
          return false;
        
     }
	 //-- check that the quantity is a number and convert to an integer
	 IntValue = obj.quantity.value;
		IntValue = parseInt(IntValue);
		if (isNaN(IntValue)) {   
			alert("Please enter a valid number value for the required quantity.\n\nThank you.");
			obj.quantity.value="";
			return false;
		}
	 //-- check the quantity is not zero
	 if(IntValue==0){
	 	alert("Please enter a valid number value for the required quantity.\n\nThank you.");
		return false;
	 }
	 
		//-- close the Cart Window
		theWin = window.cartWin;
        //if(!theWin || theWin.closed){ }else{theWin.close();}
		if(theWin){theWin.close();}
		return true;
		
}

function checkBasketForm(){
	theForm = document.forms["frmBasket"];
	for(i=0;i<theForm.length;i++){
		if(theForm.elements[i].type =="text"){
			//-- returns, "quanti", "priceE", "priceT", "allTot"
			if(theForm.elements[i].name.substring(0,6)=="quanti"){
				var quan = theForm.elements[i].value;
				if(isNaN(quan)){
					msg="Please enter a valid number value for the required quantity of all items."
					msg+="\n\nSetting an items quantity to '0' will remove that item."
					msg+="\n\nThank you."
					alert(msg);
					return false;
				}

			}
		}
	}
}

function viewPopupBsktNo(){
alert("Please login to be able to view Basket (registered Customers only).\n\nThank you.");
}
function viewPopupBskt(){
	var winWidth = 600;
	var winHeight = 500;
	var winLeft = (screen.width / 2) - (winWidth/2) +100;
	var winTop = (screen.height / 2) - (winHeight/2) -100;
	var url = '/store/basket_popup.asp';
	var HelpWin
	cartWin = ""
	
	if (!cartWin  || cartWin.closed){
		cartWin = eval('window.open(url,"cartWin","resizable=yes,scrollbars=yes,status=yes,left='+winLeft+',top='+winTop+',Width='+winWidth+'px,Height='+winHeight+'px");')
		cartWin.focus();
	}
	
}

function checkOut(){
	//-- check we have items before allowing checkout
	/*
	
	obj = document.forms["frmBasket"].elements['allTotal'];
	if(obj.value=="£0.00 total"){
		alert("yes");
	}else{
		alert("no");
		alert(obj.value);
	}*/

	//-- no customer ID/Not logged in
	//if(cid==""){ alert("Please Login to be able to place your order");return false;}
	
	//-- check we have a basket ID
	/*
		if(bsktID!=""||bsktID!=null){
		//var url=secureCheckout+bsktID+"&cid="+cid; checkout
		if(cid!=""){ //-- we have a customer ID, so we can place order
			var url=checkout+bsktID+"&cid="+cid;
			opener.location.href=url;
			shutDown();
		}else{ //-- no customer ID
			alert("Please Login to be able to place your order");
		}
	}*/
	/**/
	
	opener.location.href=checkoutURL;
	opener.focus();
	shutDown();
	
	//alert("paypal or own SSL(yes!) at this point");

}

function DeleteMe(theElement){
	obj = document.forms["frmBasket"].elements[theElement];
	obj.value=0;
	checkBsktQuantity(obj);
}

function promptUpdate(obj){
	//obj.elements['submit'].className="bskButtonPrompt";
	
	//btn_On = new Image(); btn_On.src = "/images/look/default/buttons/btnUpdateBskt.gif";
	//obj.elements['submit'].src = "/images/look/default/buttons/btnUpdateBskt.gif";
	//obj.elements['submit'].src = btn_On.src;
}

function checkBsktQuantity(obj){
		if(obj.value==0){
			
			//-- change style
			obj.className="bskEmptyTextBox";
			//reCalculate();
			//document.forms["frmBasket"].elements['submit'].className="bskButtonPrompt";
			obj.focus();
		}else{
			obj.className="textBox1";
			//reCalculate();
			//document.forms["frmBasket"].elements['submit'].className="bskButtonPrompt";
			obj.focus();
		}
}

function removeFocus(obj){
	//alert(toString(obj)+" hasfocus")
	obj.blur();
}

function reCalculate(){
	theForm = document.forms["frmBasket"];
	var allTot=0;
	for(i=0;i<theForm.length;i++){
		if(theForm.elements[i].type =="text"){
			//-- returns, "quanti", "priceE", "priceT", "allTot"
			if(theForm.elements[i].name.substring(0,6)=="quanti"){
				var quan = theForm.elements[i].value;if(isNaN(quan)){return false};quan = eval(quan*1);
				var priceEa = theForm.elements[i+1].value;priceEa = priceEa.substring(3);priceEa = parseFloat(priceEa);
				var priceTot = theForm.elements[i+2].value;priceTot = priceTot.substring(1);priceTot = parseFloat(priceTot);
				//-- adjust priceTot
				priceTot = (quan * priceEa);
				var allTot = allTot + priceTot;
				
				theForm.elements[i].value = quan;
				theForm.elements[i+1].value = "@ "+ GetCurrency(priceEa,"£") + " ea";
				theForm.elements[i+2].value = GetCurrency(priceTot,"£");
				theForm.elements['allTotal'].value = GetCurrency(allTot,"£");
				//alert(quan +" x "+ priceEa +" = "+ priceTot)
			}
		}
	}
}

function GetCurrency(amount,poundSign){
	tmpCurr = poundSign + amount  /**/
	hasPeriod = tmpCurr.indexOf(".")
	if(hasPeriod==-1){
		tmpCurr = tmpCurr +".00"
	}else{
		zerosAfterPeriod = tmpCurr.substring(hasPeriod)
		if(zerosAfterPeriod.length==3){
			tmpCurr = tmpCurr
		}else{
			tmpCurr = tmpCurr +"0"
		}
	}

	return tmpCurr;
}


function shutDown(){
	close('self');
}

//-->
