

function inet_pop_win(pageToLoad, winName, width, height, center, ramme) {
	xposition=0; yposition=0;
	if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
		xposition = (screen.width - width) / 2;
		yposition = (screen.height - height) / 2;
		}
	width = width + ramme * 2
	args = "width=" + width + "," 
	+ "height=" + height + "," 
	+ "location=0," 
	+ "menubar=0,"
	+ "resizable=0,"
	+ "scrollbars=0,"
	+ "status=0," 
	+ "titlebar=0,"
	+ "toolbar=0,"
	+ "hotkeys=0,"
	+ "left=" + xposition + ","
	+ "top=" + yposition;

	window.open(pageToLoad+"&ramme="+ramme,winName,args );
}


var win = null;

function inet_open_win() {
	if (ua["dom"]) {
		var url = "";
		var target = "";

		var attributes = "";


		if (arguments.length > 0) {
			url = arguments[0];
		}

		//Target attribute:
		if (arguments.length > 1) {
			target = arguments[1];
		}
			
		//Optional attributes:
		if (arguments.length > 2) {
			attributes = arguments[2];
		}
	
		if (win != null) {
			if (!win.closed) {
				win.close();
			}
		}

		win = window.open(url, target, attributes);
		win.focus();
		return false;
	}
}

function toggleMenuLink(obj) {
	parobj = obj.parentNode;

	parclasses = parobj.className.split(" ");

	for (i=0; i<parclasses.length; i++) {
		if (parclasses[i] == "closed") {
			parclasses[i] = "open";
			parobj.className = parclasses.join(" ");
			i = parclasses.length;
		}
		else if (parclasses[i] == "open") {
			parclasses[i] = "closed";
			parobj.className = parclasses.join(" ");


			i = parclasses.length;


		}
	}

	return false;
}



/**** INIT ****/

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != "function") {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function blurAnchors(){ 
	if(document.getElementsByTagName) { 
	var a = document.getElementsByTagName("a"); 
	//collect all anchors A 
	for(var i = 0; i < a.length; i++){ 
		// mouse onfocus, blur anchors 
		a[i].onfocus = function(){this.blur();}; 
		} 
	} 
} 

addLoadEvent(blurAnchors);


/**** MENU ****/
function inet_menu_delay_hide() {
	if (ua["dom"]) {
		delayhide=setTimeout("inet_menu_show_default()",500)
	}
}

function inet_menu_clear_hide() {
	if (ua["dom"]) {
		if (window.delayhide) clearTimeout(delayhide)
	}
}

function inet_menu_over(id) {
	if (ua["dom"]) {
		if (window.delayhide) clearTimeout(delayhide)
		inet_show_sub(id);
	}
}

function inet_menu_out() {
	if (ua["dom"]) {
		inet_menu_delay_hide();
	}
}

function inet_show_sub(id) {
	if (ua["dom"]) {
		submenudiv = document.getElementById("inet_submenus");
		aDIV = submenudiv.getElementsByTagName("div");
		for (i=0; i<aDIV.length; i++) {
			aDIV[i].style.visibility = (aDIV[i].id == "submenu"+id ? "visible" : "hidden");
			aDIV[i].style.display = (aDIV[i].id == "submenu"+id ? "block" : "none");
		}
	}
}

function inet_menu_show_default() {
	if (ua["dom"]) {
		submenudiv = document.getElementById("inet_submenus");
		aDIV = submenudiv.getElementsByTagName("div");
		for (i=0; i<aDIV.length; i++) {
			is_default = hasClassName(aDIV[i], "default");
			aDIV[i].style.visibility = (is_default ? "visible" : "hidden");
			aDIV[i].style.display = (is_default ? "block" : "none");
		}
	}
}




function hasClassName(elm, cname) {
	if (ua["dom"]) {
		aCname = elm.className.split(" ");
		for (j=0; j<aCname.length; j++) {
			if (aCname[j] == cname) return true;
		}
	}
	return false;
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}


function inp_init(inp, init_txt) {
	var inp = inp;
	var inp_value = trim(inp.value);

	if (inp_value == '') {
		inp.value = init_txt;
	}
}

function inp_clear(inp, init_txt) {
	var inp = inp;
	var inp_value = trim(inp.value);

	if (inp_value == init_txt) {
		inp.value = '';
	}
}

function inp_val(inp, init_txt, val_txt) {
	var inp = inp;
	var inp_value = trim(inp.value);
	
	if ((inp_value == init_txt) || (inp_value == '')) {
		alert(val_txt);
		return false;
	}
	else {
		return true;
	}
}

function inp_val2(inp, inp2, init_txt, init_txt2, val_txt, val_txt2) {
	var inp = inp;
	var inp2 = inp2;
	var inp_value = trim(inp.value);
	var inp_value2 = trim(inp2.value);
	
	if ((inp_value == init_txt) || (inp_value == '')) {
		alert(val_txt);
		return false;
	}
	else if ((inp_value2 == init_txt2) || (inp_value2 == '')) {
		alert(val_txt2);
		return false;
	}
	else {
		return true;
	}
}


/*
function handle_poco(poco_id) {
	var str_poco_id = poco_id;
	if (str_poco_id.match('cat_') != null) {
		poco_id = str_poco_id.replace(/cat_/, '');
		document.forms['search_produsradv'].prod_usr_poco_main.value = poco_id;
		//alert(poco_id);
	}
}
*/

function validate_usr() {
	var frm = document.getElementById("form_produsr");
	var val_message = "";
	lbl = frm.getElementsByTagName("label")
	for (i=0; i<lbl.length; i++) {
		lbl[i].className = "";
	}

	if (frm.usr_usrname.value=='') {
		document.getElementById('label_usr_usrname').className = 'redtxt';
		val_message += 'Please enter user name\n';
	}
	if (frm.usr_pwd.value=='') {
		document.getElementById('label_usr_pwd').className = 'redtxt';
		val_message += 'Please enter password\n';
	}
	if ((frm.usr_pwd.value!=frm.usr_pwd2.value) || (frm.usr_pwd2.value=="")) {
		document.getElementById('label_usr_pwd2').className = 'redtxt';
		val_message += 'Please retype password\n';
	}
	if (!validate_email(frm.usr_email.value)) {
		document.getElementById('label_usr_email').className = 'redtxt';
		val_message += 'Please enter a valid email\n';		
	}
	if (frm.nationality.value=='') {
		document.getElementById('label_nationality').className = 'redtxt';
		val_message += 'Please enter your nationality\n';
	}
	if (!frm.sex3.checked && !frm.sex4.checked) {
		document.getElementById('label_sex').className = 'redtxt';
		val_message += 'Please enter your sex\n';
	}
	if (val_message!="") {
		alert(val_message);
		return false;
	} else {
		return true;
	}
}

function validate_usr_modify() {
	var frm = document.getElementById("form_produsr");
	var val_message = "";
	lbl = frm.getElementsByTagName("label")
	for (i=0; i<lbl.length; i++) {
		lbl[i].className = "";
	}

	if (!validate_email(frm.usr_email.value)) {
		document.getElementById('label_usr_email').className = 'redtxt';
		val_message += 'Please enter a valid email\n';		
	}

	if (val_message!="") {
		alert(val_message);
		return false;
	} else {
		return true;
	}
}

function validate_pwd() {
	var frm = document.getElementById('form_produsr_pwd');
	lbl = frm.getElementsByTagName('label')
	for (i=0; i<lbl.length; i++) {
		lbl[i].className = '';
	}

	if (trim(frm.usr_pwd.value)=='') {
		document.getElementById('label_usr_pwd').className = 'redtxt';
		alert('Please enter old password');
		return false;
	}
	if (trim(frm.usr_pwd2.value)=='') {
		document.getElementById('label_usr_pwd2').className = 'redtxt';
		alert('Please enter new password');
		return false;
	}
	if (trim(frm.usr_pwd2.value)!=frm.usr_pwd3.value) {
		document.getElementById('label_usr_pwd3').className = 'redtxt';
		alert('Please retype new password');
		return false;
	}

	return true;
}

function validate_pwdreq() {
	var frm = document.getElementById('form_produsr_pwdreq');
	lbl = frm.getElementsByTagName('label')
	for (i=0; i<lbl.length; i++) {
		lbl[i].className = '';
	}

	if (trim(frm.requestemail.value)=='' && trim(frm.requestname.value)=='') {
		document.getElementById('label_requestemail').className = 'redtxt';
		document.getElementById('label_requestname').className = 'redtxt';
		alert('Please enter either your email or your user name');
		return false;
	}
	if (trim(frm.requestemail.value) != '') {
		if (!validate_email(frm.requestemail.value)) {
			document.getElementById('label_requestemail').className = 'redtxt';
			alert('Please enter a valid email');
			return false;
		}
	}

	return true;
}

function validate_produsrdel() {
	var frm = document.getElementById('form_produsr_del');
	lbl = frm.getElementsByTagName('label')
	for (i=0; i<lbl.length; i++) {
		lbl[i].className = '';
	}

	if (trim(frm.prod_usr_name.value)=='') {
		document.getElementById('label_prod_usr_name').className = 'redtxt';
		alert('Please enter your username');
		return false;
	}
	if (trim(frm.prod_usr_pwd.value)=='') {
		document.getElementById('label_prod_usr_pwd').className = 'redtxt';
		alert('Please enter your password');
		return false;
	}

	return true;
}

function validate_email(inp) {
	var objRegExp = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	return objRegExp.test(inp);
}




function validate_cust() {
	var frm = document.getElementById("eshp_data");
	var val_message = "";
	lbl = frm.getElementsByTagName("label")
	for (i=0; i<lbl.length; i++) {
		lbl[i].className = "";
	}

	if (frm.eshp_ifirstname.value=='') {
		document.getElementById('label_eshp_ifirstname').className = 'redtxt';
		val_message += 'Please enter your first name\n';
	}
	if (frm.eshp_ilastname.value=='') {
		document.getElementById('label_eshp_ilastname').className = 'redtxt';
		val_message += 'Please enter your last name\n';
	}
	if (frm.eshp_iaddress1.value=='') {
		document.getElementById('label_eshp_iaddress1').className = 'redtxt';
		val_message += 'Please enter your address\n';
	}
	if (frm.eshp_izipcode.value=='' || frm.eshp_icity.value=='') {
		document.getElementById('label_eshp_izipcode').className = 'redtxt';
		val_message += 'Please enter your postcode and city\n';
	}
	if (frm.eshp_icountrycode.value=='') {
		document.getElementById('label_eshp_icountrycode').className = 'redtxt';
		val_message += 'Please enter your country\n';
	}
	if (!validate_email(frm.eshp_iemail.value)) {
		document.getElementById('label_eshp_iemail').className = 'redtxt';
		val_message += 'Please enter valid email\n';		
	}

	if (val_message!="") {
		alert(val_message);
		return false;
	} else {
		return true;
	}
}

