
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 fnValidateLinks(x) {
	if (x.links_title.value.length < 4) {
		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 this link</font>";
		document.getElementById("ShowErrors").innerHTML = str;
		x.links_title.focus();
		return false;	
	}
	
	if (x.links_desc.value.length < 4) {
		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 description for this link</font>";
		document.getElementById("ShowErrors").innerHTML = str;
		x.links_desc.focus();
		return false;	
	}
	
	if (x.links_url.value.length < 10) {
		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 correct url for this link</font>";
		document.getElementById("ShowErrors").innerHTML = str;
		x.links_url.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}$/


