// JavaScript Document
// functions using in incregistration.php for registration.php
function checkval()
{
	if(document.getElementById("name").value=="")
	{
		alert("Enter Full Name");
		document.getElementById("name").focus();
		return false;
	}
	if(!isEmail(trim(document.getElementById("email").value)))
	{
		alert("Please enter Valid Email Address");
		document.getElementById("email").focus();
		return false;
	}
	if(document.getElementById("cemail").value=="")
	{
		alert("Please confirm email");
		document.getElementById("cemail").focus();
		return false;
	}	
	if(document.getElementById("email").value != document.getElementById("cemail").value)
	{
		alert("Email and Confirm email are not equal");
		document.getElementById("cemail").focus();
		return false;
	}
	if(document.getElementById("password").value=="")
	{
		alert("Enter Password.");
		document.getElementById("password").focus();
		return false;
	}
	if(document.getElementById("password").value != "")
	{
		if(document.getElementById("password").value.length < 6)
		{
			alert("Password should not less than 6 characters");
			document.getElementById("password").focus();
			return false;
		}
	}
	if(document.getElementById("cpassword").value == "")
	{
		alert("enter confirn Password");
		document.getElementById("cpassword").focus();
		return false;
	}
	if(document.getElementById("cpassword").value != document.getElementById("password").value)
	{
		alert("Password and Confirm Password are not equal");
		document.getElementById("password").focus();
		return false;
	}
	if(document.getElementById("location").value=="")
	{
		alert("Enter your location");
		document.getElementById("location").focus();
		return false;
	}
	
	if(document.getElementById("securityq").value=="select")
	{
		alert("Choose Question for your security");
		document.getElementById("securityq").focus();
		return false;
	}
	if(document.getElementById("securityqans").value=="")
	{
		alert("Please give answer for security question");
		document.getElementById("securityqans").focus();
		return false;
	}

	if(document.getElementById("terms").checked!=true)
	{
		alert("Check Terms & Conditions");
		document.getElementById("terms").focus();
		return false;
	}
	document.getElementById("insert1").value=1;
	document.registration.submit();
}
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
} 
function isEmail(str)
{
	var regex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; 
	return regex.test(str);
}



//**************
//****************************
//******************************************
// functions using in inclogin.php for ligin.php
function checksignin()
{
	if(!isEmail(trim(document.getElementById("email").value)))
	{
		alert("Please enter Valid Email Address");
		document.getElementById("email").focus();
		return false;
	}
	if(document.getElementById("password1").value=="")
	{
		alert("Enter Password.");
		document.getElementById("password1").focus();
		return false;
	}
	
}

function activeforgot()
{
	document.getElementById("divforgot").style.display="block";
	document.getElementById("divlogin").style.display="none";
}
function activelogin()
{
	document.getElementById("divforgot").style.display="none";
	document.getElementById("divlogin").style.display="block";
}

function sendpassword()
{
	if(!isEmail(trim(document.getElementById("femail").value)))
	{
		alert("Please enter Valid Email Address");
		document.getElementById("femail").focus();
		return false;
	}
	else if(document.getElementById("securityq").value=="select")
	{
		alert("Select your security question");
		document.getElementById("securityq").focus();
		return false;
	}
	else if(document.getElementById("securityqans").value=="")
	{
		alert("Give answer for your security question");
		document.getElementById("securityqans").focus();
		return false;
	}
	else
	{
		document.getElementById("forgot1").value=1;
		document.formforgot.submit();
	}
}

//**************
//****************************
//******************************************
// functions using in inccontact.php for contact.php
function contact()
{
	if(document.getElementById("cname").value=="")
	{
		alert("Enter Your Name.");
		document.getElementById("cname").focus();
		return false;
	}
	if(!isEmail(trim(document.getElementById("cemail").value)))
	{
		alert("Please enter Valid Email Address");
		document.getElementById("cemail").focus();
		return false;
	}
	if(document.getElementById("csuggestions").value=="")
	{
		alert("Enter Your Suggestions.");
		document.getElementById("csuggestions").focus();
		return false;
	}
	if(document.getElementById("ccomplaints").value=="")
	{
		alert("Enter Your Complaints.");
		document.getElementById("ccomplaints").focus();
		return false;
	}
	document.getElementById("sendcontact").value=1;
	document.getElementById("contactform").submit();
	return true;
}

//**************
//****************************
//******************************************
// functions using in incupload.php for upload.php
function uploadimage ()
{
	if(document.getElementById("common_name").value=="")
	{
		alert("Enter Common Name for Plant.");
		document.getElementById("common_name").focus();
		return false;
	}
	if(!checkfiletype(document.getElementById("image1").value))
	{
		//alert("select file");
		document.getElementById("image1").focus();
		return false
	}
	//if(!checkfiletype(document.getElementById("image2").value))
//	{
//		//alert("select file");
//		document.getElementById("image2").focus();
//		return false
//	}
//	if(!checkfiletype(document.getElementById("image3").value))
//	{
//		//alert("select file");
//		document.getElementById("image3").focus();
//		return false
//	}
	//if(document.getElementById("plant_type").value=="select")
//	{
//		alert("Select Plant type");
//		document.getElementById("plant_type").focus();
//		return false;
//	}
	else if(document.getElementById("decoration_purposes").value=="select")
	{
		alert("Select Decoration Purposes");
		document.getElementById("decoration_purposes").focus();
		return false;
	}
	else if(document.getElementById("decorative_parts").value=="select")
	{
		alert("Select Decorative Parts");
		document.getElementById("decorative_parts").focus();
		return false;
	}
	else if(document.getElementById("shapeof_adultPlant").value=="select")
	{
		alert("Select Shape of the Adult Plant - Shrubs and Trees only");
		document.getElementById("shapeof_adultPlant").focus();
		return false;
	}
	else if(document.getElementById("growth_habits").value=="select")
	{
		alert("Select Growth Habits - Herbaceous Only");
		document.getElementById("growth_habits").focus();
		return false;
	}
	else if(document.getElementById("foliage_color").value=="select")
	{
		alert("Select Foliage Colour");
		document.getElementById("foliage_color").focus();
		return false;
	}
	else if(document.getElementById("flower_color").value=="select")
	{
		alert("Select Flower Colour");
		document.getElementById("flower_color").focus();
		return false;
	}
	else if(document.getElementById("height").value=="select")
	{
		alert("Select Height of Plant");
		document.getElementById("height").focus();
		return false;
	}
	else if(document.getElementById("hardiness").value=="select")
	{
		alert("Select Hardiness - Average Minimum Temperature");
		document.getElementById("hardiness").focus();
		return false;
	}
	else
	{
		document.getElementById("upload1").value=1;
		document.formupload.submit();
		return true;	
	}

}

function checkfiletype(str1)
{
	if(str1=="")
	{
		alert("select jpg, jpeg,gif, png or bmp file to upload");
		return false;
	}
	else
	{
		var	fName=str1;
		var name=fName.split("\\");
		a=name.length;
		var fullName = name[a-1];
		var splitName = fullName.split(".");
		var fileType = splitName[1];
		fileType = fileType.toLowerCase();
		if (fileType!='jpg' && fileType!='jpeg' && fileType!='png' && fileType!='bmp' && fileType!='gif')
		{
			alert("You have to select jpg, jpeg,gif, png or bmp file");
			return false;			
		}
		return true;
	}
}



//**************
//****************************
//******************************************
// functions using in incpicturegallery.php for picturegallery.php
function popwin(url)
{


// Script Source: CodeLifter.com
// Copyright 2003
// Do not remove this notice.

// SETUPS:
// ===============================

// Set the horizontal and vertical position for the popup

PositionX = 100;
PositionY = 100;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

defaultWidth  = 500;
defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows

var AutoClose = true;

// Do not edit below this line...
// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;

popImage(url,"Image");

function popImage(imageURL,imageTitle){
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(300,300);');
writeln('width=300-(document.body.clientWidth-document.images[0].width);');
writeln('height=300-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=FFFFFF scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=FFFFFF scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<img name="George" src="'+imageURL+'" style="display:block"></body></html>');
close();		
}}

}

function popwindow(url,w, h)
{
pollwindow=window.open(url,'pollwindow','top=0,left=0,status=no,toolbars=no,scrollbars=yes,width='+w+',height='+h+',maximize=no,resizable');
pollwindow.focus();
}


//**************
//****************************
//******************************************
// functions using in main1.dwt.php for main1.dwt.php
function searchtext()
{
	if(document.getElementById("searchname").value=="")
	{
		alert("Please Enter Plant Name");
		document.getElementById("searchname").focus();
		return false;
	}
	else
	{
		document.getElementById("search1").value=document.getElementById("searchname").value;
		document.searchbyname.action="plantdetail.php?page=1";
		document.searchbyname.submit();
	}
}

function advancesearch()
{
	document.getElementById("advsearch").value=1;
	document.formadvancesearch.action="plantdetail.php?page=1";
	document.formadvancesearch.submit();
}

function notadvsearch(pid)
{
	alert("You have to login to access this feature");
	location.href="login.php?pid="+pid;
}
function notadvsearch1(pid)
{
	alert("You have to login to access this feature");
	location.href="login.php";
}
function checkreview(pid)
{
	var val=confirm("You have to login to access this feature. Click Ok to login");
	if(val==true){
		location.href="login.php";
	}
}
function searchtext3()
{
	if(document.getElementById("searchuser").value=="")
	{
		alert("Please Enter User Name");
		document.getElementById("searchuser").focus();
		return false;
	}
	else
	{
		document.getElementById("search3").value=document.getElementById("searchuser").value;
		document.searchbyuser.action="plantdetail.php";	//+"&c="+c;
		document.searchbyuser.submit();
	}
}

//**************
//****************************
//******************************************
// functions using in incviewcomment.dwt.php for viewcomment.php

function addreview()
{
/*	if(document.getElementById("username").value=="")
	{
		alert(Please Enter your name);
		document.getElementById("username").focus();
		return false
	}
	else if(!isEmail(trim(document.getElementById("cemail").value)))
	{
		alert("Please enter Valid Email Address");
		document.getElementById("cemail").focus();
		return false;
	}
	else if(document.getElementById("review").value=="")
	{
		alert(Please Enter your name);
		document.getElementById("review").focus();
		return false
	}*/
	
		if(document.getElementById("review").value==""){
			alert('Please enter your comments');
			document.getElementById("review").focus();
		}	
		else
		{
			document.formaddreview.submit();
		}

}


/********** Function for the popup window for the terms displayed in the registration file ********/
function mypopup()
 {
	mywindow = window.open ("inc/incterms.php",  "mywindow","location=1,status=1,scrollbars=1, toobar=0, menubar=0,  width=300,height=400");	
	mywindow.moveTo(0,0);
 } 
 
 
 /***** for the chagepassword used in the incmyaccount.php **/
 function fnchanagepass_valid()
 {
	 if(document.getElementById("password").value==""){
			alert('Please enter password');
			document.getElementById("password").focus();			
		}
	else if(document.getElementById("cpassword").value==""){
			alert('Please confirm password');
			document.getElementById("cpassword").focus();			
		}
	else if(document.getElementById("cpassword").value != document.getElementById("password").value ){
			alert('Both password does not matched ?');
			document.getElementById("cpassword").focus();
		}
	else{
			document.frmpass.submit();
		}
 }
 

//**************
//****************************
//******************************************
// functions using in add_upload.php for Administrator
function adminuploadimage()
{	
	
	if(document.getElementById("common_name").value=="")
	{
		alert("Enter Common Name for Plant");
		document.getElementById("common_name").focus();
		return false;
	} 

	if(document.getElementById("plant_type").value=="select")
	{
		alert("Select Plant type");
		document.getElementById("plant_type").focus();
		return false;
	}
	else if(document.getElementById("decoration_purposes").value=="select")
	{
		alert("Select Decoration Purposes");
		document.getElementById("decoration_purposes").focus();
		return false;
	}
	else if(document.getElementById("decorative_parts").value=="select")
	{
		alert("Select Decorative Parts");
		document.getElementById("decorative_parts").focus();
		return false;
	}
	else if(document.getElementById("shapeof_adultPlant").value=="select")
	{
		alert("Select Shape of the Adult Plant - Shrubs and Trees only");
		document.getElementById("shapeof_adultPlant").focus();
		return false;
	}
	else if(document.getElementById("growth_habits").value=="select")
	{
		alert("Select Growth Habits - Herbaceous Only");
		document.getElementById("growth_habits").focus();
		return false;
	}
	else if(document.getElementById("foliage_color").value=="select")
	{
		alert("Select Foliage Colour");
		document.getElementById("foliage_color").focus();
		return false;
	}
	else if(document.getElementById("flower_color").value=="select")
	{
		alert("Select Flower Colour");
		document.getElementById("flower_color").focus();
		return false;
	}
	else if(document.getElementById("height").value=="select")
	{
		alert("Select Height of Plant");
		document.getElementById("height").focus();
		return false;
	}
	else if(document.getElementById("hardiness").value=="select")
	{
		alert("Select Hardiness - Average Minimum Temperature");
		document.getElementById("hardiness").focus();
		return false;
	}
	else
	{
		document.formupload.submit();
		return true;	
	}

}


//**************
//****************************
//******************************************
// functions using in incuploadpest.php for pest.php

function uploadpest()
{
	if(document.getElementById("common_name").value=="")
	{
		alert("Enter Common Name for Plant.");
		document.getElementById("common_name").focus();
		return false;
	}
	if(!checkfiletype(document.getElementById("image1").value))
	{
		//alert("select file");
		document.getElementById("image1").focus();
		return false;
	}
	//if(!checkfiletype(document.getElementById("image2").value))
	//{
		//alert("select file");
		//document.getElementById("image2").focus();
		//return false;
	//}
	//if(!checkfiletype(document.getElementById("image3").value))
	//{
		//alert("select file");
		//document.getElementById("image3").focus();
		//return false;
	//}
	document.getElementById("upload1").value=1;
	document.getElementById("pagetask").value="uploadpest";
	document.formuploadpest.action="pest.php?page=10";
	document.formuploadpest.submit();
	return true;	

}

//**************
//****************************
//******************************************
// functions using in incpestsearch.php for pest.php for searching features

function searchpest1()
{
	document.formspestbyname.search1.value=1;
	document.formspestbyname.pagetask.value="pestdetail";
	document.formspestbyname.action="pest.php?page=2";
	document.formspestbyname.submit();
}

function searchpest2()
{
	document.formspestbyattac.search2.value=2;
	document.formspestbyattac.pagetask.value="pestdetail";
	document.formspestbyattac.action="pest.php?page=2";
	document.formspestbyattac.submit();
}

function searchpest3()
{
	document.formspestbymember.search3.value=3;
	document.formspestbymember.pagetask.value="pestdetail";
	document.formspestbymember.action="pest.php?page=2";
	document.formspestbymember.submit();
}

function searchpest4()
{
	document.formspestbygroup.search4.value=4;
	document.formspestbygroup.pagetask.value="pestdetail";
	document.formspestbygroup.action="pest.php?page=2";
	document.formspestbygroup.submit();
}


//**************
//****************************
//******************************************
// functions using in incgardenssearch.php for gardens.php for searching features

function searchgardens1()
{
	if(document.formsgardensbyname.searchtext.value=="")
	{
		alert("Enter Garden's location you want to search...!");
		document.formsgardensbyname.searchtext.focus();
		return false;
	}
	else
	{
		document.formsgardensbyname.search1.value=1;
		document.formsgardensbyname.pagetask.value="gdetail";
		document.formsgardensbyname.action="gardens.php?page=3";
		document.formsgardensbyname.submit();
	}
}

function searchgardens2()
{
	document.formgardensbycategory.search2.value=2;
	document.formgardensbycategory.pagetask.value="gdetail";
	document.formgardensbycategory.action="gardens.php?page=3";
	document.formgardensbycategory.submit();
}

function searchgardens3()
{
	if(document.formgardensbyelement.softscape1.value=="" && document.formgardensbyelement.hardscape1.value=="")
	{
		alert("Please Select Element for Search..!");
		document.formgardensbyelement.softscape1.focus();
		return false;
	}
	else
	{
		document.formgardensbyelement.search3.value=3;
		document.formgardensbyelement.pagetask.value="gdetail";
		document.formgardensbyelement.action="gardens.php?page=3";
		document.formgardensbyelement.submit();
	}
}

function searchgardens4()
{
	if(document.formgardensbyowner.searchtext4.value=="")
	{
		alert("Enter Name of Garden or Owner to search...!");
		document.formgardensbyowner.searchtext4.focus();
		return false;
	}
	else
	{
		document.formgardensbyowner.search4.value=4;
		document.formgardensbyowner.pagetask.value="gdetail";
		document.formgardensbyowner.action="gardens.php?page=3";
		document.formgardensbyowner.submit();
	}
}

function searchgardens5()
{
	if(document.formgardensbymember.searchtext5.value=="")
	{
		alert("Enter Name of Member to search...!");
		document.formgardensbymember.searchtext5.focus();
		return false;
	}
	else
	{
		document.formgardensbymember.search4.value=5;
		document.formgardensbymember.pagetask.value="gdetail";
		document.formgardensbymember.action="gardens.php?page=3";
		document.formgardensbymember.submit();
	}
}

function zoomgarden(gid)
{
	alert("You have to login to access this feature");
	location.href="login.php?gid="+gid;
}



//**************
//****************************
//******************************************
// functions using in add_pest.php for Administration in siteadmin

function adminuploadpest()
{
	if(document.getElementById("common_name").value=="")
	{
		alert("Enter Common Name for Plant.");
		document.getElementById("common_name").focus();
		return false;
	}
	document.formuploadpest.submit();
	return true;	

}


//**************
//****************************
//******************************************
// functions using in add_gardens.php for Administration in siteadmin

function adminuploadgarden()
{
	if(document.getElementById("common_name").value=="")
	{
		alert("Enter Common Name for Garden.");
		document.getElementById("common_name").focus();
		return false;
	}
	document.formuploadgarden.submit();
	return true;	

}


//**************
//****************************
//******************************************
// functions using in add_gardens.php for Administration in siteadmin

function adminuploadgardens()
{
	if(document.getElementById("common_name").value=="")
	{
		alert("Enter Common Name for Plant.");
		document.getElementById("common_name").focus();
		return false;
	}
	document.formuploadgardens.submit();
	return true;	

}

//**************
//****************************
//******************************************
// functions using in add_advert.php for Administration in siteadmin
//	to add and edit Advertistment

function advert()
{
	if(document.getElementById("adname").value=="")
	{
		alert("Enter Name for Advertisemtent");
		document.getElementById("common_name").focus();
		return false;
	}
	if(document.getElementById("adtext").value.length > 1000)
	{
		alert("Enter onlu 1000 character description");
		document.getElementById("adtext").focus();
		return false;
	}
	document.formadvert.submit();
	return true;	

}




//**************
//****************************
//******************************************
// functions using in add_pestreview.php for Administration in siteadmin
//	to add and edit comment on pest

function adminpestaddreview()
{
		if(document.getElementById("review").value=="")
		{
			alert('Please enter your comments');
			document.getElementById("review").focus();
		}	
		else
		{
		document.formuploadpest.submit();
		}	
}
function adminplantaddreview()
{
		if(document.getElementById("review").value=="")
		{
			alert('Please enter your comments');
			document.getElementById("review").focus();
		}	
		else
		{
		document.formuploadplant.submit();
		}	
}
function admingardensaddreview()
{
		if(document.getElementById("review").value=="")
		{
			alert('Please enter your comments');
			document.getElementById("review").focus();
		}	
		else
		{
		document.formuploadgardens.submit();
		}	
}

//**************
//****************************
//******************************************
// functions using in incuploadgardens.php in gardens.php

function gardenupload()
{
	if(document.getElementById("common_name").value=="")
	{
		alert("Enter Common name of Garden or Owner or Item");
		document.getElementById("common_name").focus();
		return false;
	}
	<!--if(!checkfiletype(document.getElementById("image1").value))
	//{
		//alert("select file");
		//document.getElementById("image1").focus();
		//return false;
	//}
	//if(!checkfiletype(document.getElementById("image2").value))
	//{
		//alert("select file");
		//document.getElementById("image2").focus();
		//return false;
	//}-->
	if(!checkfiletype(document.getElementById("image3").value))
	{
		//alert("select file");
		document.getElementById("image3").focus();
		return false;
	}
	//if(!checkfiletype(document.getElementById("image4").value))
//	{
//		//alert("select file");
//		document.getElementById("image4").focus();
//		return false;
//	}
//	if(!checkfiletype(document.getElementById("image5").value))
//	{
//		//alert("select file");
//		document.getElementById("image5").focus();
//		return false;
//	}
	document.formuploadgarden.upload1.value=1;
	//document.getElementById("pagetask").value="uploadpest";
	document.formuploadgarden.action="gardens.php?page=10";
	document.formuploadgarden.submit();
	return true;	
}
