
function mytrim(val)
{
		val1 = "";
		val2="";
		ctrr = 0;
		lngth = val.length;
		for (i=0; i<lngth; i++)
		{
		if (val.charCodeAt(i) != 32)
		{
		for(j=i;j<lngth;j++)
		{
		if (val.charCodeAt(j) != 13 && val.charCodeAt(j) != 10 )
			{
			val1 += val.charAt(j);
			}
		}
		break;
		}
		}
		if (val1 != "")
		{
		lngth = val1.length
		ctrr=lngth;
		for (k=0; k<lngth; k++)
		{
		ctrr=ctrr-1;
		if (val1.charCodeAt(ctrr) != 32)
		{
		for(l=0;l<lngth-k;l++)
		{
		val2 += val1.charAt(l);
		}
		val1=val2;
		break;
		}
		}
		}
		return val1;
}
function IsNumeric(sText)
 {
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;


   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;

 }
function chkemail(email)
{
	var emailvalid=true;

		if (email.value.length < 5)
		{
			emailvalid=false;
		}
		else
		{

			var flag = "false";
			var flag1 = "false";
			var flag2="true";
			for (var i = 1; i < email.value.length; i++)
			{
				var ch = email.value.substring(i, i + 1);
				if (ch == ".")
				{
					flag = "true";
				}
				if (ch == "@")
				{
					flag1 = "true";
				}
				if (ch==" ")
				{
					flag2="false";
				}

			}
			if (flag == "false" || flag1 == "false" || flag2 == "false")
			{
				emailvalid=false;
			}
		}
		return emailvalid;
}
 


function emptyvalue(x1) {

 if(x1.value=="First Name" || x1.value=="Last Name" || x1.value=="Name"  || x1.value=="Email Address"  ||  x1.value=="Email Id"||  x1.value=="Street Address" || x1.value=="City" || x1.value=="State/Province" ||  x1.value=="Zip Code" ||  x1.value=="Postal Code" || x1.value=="Mobile Number" || x1.value=="Home Phone" || x1.value=="Mobile" )
 {
  pretext=x1.value;
  	
  x1.style.color='#000000';
  x1.value="";
 } else {

  switch(x1.name) {
  
	case "firstname":
    pretext="First Name";
    break;
   case "lastname":
    pretext="Last Name";
    break;
	case "name":
    pretext="Name";
    break;
	case "email":
    pretext="Email Address";
    break;
	case "email":
    pretext="Email Id";
    break;
	 case "address":
    pretext="Street Address";
    break;
	 case "city":
    pretext="City";
    break;
	 case "state":
    pretext="State/Province";
    break;
   	 case "zip":
    pretext="Zip Code";
    break;
	case "zip":
    pretext="Postal Code";
    break;
	 case "mobile":
    pretext="Mobile Number";
    break;
	case "mobile1":
    pretext="Mobile";
    break;
	 case "phone":
    pretext="Home Phone";
    break;
	  
   default: pretext="";
  }
 }
}

function fillvalue(x1) {
 if (x1.value=="") {
  x1.style.color = '#000000';
  x1.value = pretext;
 }
}

function ValidateVolunteer()
{
	if(mytrim(document.frmvolunteer.firstname.value)=="" || mytrim(document.frmvolunteer.firstname.value)=="First Name")
		{
			  alert("Please enter first name");
			  document.frmvolunteer.firstname.focus();
			  return false;
		}
		if(mytrim(document.frmvolunteer.lastname.value)=="" || mytrim(document.frmvolunteer.lastname.value)=="Last Name")
		{
			  alert("Please enter last name");
			  document.frmvolunteer.lastname.focus();
			  return false;
		}
		var chkFilter=/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
		if (!(chkFilter.test(document.frmvolunteer.email.value))) {
			  alert("Please enter a valid email address");
			  document.frmvolunteer.email.focus();
			  return false;
		}
			if(mytrim(document.frmvolunteer.zip.value)=="" || mytrim(document.frmvolunteer.zip.value)=="Zip Code")
		{
			  alert("Please enter zip code");
			  document.frmvolunteer.zip.focus();
			  return false;
		}
		if (!IsNumeric(document.frmvolunteer.zip.value))
		{
			alert("Please enter valid zip code");
			document.frmvolunteer.zip.focus();
			return false;
		}
		if (document.frmvolunteer.zip.value.length<5)
		{
			alert("Please enter valid zip code");
			document.frmvolunteer.zip.focus();
			return false;
		}
		if (mytrim(document.frmvolunteer.comments.value)=="")
		{
			alert("Please enter comments below 1000 words.");
			document.frmvolunteer.comments.focus();
			return false;
			
		}
		if (document.frmvolunteer.comments.value.length>1000)
			{
				alert("Please enter comments below 1000 words.");
				document.frmvolunteer.comments.focus();
				return false;
			}
		
		
}
function ValidateContact()
{
	if(mytrim(document.frmcontactus.firstname.value)=="" || mytrim(document.frmcontactus.firstname.value)=="First Name")
		{
			  alert("Please enter first name");
			  document.frmcontactus.firstname.focus();
			  return false;
		}
		if(mytrim(document.frmcontactus.lastname.value)=="" || mytrim(document.frmcontactus.lastname.value)=="Last Name")
		{
			  alert("Please enter last name");
			  document.frmcontactus.lastname.focus();
			  return false;
		}
		
			if(mytrim(document.frmcontactus.zip.value)=="" || mytrim(document.frmcontactus.zip.value)=="Zip Code")
		{
			  alert("Please enter zip code");
			  document.frmcontactus.zip.focus();
			  return false;
		}
		if (!IsNumeric(document.frmcontactus.zip.value))
		{
			alert("Please enter valid zip code");
			document.frmcontactus.zip.focus();
			return false;
		}
		if (document.frmcontactus.zip.value.length<5)
		{
			alert("Please enter valid zip code");
			document.frmcontactus.zip.focus();
			return false;
		}
		var chkFilter=/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
		if (!(chkFilter.test(document.frmcontactus.email.value))) {
			  alert("Please enter a valid email address");
			  document.frmcontactus.email.focus();
			  return false;
		}
		if (mytrim(document.frmcontactus.comments.value)=="")
		{
			alert("Please enter comments below 1000 words.");
			document.frmcontactus.comments.focus();
			return false;
			
		}
		if (document.frmcontactus.comments.value.length>1000)
			{
				alert("Please enter comments below 1000 words.");
				document.frmcontactus.comments.focus();
				return false;
			}
		
		
}

function ValidateTellFriend()
	{
		var ret=true;
		if (mytrim(document.frmtellfriend.friend1.value)!="")
		{
			if (!chkemail(document.frmtellfriend.friend1))
			{
				alert("Please enter valid email address");
				document.frmtellfriend.friend1.focus();
				return false;
			}
			ret=false;
		 }
		 if (mytrim(document.frmtellfriend.friend2.value)!="")
		{
			if (!chkemail(document.frmtellfriend.friend2))
			{
				alert("Please enter valid email address");
				document.frmtellfriend.friend2.focus();
				return false;
			}
			ret=false;
		 }
		 if (mytrim(document.frmtellfriend.friend3.value)!="")
		{
			if (!chkemail(document.frmtellfriend.friend3))
			{
				alert("Please enter valid email address");
				document.frmtellfriend.friend3.focus();
				return false;
			}
			ret=false;
		 }
		//	 if (mytrim(document.frmtellfriend.friend4.value)!="")
//		{
//			if (!chkemail(document.frmtellfriend.friend4))
//			{
//				alert("Please enter valid Email Address");
//				document.frmtellfriend.friend4.focus();
//				return false;
//			}
//			ret=false;
//		 }
//		  if (mytrim(document.frmtellfriend.friend5.value)!="")
//		{
//			if (!chkemail(document.frmtellfriend.friend5))
//			{
//				alert("Please enter valid Email Address");
//				document.frmtellfriend.friend5.focus();
//				return false;
//			}
//			ret=false;
//		 }
		
		if(ret==true)
		{
				alert("Please enter atleast one email address");
				document.frmtellfriend.friend1.focus();
				return false;
		}
		else
		{
			 if (mytrim(document.frmtellfriend.email.value)!="")
			{
				if (!chkemail(document.frmtellfriend.email))
				{
					alert("Please enter valid email address");
					document.frmtellfriend.email.focus();
					return false;
				}
			}
			else
			{
					alert("Please enter your email address");
					document.frmtellfriend.email.focus();
					return false;
			}
		}
		
	
		
	}
	function ValidateSignup()
	{
		var chkFilter=/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
		if (!(chkFilter.test(document.signup.email.value))) {
			  alert("Please enter a valid email id");
			  document.signup.email.focus();
			  return false;
		}
		if(mytrim(document.signup.zip.value)=="")
		{
			  alert("Please enter zip code");
			  document.signup.zip.focus();
			  return false;
		}
		if (!IsNumeric(document.signup.zip.value))
		{
			alert("Please enter valid zip code");
			document.signup.zip.focus();
			return false;
		}
		if (document.signup.zip.value.length<5)
		{
			alert("Please enter valid zip code");
			document.signup.zip.focus();
			return false;
		}
		
}
		
function Validatecontactus()
{
	if(mytrim(document.frmcontactus.firstname.value)=="" || mytrim(document.frmcontactus.firstname.value)=="First Name")
		{
			  alert("Please enter first name");
			  document.frmcontactus.firstname.focus();
			  return false;
		}
		if(mytrim(document.frmcontactus.lastname.value)=="" || mytrim(document.frmcontactus.lastname.value)=="Last Name")
		{
			  alert("Please enter last name");
			  document.frmcontactus.lastname.focus();
			  return false;
		}
		if(mytrim(document.frmcontactus.zip.value)=="" || mytrim(document.frmcontactus.zip.value)=="Zip Code")
		{
			  alert("Please enter zip code");
			  document.frmcontactus.zip.focus();
			  return false;
		}
		if (!IsNumeric(document.frmcontactus.zip.value))
		{
			alert("Please enter valid zip code");
			document.frmcontactus.zip.focus();
			return false;
		}
		if (document.frmcontactus.zip.value.length<5)
		{
			alert("Please enter valid zip code");
			document.frmcontactus.zip.focus();
			return false;
		}
		var chkFilter=/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
		if (!(chkFilter.test(document.frmcontactus.email.value))) {
			  alert("Please enter a valid email address");
			  document.frmcontactus.email.focus();
			  return false;
		}
			
		if (mytrim(document.frmcontactus.comments.value)=="")
		{
			alert("Please enter comments below 1000 words.");
			document.frmcontactus.comments.focus();
			return false;
			
		}
		if (document.frmcontactus.comments.value.length>1000)
			{
				alert("Please enter comments below 1000 words.");
				document.frmcontactus.comments.focus();
				return false;
			}
		
		
}
function showdiv()
{
	var k,k1;
	var d = document.getElementById('txtcomments');
	k1=getPosition(d);
	k=k1.split(",");


	
	
	document.getElementById('smilies').style.position = "absolute";
	document.getElementById('smilies').style.top = k[1]+"px";
	document.getElementById('smilies').style.left = k[0]+"px";
	
		document.getElementById('smilies').style.visibility = 'visible'; 
	

}
function hidediv()
{
	document.getElementById('smilies').style.visibility = 'hidden'; 
}
function insertsmile(smile)
{
	var insertS;
	if (document.getElementById('txtcomments').value=="")
	{
		insertS=smile;
	}
	else
	{
		insertS=" "+smile;
	}	
	document.getElementById('txtcomments').value=document.getElementById('txtcomments').value+insertS;
	hidediv();
}
function getPosition(obj){
    var topValue= 0,leftValue= 0;
    while(obj){
	leftValue+= obj.offsetLeft;
	topValue+= obj.offsetTop;
	obj= obj.offsetParent;
    }
    finalvalue = leftValue + "," + topValue;
    return finalvalue;
}
function showdiv()
{
	var k,k1;
	var d = document.getElementById('txtcomments');
	k1=getPosition(d);
	k=k1.split(",");


	
	
	document.getElementById('smilies').style.position = "absolute";
	document.getElementById('smilies').style.top = k[1]+"px";
	document.getElementById('smilies').style.left = k[0]+"px";
	
		document.getElementById('smilies').style.visibility = 'visible'; 
	

}
function hidediv()
{
	document.getElementById('smilies').style.visibility = 'hidden'; 
}
function insertsmile(smile)
{
	var insertS;
	if (document.getElementById('txtcomments').value=="")
	{
		insertS=smile;
	}
	else
	{
		insertS=" "+smile;
	}	
	document.getElementById('txtcomments').value=document.getElementById('txtcomments').value+insertS;
	hidediv();
}
function getPosition(obj){
    var topValue= 0,leftValue= 0;
    while(obj){
	leftValue+= obj.offsetLeft;
	topValue+= obj.offsetTop;
	obj= obj.offsetParent;
    }
    finalvalue = leftValue + "," + topValue;
    return finalvalue;
}


	