

function ListMouseOver(e) {
	e.style.border = "1px solid #DCDCDC";
}

function ListMouseOut(e) {
	e.style.border = "1px solid #FFFFFF";
}

function FlickText(t) {
	var obj = document.all("tooldiv");
	if (obj) {
		obj.innerText = t;
	}
}

function DoPrint() {
   var loc = location.href;
	if (loc.indexOf("#")>0) {
		loc = loc.substring(0, loc.indexOf("#"));
	}
	var pri = "?p=1";
	if (loc.indexOf("?")>0) {
		pri = "&p=1";
	}
	OpenWindow(loc+pri, 769, 400);
}

function OpenWindow(url, w, h, attr)
{
	var m_attr = "toolbar=1,location=0,directories=0,status=0,menubar=yes,scrollbars=yes,resizable=yes";
	if (attr)
	{
		m_attr = attr;
	}	
	window.open(url, "", m_attr+",width="+w+",height="+h);
}


function DoSearch() {
	location.href = "/Site%20tools/search.aspx?search="+document.getElementById("searchfield").value;
}

function PostSearch(buttonName) {    
	if (event.keyCode == 13) {        
		event.cancelBubble = true;
		event.returnValue = false;
		var button = document.getElementById(buttonName);
		if (button != null) {
			button.click(); 
		}
	}
}

function NewsSubscribe(r, act, o) {
	var isValid = true;
	var oe = o.elements;
	HideError("1");
	HideError("2");
	if (oe["1"].value=="") {ShowError("1");isValid = false;}
	if (!isValidEmail(oe["2"].value)) {ShowError("2");isValid = false;}
	if (isValid) {
		location.href = "/Forms/newsletter.aspx?1="+oe["1"].value+"&2="+oe["2"].value+"&3="+oe["3"].value+"&4="+oe["4"].value+"&5="+oe["5"].value+"&6="+oe["6"].value+"&7="+oe["7"].value+"&act="+act+"&r="+r;
		return true;
	}
	return false;
}

function SendLink(o) {
	var isValid = true;
	var oe = o.elements;
	HideError("1");
	HideError("2");
	if (oe["1"].value=="") {ShowError("1");isValid = false;}
	if (!isValidEmail(oe["2"].value)) {ShowError("2");isValid = false;}
	if (isValid) {
		location.href = "/Forms/email.aspx?1="+oe["1"].value+"&2="+oe["2"].value+"&3="+oe["3"].value+"&id="+QS("id")+"&la="+QS("la");
		return true;
	}
	return false;
}

function DontPost() {  
	if (event.keyCode == 13) {
		event.cancelBubble = true;
		event.returnValue = false;
	}
}

function ShowError(oID) {
	document.getElementById("error"+oID).style.display = "inline";
}

function HideError(oID) {
	document.getElementById("error"+oID).style.display = "none";
}

function isValidEmail(emailAddress) {
	var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
	return re.test(emailAddress);
}

function DoEmail(p, l) {
	window.open("/Site tools/Send to friend.aspx?id="+p+"&la="+l, "dviPrint", "toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=no,resizable=no,width=450,height=350");
	
}

function PrepPrint() {
	for (i=0; i<document.body.all.tags("A").length; i++) {
		document.body.all.tags("A")[i].href = 'JavaScript:void(0)';
		document.body.all.tags("A")[i].target = '';
	}
	for (i=0; i<document.body.all.length; i++) {
		document.body.all[i].setAttribute('onclick','');
	}
	window.print();
}

function CheckForm(form,id) {
	var isValid = true;
	var formElements = form.elements;
	var brochure = new Array("","Dairy and Dessert","Private Label","Bakery and Industrial Sector","Ice Cream and Dessert","Salad and Snack");
	var brochureorder = new Array();
	var counter = 0;
	var contact = "";
	HideError("1");
	HideError("2");
	HideError("3");
	HideError("4");
	for(i=0;i<6;i++) {
		if(formElements[i].checked==true) {
			brochureorder[counter] = brochure[i];
			counter++;
		}
	}
	if (brochureorder.join(",")=="") {isValid = false;}
	if (formElements["name"].value=="") {ShowError("1");isValid = false;}
	if (formElements["address"].value=="") {ShowError("2");isValid = false;}
	if (formElements["zip"].value=="") {ShowError("3");isValid = false;}
	if (formElements["mail"].value!="")
		if (!isValidEmail(formElements["mail"].value)) {ShowError("4");isValid = false;}
	if (isValid) {
		if(formElements["contactByPhone"].checked==true && formElements["contactByMail"].checked==true)
			contact = "Contact me by phone or mail.";
		else if(formElements["contactByPhone"].checked==true)
			contact = "Contact me by phone.";
		else if(formElements["contactByMail"].checked==true)
			contact = "Contact me by mail.";
		location.href = "/forms/Orderform.aspx?brochures="+brochureorder.join(",")+"&contact="+contact+"&company="+formElements["company"].value+"&title="+formElements["title"].value+"&name="+formElements["name"].value+"&address="+formElements["address"].value+"&zip="+formElements["zip"].value+"&phone="+formElements["phone"].value+"&fax="+formElements["fax"].value+"&mail="+formElements["mail"].value+"&comments="+formElements["comments"].value+"&id="+id;
		return true;
	}
	return false;
}
//=====================================
// Utilities
//=====================================
function QS(name) {
	var tmp = unescape( location.search.substring(1) );
	var i   = tmp.toUpperCase().indexOf(name.toUpperCase()+"=");
	if ( i >= 0 ) {
		tmp = tmp.substring( name.length+i+1 );
		i = tmp.indexOf("&");
		return( tmp = tmp.substring( 0, (i>=0) ? i : tmp.length ));
	}
	return("");
}
