function fnSwitchFeatures(feature,title,release,label,image,text,link)
{	
	var $vars = new Array("title","release","label","image","text","link");
	for(i=0;i<$vars.length;i++){
		document.getElementById(feature+$vars[i]).innerHTML = eval($vars[i]);
	}
}


var display = new Array();
display[0] = "login";
display[1] = "forgot";
display[2] = "subscribe";

var agt=navigator.userAgent.toLowerCase();
var is_ie   = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_mac  = (agt.indexOf("mac")!=-1);
var is_opera = ((agt.indexOf("opera") != -1));
var is_safari = ((agt.indexOf("safari") != -1));

//paypal callback functions

function processPPTx(cm, tx, amt, st) {
	pp = document.getElementById("paypaloutput");
	pp.innerHTML = '<p>&nbsp;</p>';
	
	var XMLHttpRequestObject = false;
	if (window.XMLHttpRequest) 			{ XMLHttpRequestObject = new XMLHttpRequest(); } 
	else if (window.ActiveXObject) 	{ XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP"); }
	
	theurl = url+"store/ppAjax.php?cm="+cm+"&tx="+tx+"&amt="+amt+"&st="+st;
	if(XMLHttpRequestObject) {
		XMLHttpRequestObject.open("GET", theurl, true);
		
		XMLHttpRequestObject.onreadystatechange = function() {
				if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
					if (XMLHttpRequestObject.responseText=='0') {
						pp.innerHTML = "<p>Verifying.  Please wait.</p>";
						setTimeout("processPPTx('"+cm+"', '"+tx+"', '"+amt+"', '"+st+"')", 2000);
					} else {
						var response = XMLHttpRequestObject.responseText.split(",");
						pp.innerHTML = response[1];
						if(response[0] > 0){
							window.location="cart-complete.php?paypal=1&oid="+response[0]+"&t="+amt+"&s=OK";
						}
					}
				}
			}
			XMLHttpRequestObject.send(null);
		}
}


function fnUpdateCart(price){
	var x = document.getElementById("items").innerHTML
	document.getElementById("items").innerHTML = parseInt(x)+1;
		
	var x = document.getElementById("price").innerHTML;
	x= x.substring(1,x.length);
	var newprice = parseFloat(x)+parseFloat(price);
	newprice = Math.round(newprice * 100) / 100;
	document.getElementById("price").innerHTML = "&pound;"+newprice;
}

function fnValidateContactForm()
{
	errors=''
	if(document.form1.Name.value == ""){errors+='- Name is required\n' ;}
	if(document.form1.Subject.value == ""){errors+='- Subject is required\n'; }
	if(document.form1.Message.value == ""){errors+='- Message is required\n'; }
	var email = document.form1.EmailAddress.value.match(/^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$/);
	if(!email) {errors+='- must contain an e-mail address.\n';}
	if(errors != '')
	{
		alert(errors);
		return false;
	}
	document.form1.submit();
}

function fnValidateProductForm()
{
	errors=''
	if(document.form1.code.value == ""){errors+='- Code is required\n' ;}
	//if(document.form1.supplier_code.value == ""){errors+='- Supplier Code is required\n'; }
	if(document.form1.descr.value == ""){errors+='- Product Description is required\n'; }
	if(document.form1.flooring_type.value == ""){errors+='- Flooring Type is required\n'; }
	if(document.form1.category.value == ""){errors+='- Category is required\n'; }
	if(document.form1.species.value == ""){errors+='- species is required\n'; }
	if(document.form1.size.value == ""){errors+='- Product Size is required\n'; }
	if(document.form1.m2_per_pack.value == ""){errors+='- Pack Size is required\n'; }
	if(document.form1.price_m2.value == ""){errors+='- Price is required\n'; }
	//if(document.form1.barcode.value == ""){errors+='- Barcode is required\n'; }
	if(errors != '')
	{
		alert(errors);
		return false;
	}
	document.form1.submit();
}

function fnValidateLogin()
{
	var x=document.frmLogin;
	var frmField = ["uname","pword"];
	var frmMsg = ["User Name","Password"];

for (i=0; i< frmField.length;i++) {
	if (x.elements[frmField[i]].value == "" || x.elements[frmField[i]].value.length == 0) {
		alert(frmMsg[i] + " cannot be empty.");
		x.elements[frmField[i]].focus();
		return false;
		}	
}
return true;
}


function fnValidateNews(x)
{
	if (x.news_title.value=="" || x.news_title.value.length==0) {
		var str = "<img src=../images/admin/help_icon.gif width=17 height=22 hspace=4 vspace=0 align=absmiddle>";
    		str += "<font color=\"#FF0000\">Please enter a title for the news article</font>";
		document.getElementById("ShowErrors").innerHTML = str;
		x.news_title.focus();
		return false;
	} 
			
		if (x.news_body.value=="" || x.news_body.value.length==0) {
		var str = "<img src=../images/admin/help_icon.gif width=17 height=22 hspace=4 vspace=0 align=absmiddle>";
    		str += "<font color=\"#FF0000\">Please enter some text for the news article</font>";
		document.getElementById("ShowErrors").innerHTML = str;
		x.news_body.focus();
		return false;
	} 
return true;
}
function fnValidateService(x)
{
	if (x.service_title.value=="" || x.service_title.value.length==0) {
		var str = "<img src=../images/admin/help_icon.gif width=17 height=22 hspace=4 vspace=0 align=absmiddle>";
    		str += "<font color=\"#FF0000\">Please enter a title for the service item</font>";
		document.getElementById("ShowErrors").innerHTML = str;
		x.service_title.focus();
		return false;
	} 
			
		if (x.service_body.value=="" || x.service_body.value.length==0) {
		var str = "<img src=../images/admin/help_icon.gif width=17 height=22 hspace=4 vspace=0 align=absmiddle>";
    		str += "<font color=\"#FF0000\">Please enter some text for the service item</font>";
		document.getElementById("ShowErrors").innerHTML = str;
		x.service_body.focus();
		return false;
	} 
return true;
}

function newsdelete() {
	var str = "Are you sure you want to delete this news item?";
	str += "\nThis CANNOT BE UN-DONE.\n\n";
	str += "If you don't want to delete, you can de-activate the news item by\nclicking the 'activate/de-activate ' ";
	str += "icon.";
	return confirm(str);
}

function fnServiceDelete() {
	var str = "Are you sure you want to delete this service item?";
	str += "\nThis CANNOT BE UN-DONE.\n\n";
	str += "If you don't want to delete, you can de-activate the service by\nclicking the 'activate/de-activate ' ";
	str += "icon.";
	return confirm(str);
}


function fnLinksDelete() {
	return confirm("Are you sure you want to delete this link?\n\nNOTE: this CANNOT be undone!");
}
function fnPdfDelete() {
	return confirm("Are you sure you want to delete this PDF?\n\nNOTE: this CANNOT be undone!");
}


function fnValidateContact(x)
{
	//contact_tel,contact_fax,contact_email,contact_send_email1,contact_send_email2,contact_send_email3
	if (x.contact_add.value=="" || x.contact_add.value.length==0) {
		var str = "<img src=../images/admin/help_icon.gif width=17 height=22 hspace=4 vspace=0 align=absmiddle>";
    		str += "<font color=\"#FF0000\">Please enter your contact address</font>";
		
		document.getElementById("ShowErrors").innerHTML = str;
		x.contact_add.focus();
		return false;
	} 
	if (x.contact_tel.value=="" || x.contact_tel.value.length==0) {
		var str = "<img src=../images/admin/help_icon.gif width=17 height=22 hspace=4 vspace=0 align=absmiddle>";
    		str += "<font color=\"#FF0000\">Please enter a contact telephone number</font>";

		document.getElementById("ShowErrors").innerHTML = str;
		x.contact_tel.focus();
		return false;
	} 
	
	if (x.contact_email.value=="" || x.contact_email.value.length==0) {
		var str = "<img src=../images/admin/help_icon.gif width=17 height=22 hspace=4 vspace=0 align=absmiddle>";
    		str += "<font color=\"#FF0000\">Please enter at least 1 email address to recieve mail.</font>";

		document.getElementById("ShowErrors").innerHTML = str;
		x.contact_email.focus();
		return false;
	} 
	var email = x.contact_email.value.match(/^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$/);
	    if(email) {
	         } else {
				 var str = "<img src=../images/admin/help_icon.gif width=17 height=22 hspace=4 vspace=0 align=absmiddle>";
    			str += "<font color=\"#FF0000\">Contact Email format incorrect</font>";
	 			document.getElementById("ShowErrors").innerHTML = str;
	     x.contact_email.focus();
	return false;
	}
	
	var email = x.contact_send_email1.value.match(/^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$/);
	    if(email) {
	    } else {
			var str = "<img src=../images/admin/help_icon.gif width=17 height=22 hspace=4 vspace=0 align=absmiddle>";
			str += "<font color=\"#FF0000\">First email recipient format incorrect</font>";
			document.getElementById("ShowErrors").innerHTML = str;
			x.contact_send_email1.focus();
			return false;
		}
	return true;
}	

function fnValidateAbout(x)
{
	if (x.about_txt.value=="" || x.about_txt.value.length==0) {
		var str = "<img src=../images/admin/help_icon.gif width=17 height=22 hspace=4 vspace=0 align=absmiddle>";
    		str += "<font color=\"#FF0000\">Please enter content for the 'About Us' area</font>";
		document.getElementById("ShowErrors").innerHTML = str;
		x.about_txt.focus();
		return false;
	} 
return true;
}

function fnValidateHelp(x)
{
	if (x.help_txt.value=="" || x.help_txt.value.length==0) {
		var str = "<img src=../images/admin/help_icon.gif width=17 height=22 hspace=4 vspace=0 align=absmiddle>";
    		str += "<font color=\"#FF0000\">Please enter content for the 'Help' area</font>";
		document.getElementById("ShowErrors").innerHTML = str;
		x.help_txt.focus();
		return false;
	} 
return true;
}

function fnValidateHome(x)
{
	if (x.home_txt.value=="" || x.home_txt.value.length==0) {
		var str = "<img src=../images/admin/help_icon.gif width=17 height=22 hspace=4 vspace=0 align=absmiddle>";
    		str += "<font color=\"#FF0000\">Please enter content for the home page</font>";
		document.getElementById("ShowErrors").innerHTML = str;
		x.home_txt.focus();
		return false;
	} 
return true;
}


function fnValidateMailingList(sAction,URL) {
	var x = document.mailinglist;
	var nValid = 1
	if (x.mailing_name.value == "" || x.mailing_name.value.length == 0  || x.mailing_name.value == "Your Name") {
		x.mailing_name.focus();
		nValid = 0
		//return false;
	}
	
		if (x.mailing_email.value == "" || x.mailing_email.value.length == 0 || x.mailing_email.value == "Your Email") {
		x.mailing_email.focus();
		nValid = 0
		//return false;
	}
	
	var email = x.mailing_email.value.match(/^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$/);
	    if(email) {
	         } else {
	     alert("Email format incorrect");
	     x.mailing_email.focus();
		 nValid = 0
	//return false;
	}
	
	if(nValid == 1)
	{
		if(sAction == 'join')
		{
			x.submit();
		}
		else
		{
			x.action = URL + "mailinglist_unsubscribe/";
			x.submit();
			//return false;
		}
	}
}

function fnValidateMailingListUnsub() {
	var x = document.mailinglist_unsubscribe;
	var nValid = 1
	if (x.mailing_name.value == "" || x.mailing_name.value.length == 0  || x.mailing_name.value == "Your Name") {
		x.mailing_name.focus();
		nValid = 0
	}
		if (x.mailing_email.value == "" || x.mailing_email.value.length == 0 || x.mailing_email.value == "Your Email") {
		x.mailing_email.focus();
		nValid = 0
	}
	var email = x.mailing_email.value.match(/^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$/);
	    if(email) {
	         } else {
	     alert("Email format incorrect");
	     x.mailing_email.focus();
		 nValid = 0
	}
	if(nValid == 1)
	{
		x.submit();
	}
}
function fnValidateAddCategory(x)
{
	var x = document.frm_category;
	if(x.category.value == "")
	{
		var str = "<img src=../images/admin/help_icon.gif width=17 height=22 hspace=4 vspace=0 align=absmiddle>";
    		str += "<font color=\"#FF0000\">Please enter the category name</font>";
		document.getElementById("ShowErrors").innerHTML = str;
		x.category.focus();
		return false;
	}
		
		return true;
}

function fnOpenCalc(url,id)
{
	window.open(url + "calculator/" + id,'calculator','height=300,width=410,resizable=no,status=no,toolbar=no,menubar=no,location=no');
}

function fnOpenImg(url)
{
		window.open(url,'image','height=200,width=370,resizable=no,status=no,toolbar=no,menubar=no,location=no');

}

function popup (url,name,iwidth,iheight,scrollbars)
{
		var extras = ',resizable=no,status=no,toolbar=no,location=no,menubar=no';
		var newpopup;
		
		if (scrollbars == true)
		{
			scrollbars = "yes"
		}
		else
		{
			scrollbars = "no"
		}
		newpopup=window.open(url,name,'height=' + iheight + ',width=' + iwidth + ",scrollbars=" + scrollbars + extras)
		
		try
		{
			newpopup.focus()
		}
		catch(e)
		{
			newpopup=window.open(url,name,'height=' + iheight + ',width=' + iwidth + extras)
			alert('A popup blocker has stopped this popup showing!\r\nEnable popups for this site and try again!');
		}
}

function confirmdelete() {
	return confirm("Are you sure you want to delete this item?\n\nPLEASE NOTE: This Cannot Be Undone!");
}

function confirmclear() {
	return confirm("Are you sure you want to clear this item?");
}

function show_item(form)
{
	if (form.elements['select'].selectedIndex < 0)
	{
			alert ('You have not selected a file!');
	}
	else
	{
		popup('preview_item.php?file=' + (form.elements['select'].value),'preview','700','700',true)
	}
}

function delete_item(form)
{
	if (form.elements['select'].selectedIndex < 0)
	{
			alert ('You have not selected a file!');
	}
	else
	{
		window.location = "newsletter_view.php?rem="+ form.elements['select'].value;
	}
}

function fnValidateAccount(x)
{
	x = eval(x);
	valid = 1;
	if (x.name.value=="" || x.name.value.length==0) {
		var str = "<p><img src=../images/admin/help_icon.gif width=17 height=22 hspace=4 vspace=0 align=absmiddle>";
    		str += "<font color=\"#FF0000\"> Please enter a your name</font></p>";
		document.getElementById("ShowErrors").innerHTML = str;
		valid = 0
	} 
			
	if (x.address.value=="" || x.address.value.length==0) {
		var str = "<p><img src=../images/admin/help_icon.gif width=17 height=22 hspace=4 vspace=0 align=absmiddle>";
    		str += "<font color=\"#FF0000\">  Please enter your address</font></p>";
		document.getElementById("ShowErrors").innerHTML = str;
		x.address.focus();
	valid = 0
	} 
	
	if (x.newpword.value!= "" && x.conpword.value== "") {
		var str = "<p><img src=../images/admin/help_icon.gif width=17 height=22 hspace=4 vspace=0 align=absmiddle>";
    		str += "<font color=\"#FF0000\">Please confirm your new password</font></p>";
		document.getElementById("ShowErrors").innerHTML = str;
		x.conpword.focus();
	valid = 0
	} 
	if (x.newpword.value!= "" && (x.conpword.value != x.newpword.value)) {
		var str = "<p><img src=../images/admin/help_icon.gif width=17 height=22 hspace=4 vspace=0 align=absmiddle>";
    		str += "<font color=\"#FF0000\">Your new password and confirmation password do not match.</font></p>";
		document.getElementById("ShowErrors").innerHTML = str;
		x.conpword.focus();
	valid = 0
	} 
		
	if(valid == 1)
	{
		x.submit();
	}
}
//mail validation regexp
///^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$/

function myormr(iorg, title, key){
            var w = 760;
            var h = 510;
            var ww = Math.floor((screen.width-w)/2);
            var hh = Math.floor((screen.height-h)/2);
            var adr = "http://flash.myormr.com/index.php?iorg=" + iorg + "&title=" + escape(title) + "&key=" + escape(key);
            var edictl = 'disabled';
	    if(edictl){
                        adr += "&edictl=" + escape(edictl);
            }
            window.open(adr, 'myormr', 'status=yes,resizable=yes,width='+w+',height='+h+',top='+hh+',left='+ww);
}

function fnSwitchStatus(keepon,id)
{
	if (keepon == "notify")
	{
		document.getElementById('notify'+id).style.display ='block';
		document.getElementById('buy'+id).style.display ='none';
	}
	else
	{
		document.getElementById('notify'+id).style.display ='none';
		document.getElementById('buy'+id).style.display ='block';
	}
}

function fnCheckStatus(size,id)
{
	if(size.options[size.selectedIndex].text.indexOf('Out of Stock')!= -1)
	{
		fnSwitchStatus('notify',id)
	}
	else
	{
		fnSwitchStatus('buy',id)
	}
	
}
function showHide (show) {
	for (i = 0; i < 3; i++) {
		if (display[i] != show) {
			if (d = document.getElementById(display[i])) {
				d.style.display = 'none';
			}
		}
	}
	
	if (d = document.getElementById(show)) {
		d.style.display = 'block';
	}
	return false;
}

function togglePasswordChange() {
	var pw1 = document.getElementById('cust_pass_new');
	var pw2 = document.getElementById('cust_pass_confirm');
	
	if(pw1.disabled) { pw1.disabled=false } else { pw1.disabled=true; }
	if(pw2.disabled) { pw2.disabled=false } else { pw2.disabled=true; }
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function KeyValue(value) {
	alert("www.sandyrivera.dj is sorry but is unable to show you this media via key values");
	return false;
}
var wasplaying = false;

function fnStopFlash(){
		
	if(document.getElementById('objectMain').setPlayerState){
		if(!(document.getElementById('objectMain').isPaused()||document.getElementById('objectMain').isStopped())){
			document.getElementById('objectMain').setPlayerState("pause");
			wasplaying = true;
		}
	}else{
		//we will use the embed instead;
		if(document.getElementById('embedMain')){
			//alert(document.getElementById('embedMain').isPaused()+ " "+ document.getElementById('embedMain').isStopped()+" "+document.getElementById('embedMain').isPaused() || document.getElementById('embedMain').isStopped());
			if(!(document.getElementById('embedMain').isPaused() || document.getElementById('embedMain').isStopped()) ){
				document.getElementById('embedMain').setPlayerState("pause");
				wasplaying = true;
			}
		}else{
			
		}
	}
	
	
	MM_showHideLayers('brand','','hide');
	MM_showHideLayers('header','','hide');
	MM_showHideLayers('mediaplayer','','hide');
}

function hideGallery() {
	window.document.header.SetVariable("stopplaying","false");
	//if(!is_safari){
	if(document.getElementById('objectMain').setPlayerState){
		if(document.getElementById('objectMain').isPaused() && wasplaying){
			document.getElementById('objectMain').setPlayerState("pause");
		}
	}else{
		//we will use the embed instead;
		if(document.getElementById('embedMain')){
			if(document.getElementById('embedMain').isPaused() && wasplaying ){
				document.getElementById('embedMain').setPlayerState("pause");
			}
		}else{
			
		}
	}
		
	//}
	//alert(navigator.appName + "| " +navigator.userAgent);
	MM_showHideLayers('brand','','show');
	MM_showHideLayers('header','','show');
	MM_showHideLayers('mediaplayer','','show');
	MM_showHideLayers('galleryCont','','hide');
		if(!is_mac) {
			deleteFlashContent();
		} else if(is_mac && !is_ie) {
			deleteFlashContent();
		}
	}
	function deleteFlashContent() {
		if (document.getElementById) {
    		document.getElementById('galleryCont').innerHTML = "";
		} else if (document.all) {
    		document.all.galleryCont.innerHTML = "";
    	}
	}

