function _openwin(page){
 window.open(page, 'helpWindow', 'location=no,scrollbars=yes,toolbar=no,width=300,height=400');
}

function _open_telwin(page){
 telwin=window.open(page+'&ref='+window.location, "tel", 'location=no,scrollbars=yes,toolbar=no,status=yes,width=473,height=400,resizable=yes');
 telwin.window.focus();
}

function sure(text){
 if (confirm(text)) 
	  return (true); 
  else 
	  return (false);
}

function updQuant(i){
	var f="prodform"+i;
	var e="quant"+i;
	p=document.getElementById(f);
	q=document.getElementById(e);
	p.quant.value=q.value;
	p.submit();
}

function updateSaturdayCharge(dateField,selectedDateField){
	try{
		var dateValue = document.getElementById(dateField).value;
		var day = dateValue.substr(0, 2);
		var month = dateValue.substr(3, 2);
		var year = dateValue.substr(6, 4);	
		var delDate = new Date(year, month - 1, day);
		if(delDate.getDay() == 6){
			document.getElementById("saturdayDelCharge").value = 20;
		}else{
			document.getElementById("saturdayDelCharge").value = 0;
		}	
		document.getElementById(selectedDateField).value=dateValue;
		var optionsForm = document.getElementById("optionsForm");
		if(optionsForm){
			optionsForm.submit();
		}
	}catch(e) {}	
}

function frmsubmit(func) {	
	try{	
		document.basket.func.value = func;
		document.basket.submit();		
	}catch (e) {}
}

function _opensecwin(url){
secwin=window.open(url, 'securewin', 'location=yes,scrollbars,width=786,height=600');
 secwin.window.focus();
}

function _openemailpagewin(){
	epagewin=window.open('emailpage.php', 'epwin', 'location=no,scrollbars,status=no,width=500,height=350');
	epagewin.window.focus();
}


function launchcalculator(prod_id,formid,quantid){
calcwin=window.open('calculator.php?id='+prod_id+'&form='+formid+'&quant='+quantid, 'calcwin', 'location=no,scrollbars=yes,toolbar=no,status=no,resizable=no,width=345,height=460');
 calcwin.window.focus();
}


function validateForm(){
 if(document.sp_form.email.value==""){
	alert("Please type in your email address");
	document.sp_form.email.focus();
	document.sp_form.email.style.backgroundColor='ffff00';
	return false;
}else if(document.sp_form.email.value!=document.sp_form.email2.value){
	alert("Please type in your email address the same both times");
	document.sp_form.email.focus();
	document.sp_form.email.style.backgroundColor='ffff00';
	return false;
 } else if (!valid_email(document.sp_form.email.value)){
		alert("You must enter a valid e-mail address");
		document.sp_form.email.focus();
		document.sp_form.email.style.backgroundColor='ffff00';
		return (false);
 }else{
	return true;
 }
}

function valid_email(addr) {
	if (matchit(addr)==null){
		//alert("This is not a genuine e-mail address.");
		return (false);
	} else {
		return (true);
	}
}

function matchit(email){
	var result= email.match(/(^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$)/gi);
	return result;
}

function validateRegForm() {
	if (document.regform.email.value == ""){
		document.regform.email.style.backgroundColor='ffff00';
		alert("You must enter your e-mail address");
		document.regform.email.focus();
		return (false);
	}else if (!valid_email(document.regform.email.value)){
		document.regform.email.style.backgroundColor='ffff00';
		alert("You must enter a valid e-mail address");
		document.regform.email.value="";
		document.regform.email.focus();
		return (false);
	}else if (document.regform.firstname.value == ""){
		document.regform.firstname.style.backgroundColor='ffff00';
		alert("You must enter your firstname");
		document.regform.firstname.focus();
		return (false);
	}else if (document.regform.lastname.value == ""){
		document.regform.lastname.style.backgroundColor='ffff00';
		alert("You must enter your last name");
		document.regform.lastname.focus();
		return (false);
	}else if (document.regform.pass.value == ""){
		document.regform.pass.style.backgroundColor='ffff00';
		alert("You must enter a password");
		document.regform.pass.focus();
		return (false);
	}else if (document.regform.pass2.value == ""){
		document.regform.pass2.style.backgroundColor='ffff00';
		alert("You must re-enter your password");
		document.regform.pass2.focus();
		return (false);
	}else if (document.regform.pass2.value != document.regform.pass.value){
		document.regform.pass.style.backgroundColor='ffff00';
		document.regform.pass2.style.backgroundColor='ffff00';
		document.regform.pass2.value='';
		document.regform.pass.value='';
		alert("Your passwords must be exactly the same each time you type them in.");
		document.regform.pass.focus();
		return (false);
	}else {
		document.regform.submit();
		return (true);
	}
}

function validateForm2(f) {
	if (f.firstname.value == ""){
		f.firstname.style.backgroundColor='#ffff00';
		alert("Please enter your firstname");
		f.firstname.focus();
		return (false);
	}else if (f.lastname.value == ""){
		f.lastname.style.backgroundColor='#ffff00';
		alert("Please enter your last name");
		f.lastname.focus();
		return (false);
	}else if (f.addr1.value == ""){
		f.addr1.style.backgroundColor='#ffff00';
		alert("Please enter an address");
		f.addr1.focus();
		return (false);
	}else if (f.town.value == ""){
		f.town.style.backgroundColor='#ffff00';
		alert("Please enter a town");
		f.town.focus();
		return (false);
	}else if (f.postcode.value == ""){
		f.postcode.style.backgroundColor='#ffff00';
		alert("Please enter a postcode");
		f.postcode.focus();
		return (false);
	/*}else if (f.country.selectedIndex == 0){
		alert("Please select a country");
		f.country.focus();
		return (false);*/
	}else if (f.tel.value == ""){
		f.tel.style.backgroundColor='#ffff00';
		alert("Please enter a telephone number");
		f.tel.focus();
		return (false);
	}else if (f.emailAddress.value == ""){
		f.emailAddress.style.backgroundColor='#ffff00';
		alert("Please enter your email address");
		f.emailAddress.focus();
		return (false);
	}else if (!valid_email(f.emailAddress.value)){
		alert("You must enter a valid e-mail address");		
		f.emailAddress.style.backgroundColor='ffff00';
		f.emailAddress.focus();
		return (false);
	}else if (f.where_find_us.value == ""){
		//f.where_find_us.style.backgroundColor='#ffff00';
		//alert("Please let us know where you found out about us.");
		//f.where_find_us.focus();
		//return (false);
	}else {
		f.submit();
		return (true);
	}
}

function validateLoginForm(){
 if(document.loginform.email.value==""){
	alert("Please type in your email address");
	document.loginform.email.focus();
	document.loginform.email.style.backgroundColor='ffff00';
	return false;
 } else if (!valid_email(document.loginform.email.value)){
		alert("You must enter a valid e-mail address");
		document.loginform.email.focus();
		document.loginform.email.style.backgroundColor='ffff00';
		return (false);
}else if (document.loginform.pass.value == ""){
		document.loginform.pass.style.backgroundColor='ffff00';
		alert("You must enter a password");
		document.loginform.pass.focus();
		return (false);
 }else{
	return true;
 }
}

function showDelTable(){
	var oDelTable = document.getElementById("del_table");
	
	if(oDelTable){
		if(oDelTable.style.display == "none"){		
			oDelTable.style.display = "block";
		}else{
			oDelTable.style.display = "none";
		}
	}
}
function submitExecuteSearch(myfield, e){
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13)
	   {
	   executeSearch();
	   return false;
	   }
	else
	   return true;
}

function showSearchFilter(){
	var oSearchFilter = document.getElementById("categorySearchFilterMain");
	var oSearchSelection = document.getElementById("categorySearchFilterSelection");
	var oShowFilter = document.getElementById("imgShowFilter");
	
	if(oSearchFilter){
		if(oSearchFilter.style.display == "none"){
			oSearchFilter.style.display = "block";
			oSearchSelection.style.display = "block";
			oShowFilter.src = "images/site_v2/arrow_down.gif";
		}else{
			oSearchFilter.style.display = "none";
			oSearchSelection.style.display = "none";
			oShowFilter.src = "images/site_v2/arrow_right.gif";
		}
	}
}
function executeSearch(){		
	//set the price range
	var sPriceRange = document.getElementById("selPrice").options[document.getElementById("selPrice").selectedIndex].value;
	var aPriceRange = sPriceRange.split(",");	
	var iPriceFrom = aPriceRange[0];
	var iPriceTo = aPriceRange[1];
	
	var sFreeText = document.getElementById("freeText").value;
	if(sFreeText == "TV STAND TEXT SEARCH..."){
		sFreeText = "";
	}
	//call the ajax function to create the filter in the database
	xajax_createQuickSearchFilter(0, 0, iPriceFrom, iPriceTo, sFreeText, 0);
}

function redirectToSearchResultsPage(categoryId){
	window.location = msWebsitePathUrl + "/index.php?main=cat&id=0&filter=quickTextSearch";	
}
function showListView(){
	var oDivs = document.getElementsByTagName("DIV");
	if(oDivs){
		
		for(var i = 0; i < oDivs.length - 1; i++){			
			oDiv = oDivs[i];			
			switch (oDiv.className){
				case "thumb":
				case "thumb leadingThumb":
					oDiv.className+=" productListViewThumb";
					break;
			}
		}
	}
	mListType = "list";
}

function showThumbsView(){
	var oDivs = document.getElementsByTagName("DIV");
	if(oDivs){
		
		for(var i = 0; i < oDivs.length - 1; i++){			
			oDiv = oDivs[i];			
			switch (oDiv.className){
				case "thumb productListViewThumb":
				case "thumb leadingThumb productListViewThumb":
					oDiv.className = oDiv.className.replace(" productListViewThumb", "");
					break;
			}
		}
		mListType = "thumbs";
	}
}