/*
	Website scripts
	(c) BDesigned Studios
*/

function openWindow(address,winurl,winwidth,winheight) {
	var new_window = window.open(address,winurl,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=' + winwidth + ',height=' + winheight);
}

function popup_centre(popupwidth,popupheight) {
	/* When calling this function supply the width and height of the popup */
	var horizontal = ((screen.availWidth / 2) - (popupwidth / 2));
	var vertical = ((screen.availHeight / 2) - (popupheight / 2));
	window.moveTo(horizontal,vertical);
}

function validateComment(item_id) {
	var errormessage = 'Please ensure that you have completed the following:\n';
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	var formname = 'comment_form_' + item_id;
	
	if(
	   (document.getElementById(formname).username.value != '') &&
	   (document.getElementById(formname).email.value != '') &&
	   (filter.test(document.getElementById(formname).email.value)) &&
	   (document.getElementById(formname).comment.value != '')
	  ) {
		document.getElementById(formname).submit();
	} else {
		if(document.getElementById(formname).username.value == '') {
			errormessage += "  > Your name\n";
		}
		if(document.getElementById(formname).email.value == '') {
			errormessage += "  > Your email\n";
		} else {
			if((filter.test(document.getElementById(formname).email.value)) == false) {
				errormessage += "  > You must enter a valid email address\n";
			}
		}
		if(document.getElementById(formname).comment.value == '') {
			errormessage += "  > Your comment\n";
		}
		alert(errormessage);
	}
}

// Div Hider
function toggleLayer(whichLayer) {
	if (document.getElementById) {
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
	} else if (document.all) {
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
	} else if (document.layers) {
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
}

function linkToImage(image_id,image_place) {
	/* popup with image id and code so people can link to the image */
	var new_window = window.open('includes/sub_linktoimage.php?id='+image_id+'&place='+image_place,'linkImage','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=400,height=200');
}