// Open WIndow function
//
// openwin('winUrl','winName','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=123,height=456')

function openwin(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}

function openpopup(theURL) {
	//openwin(theURL,'popup','width=600,height=400,scrollbars=yes,resizable=yes,menubar=yes,status=yes')
	openwin(theURL,'popup','width=600,height=400,scrollbars=yes,resizable=yes,menubar=no')
}

function showPicture (id,zoom) {
	openwin('../forms/image_show.php?insecure=1&id=' + id + '&show=' + zoom,'popupimg','width=100,height=100,status=yes');
}
function showPictureOnSite (id,zoom) {
	if (typeof overridenpicture != 'undefined' && overridenpicture>0)
		openwin('../home/image_show.php?insecure=1&id=' + overridenpicture + '&show=' + zoom,'popupimg','width=100,height=100,status=yes');
	else
		openwin('../home/image_show.php?insecure=1&id=' + id + '&show=' + zoom,'popupimg','width=100,height=100,status=yes');
}
function showHelp (page) {
	openwin('../home/help_show.php?page='+ page ,'helppopup','width=100,height=100,scrollbars=yes');
}

function validateEmail(addr,man,db) {
	if (addr == '' && man) {
		if (db) alert('email address is mandatory');
		return false;
	}
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
		if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
			if (db) alert('email address contains invalid characters');
			return false;
		}
	}
	for (i=0; i<addr.length; i++) {
		if (addr.charCodeAt(i)>127) {
			if (db) alert("email address contains non ascii characters.");
			return false;
		}
	}

	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
		if (db) alert('email address must contain an @');
		return false;
	}
	if (atPos == 0) {
		if (db) alert('email address must not start with @');
		return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
		if (db) alert('email address must contain only one @');
		return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
		if (db) alert('email address must contain a period in the domain name');
		return false;
	}
	if (addr.indexOf('@.',0) != -1) {
		if (db) alert('period must not immediately follow @ in email address');
		return false;
	}
	if (addr.indexOf('.@',0) != -1){
		if (db) alert('period must not immediately precede @ in email address');
		return false;
	}
	if (addr.indexOf('..',0) != -1) {
		if (db) alert('two periods must not be adjacent in email address');
		return false;
	}
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
		if (db) alert('invalid primary domain in email address');
		return false;
	}
	return true;
}


function submitbasket_product(number) {
	if (/[^0-9]/.test(document.getElementById('quantity_'+number).value) || document.getElementById('quantity_'+number).value < 1)
	alert ('You must provide a correct, positive, numeric value.');
	else {

		document.getElementById('quantity').value= document.getElementById('quantity_'+number).value;
		document.getElementById('type').value= document.getElementById('type_'+number).value;
		document.getElementById('object_id').value=number;
		document.getElementById('mainform').submit();
	}
}

function submitbasket(number,prefix) {
	
		if (/[^0-9]/.test(document.getElementById('quantity_'+prefix+number).value) || document.getElementById('quantity_'+prefix+number).value < 1) 
				alert ('You must provide a correct, positive, numeric value.'); 
		else {
			document.getElementById('quantity').value= document.getElementById('quantity_' + prefix + number).value;
			document.getElementById('type').value=prefix;
			document.getElementById('object_id').value=number;
			document.getElementById('mainform').submit();
		}
	}
	
function colourBars() {
	var even = false;
	var evenColor = "#FFFFFF";
	var oddColor = "#ECECEC";
	var thearea = document.getElementById('tablealt');
	if (thearea) {
	var trs = thearea.getElementsByTagName('tr');
	    for (var i = 0; i < trs.length; i++) {
		   trs[i].style.backgroundColor = even ? evenColor : oddColor;
    	   even =  ! even;
	   }
	}
}
