<!--

function openWin( windowURL, windowName, windowFeatures ){
	window.open( windowURL, windowName, windowFeatures );
}

function openPlannerDemo(){
	openWin('planner/siteGardenPlannerDemo.php', 'demo', 'width=635,height=490');
}


function validateEmail(email){
	var emailReg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
	var emailReg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.\_]+\.([a-zA-Z]{2,6}|[0-9]{1,3})(\]?)$/; // valid
	var charReg = /[^a-zA-Z0-9@\.\-\_\']/;
	if (!emailReg1.test(email) && emailReg2.test(email) && !charReg.test(email)) {
		return true; // valid
	}else{
		return false; // not valid
	}
}


function getElementByIdCrossBrowser(element){
	var el;
	if(document.getElementById){
		el = document.getElementById(element);
	}else if(document.all){
		el = document.all[element];
	}else if(document.layers){
		for(var i=0; i<document.layers.length; i++){
			if(document.layers[i].name == element){
				el = document.layers[i];
			}
		}
	}
	return el;
}


function toggleDisplay(ele){
	var el = getElementByIdCrossBrowser(ele);
	if(el.style.display == 'none'){
		setDisplay(ele, true);
	}else{
		setDisplay(ele, false);
	}
}


function setDisplay(ele, display){
	var el = getElementByIdCrossBrowser(ele);
	if(display){
		el.style.display = '';
	}else{
		el.style.display = 'none';
	}
	
}


function toggleCheckboxes(ele,arg){
	var cTag = document.getElementsByTagName("input");
	var iTag = cTag.length;
	for(i=0; iTag > i; i++){
		var name = cTag[i].name;
		if(cTag[i].type == "checkbox"){
			if(name.match(arg)){
				cTag[i].checked = ele.checked;
			}
		}
	}
}


function resetCheckBoxes(check, argName){
	var cTag = document.getElementsByTagName("input");
	var iTag = cTag.length;
	var name = '';
	var arg = eval('/' + argName + '/');
	for(i=0; iTag > i; i++){
		name = cTag[i].name;
		if(arg.test(name) && cTag[i].type == "checkbox"){
			if(check){
				cTag[i].checked = true;
			}else{
				cTag[i].checked = false;
			}
		}
	}
}


function resetSelects(argName){
	var cTag = document.getElementsByTagName("select");
	var iTag = cTag.length;
	var name = '';
	var arg = eval('/' + argName + '/');
	for(i=0; iTag > i; i++){
		name = cTag[i].name;
		if(argName){
			if(arg.test(name)){
				cTag[i].selectedIndex = 0;
			}
		}else{
			cTag[i].selectedIndex = 0;
		}
	}
}

function hideSelects(show){
	var sels = document.getElementsByTagName('select');
	for(i=0;i<sels.length;i++){
		if(show){
			sels[i].style.visibility = 'visible';
		}else{
			sels[i].style.visibility = 'hidden';
		}
	}
}

function toggleSelects(){
	var sels = document.getElementsByTagName('select');
	for(i=0;i<sels.length;i++){
		if(sels[i].style.visibility == 'visible' || sels[i].style.visibility == ''){
			sels[i].style.visibility = 'hidden';
		}else{
			sels[i].style.visibility = 'visible';
		}
	}
}


function clearInput(ele, val){
	if(ele.value == val){
		ele.value='';
	}
}


function checkLogin(){
	var mesg = '';
	var email = document.login.email.value;
	var password = document.login.password.value;
	var charReg = /[^a-zA-Z0-9]/;
	
	if (!validateEmail(email)){
		mesg += "Please enter a valid email address.\n";
	}

	if(password.length < 6 || password.length > 14){
		mesg += "Your password should be between 6 and 14 characters.\n";
	}

	if(charReg.test(password)){
		mesg += "There are non-alphanumeric characters in your password.\nPlease remove them.";
	}

	if(mesg){
		alert(mesg);
		return false;
	}else{
		return true;
	}

}


function checkEmail(){
	var mesg = '';
	var email = document.password.email.value;
	if (!validateEmail(email)){
		mesg += "Please enter a valid email address.\n";
	}

	if(mesg){
		alert(mesg);
		return false;
	}else{
		return true;
	}
}


function checkRequest(){
	var mesg = '';
	var charReg = /[^a-zA-Z0-9]/;
	var name = document.request.name.value;
	var email = document.request.email.value;

	if (!validateEmail(email)){
		mesg += "Please enter a valid email address.\n";
	}

	if(name.length == 0 || name == 'Name of plant'){
		mesg += "Please enter the name of the plant you want us to add.\n";
	}

	if(mesg){
		alert(mesg);
		return false;
	}else{
		return true;
	}
}


function checkReport(){
	var mesg = '';
	var charReg = /[^a-zA-Z0-9]/;
	var name = document.report.name.value;
	var email = document.report.email.value;
	var report = document.report.details.value;

	if (!validateEmail(email)){
		mesg += "Please enter a valid email address.\n";
	}
	
	if(name.length == 0){
		mesg += "Please enter your name.\n";
	}
	
	if(report.length == 0){
		mesg += "Please enter your comments.\n";
	}

	if(mesg){
		alert(mesg);
		return false;
	}else{
		return true;
	}
}


function checkReview(){
	var mesg = '';
	var charReg = /[^a-zA-Z0-9]/;
	var name = document.review.reviewer.value;
	var review = document.review.details.value;
	var email = document.review.email.value;

	if (!validateEmail(email)){
		mesg += "Please enter a valid email address.\n";
	}

	if(name.length == 0 || name == 'Your name'){
		mesg += "Please enter your name.\n";
	}

	if(review.length == 0 || review == 'Your review'){
		mesg += "Please enter your review.\n";
	}

	if(mesg){
		alert(mesg);
		return false;
	}else{
		return true;
	}
}


function checkSearch(){
	var mesg = '';
	var charReg = /[^a-zA-Z0-9]/;
	var keywords = document.site_searcher.search_for.value;

	if(keywords.length == 0 || keywords == 'Enter search term'){
		mesg += "Please enter a search term.\n";
	}

	if(mesg){
		alert(mesg);
		return false;
	}else{
		return true;
	}
}


function addToGarden(plant, garden, check){
	if(check){
		openWin('sitePlantCheck.php?gardenid=' + garden + '&plantid=' + plant, 'plantCheck', 'width=400, height=400, scrollbars, status');
	}
	document.planter.process.value = 'garden';
	document.planter.gardenid.value = garden;
	document.planter.plantid.value = plant;
	document.planter.submit();
}


function addToWishList(plant, garden, check){
	if(check){
		openWin('sitePlantCheck.php?gardenid=' + garden + '&plantid=' + plant, 'plantCheck', 'width=400, height=400, scrollbars, status');
	}
	document.planter.process.value = 'wishlist';
	document.planter.gardenid.value = garden;
	document.planter.plantid.value = plant;
	document.planter.submit();
}


function removePlant(plant){
	document.uproot.process.value = 'plant';
	document.uproot.garden_plant_linkid.value = plant;
	document.uproot.submit();
}


function removeWishList(plant){
	document.planter.plantid.value = plant;
	document.planter.submit();
}


function removeGroup(group){
	document.grouper.process.value = 'remove';
	document.grouper.groupid.value = group;
	document.grouper.submit();
}


function addGardenDetails(gardenid){
	window.opener.location.href = 'serviceAccount.php?mode=garden&gardenid=' + gardenid;
	window.opener.focus();
	window.close();
}



function resetProvider(){
	document.search.provider.value = '';
	if(document.search.data_countyid){
		document.search.data_countyid[0].selected = true;	
	}
	if(document.search.site_garden_budgetid){
		document.search.site_garden_budgetid[0].selected = true;
	}
	if(document.search.site_garden_styleid){
		document.search.site_garden_styleid[0].selected = true;
	}
	if(document.search.site_garden_productid){
		document.search.site_garden_productid[0].selected = true;
	}
	if(document.search.plant_typeid){
		document.search.plant_typeid[0].selected = true;
	}
	if(document.search.site_user_retailer_typeid){
		document.search.site_user_retailer_typeid[0].selected = true;
	}
}

function resetGardenProfiler(){
	document.search.garden_owner.value = '';
	document.search.garden_postcode.value = '';
	if(document.search.site_garden_styleid){
		document.search.site_garden_styleid[0].selected = true;
	}
	if(document.search.data_countyid){
		document.search.data_countyid[0].selected = true;
	}
	document.search.garden_for_sale.checked = false;
}


function checkIdentifier(stage){
	var mesg = '';
	if(stage == 1){
		var cTag = document.getElementsByTagName("input");
		var iTag = cTag.length;
		var type = false;
		var feature = false;
		var arg1 = /plant_type_group.*/;
		var arg2 = /plant_feature.*/;
		for(i=0; iTag > i; i++){
			var name = cTag[i].name;
			if(cTag[i].type == "checkbox"){
				if(arg1.test(name)){
					if(cTag[i].checked == true){
						type = true;
					}
				}
				if(arg2.test(name)){
					if(cTag[i].checked == true){
						feature = true;
					}
				}
			}
		}
		if(!type){
			mesg += 'Please choose at least one plant type.\n';
		}
		if(!feature){
			mesg += 'Please choose at least one plant feature.\n';
		}
	}
	if(mesg){
		alert(mesg);
		return false;
	}else{
		return true;
	}
}


function resetPlantIdentifier(stage){
	if(stage == 1){
		resetCheckBoxes(false, 'plant');
	}else if(stage == 2){
		resetSelects(false);
	}
}


function checkNote(){
	var mesg = '';
	var charReg = /[^a-zA-Z0-9]/;
	var name = document.note.name.value;

	if(name.length == 0){
		mesg += "Please enter a title for your note.\n";
	}

	if(mesg){
		alert(mesg);
		return false;
	}else{
		return true;
	}
}


function limitText(limit, ele, mesg){
	if(ele.value.length > limit){
		var len = ele.value.length;
		var text = ele.value;
		ele.value = text.substring(0, limit);
		var mesg = document.getElementById(mesg);
		mesg.innerHTML = limit + ' characters maximum - ' + len + ' is too many';
	}else{
		var mesg = document.getElementById(mesg);
		mesg.innerHTML = limit + ' characters maximum - ' + (limit - ele.value.length) + ' remaining';
	}
}


function toggleNote(id){
	var el = document.getElementById('note' + id);
	if(el.style.display == 'none'){
		el.style.display = '';
	}else{
		el.style.display = 'none';
	}
}


function checkGroup(){
	var mesg = '';
	var name = document.account.name.value;

	if(!name){
		mesg += "Please enter a name for the group.\n";
	}

	if(mesg){
		alert(mesg);
		return false;
	}else{
		return true;
	}
}


function doGroup(){
	var len = document.grouper.site_garden_groupid.length;
	var sel = document.grouper.site_garden_groupid.selectedIndex;
	if(parseInt(sel + 1) == len){
		document.location = 'serviceAccount.php?mode=group&gardenid=' + document.grouper.gardenid.value + '&groupid=new';
	}else if(parseInt(sel + 1) == parseInt(len - 1)){

	}else{
		document.grouper.submit();
	}
}


function retailerSearch(el){

	if(el.id == 'plant_typeid'){
		document.search.site_garden_productid[0].selected=true;
	}else if(el.id == 'site_garden_productid'){
		document.search.plant_typeid[0].selected=true;
	}
}




// -->
