//for news updates;
function showProjectPhoto(photoname) 
{ 
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	winWidth = 450;
	winHeight = 400;
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2; 
	window.open("showProjectPhoto.php?photoname=" + photoname,"ProjectPhoto","width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
}
function check(page)
{
var name=document.forms[0].keywords.value;
if(name=='')
	{
		alert("Please enter keyword");
		document.forms[0].keywords.focus(); 
		return false;
	}
	else
	{
			if(page=='m')
			{
			document.forms[0].action="php/searchResult.php?key="+name;
			document.forms[0].submit();
			}
			if(page=='s')
			{
			document.forms[0].action="../php/searchResult.php?key="+name;
			document.forms[0].submit();
			}
	}
}

function checkContact() 
{
   name=trimSpaces(document.feedback.name.value);
  email=trimSpaces(document.feedback.email.value);
address=trimSpaces(document.feedback.address.value);
Comments=trimSpaces(document.feedback.Comments.value);
  
  if(name.length<=0)
  { 
	 alert("You have to enter your Name.");
		document.feedback.name.focus();
		return false;
  }

  if(address.length<=0)
  { 
	 alert("You have to enter your address.");
		document.feedback.address.focus();
		return false;
  }
  if(Comments.length<=0)
  { 
	 alert("You have to enter your Comments.");
		document.feedback.Comments.focus();
		return false;
  }
  
		if(!checkEmail(email)) {
			document.feedback.email.value='';
			document.feedback.email.focus();
			return false;
	 }
  
	document.feedback.frmAction.value="Save"; 
	return true;
}

function trimSpaces(stringValue) {
	// Checks the first occurance of spaces and removes them
	for(i = 0; i < stringValue.length; i++) {
		if(stringValue.charAt(i) != " ") {
			break;
		}
	}
	if(i > 0) {
		stringValue = stringValue.substring(i);
	}
	
	// Checks the last occurance of spaces and removes them
	strLength = stringValue.length - 1;
	for(i = strLength; i >= 0; i--) {
		if(stringValue.charAt(i) != " ") {
			break;
		}
	}
	if(i < strLength) {
		stringValue = stringValue.substring(0, i + 1);
	}
	
	// Returns the string after removing leading and trailing spaces.
	return stringValue;
}

function checkGuestFeedBack() {
	document.forms[0].visitorName.value = trimSpaces(document.forms[0].visitorName.value);
	if(document.forms[0].visitorName.value.length <= 0) {
		alert("Please enter your name");
		document.forms[0].visitorName.focus();
		return false;
	}

	document.forms[0].emailAddress.value = trimSpaces(document.forms[0].emailAddress.value);
	if(document.forms[0].emailAddress.value.length <= 0) {
		alert("Please enter your email address");
		document.forms[0].emailAddress.focus();
		return false;
	}
	if(!checkEmail(document.forms[0].emailAddress.value)) {
		document.forms[0].emailAddress.focus();
		document.forms[0].emailAddress.select();
		return false;
	}

	document.forms[0].visitorComments.value = trimSpaces(document.forms[0].visitorComments.value);
	if(document.forms[0].visitorComments.value.length <= 0) {
		alert("Please enter your comments");
		document.forms[0].visitorComments.focus();
		return false;
	}
	document.forms[0].frmAction.value = "update";
}
function closeWindow() {
	parent.window.opener.window.focus();
	parent.window.close();
}
function openDynWindow(url) { 
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	winWidth = 700;
	winHeight = 500;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;
	window.open(url, "Reviews", "width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
}
function checkMoreInfo1() 
{
       

			 uname=trimSpaces(document.forms[0].uname.value);
	     lname=trimSpaces(document.forms[0].lname.value);
		   email=trimSpaces(document.forms[0].email.value);
		   address=trimSpaces(document.forms[0].address.value);
			 
			 state=trimSpaces(document.forms[0].state.value);
			 city=trimSpaces(document.forms[0].city.value);

  if(uname.length<=0)
  { 
	 alert("You have to enter your first name.");
		document.forms[0].uname.focus();
		return false;
	
	}
	  
	 
	if(lname.length<=0)
  {
	 alert("You have to enter your last name.");
		document.forms[0].lname.focus();
		return false;
	
	}
	if(address.length<=0)
  {
	  alert("You have to enter your address.");
		document.forms[0].address.focus();
		return false;
	
	}
	
	
	
	if(document.forms[0].country.selectedIndex<=0)
  { 
	 alert("You have to enter the country name.");
		document.forms[0].uname.focus();
		return false;
	
	}
	  
	
	if(state.length<=0)
  { 
	 alert("You have to enter the state .");
		document.forms[0].state.focus();
		return false;
	
	}
	if(city.length<=0)
  { 
	 alert("You have to enter the city .");
		document.forms[0].city.focus();
		return false;
	
	}
	 if(email.length>0)
	 {
	if(!checkEmail(email)) {
		document.forms[0].email.focus();
		return false;
	} 
	 }
  
document.forms[0].frmAction.value="Update"; 


	return true;


}
function openCustWindow(href,winWidth,winHeight) {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;

	window.open(href, "News", "width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
	return;
} 

function openCustWindow1(id) {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	winWidth=500;
	winHeight=500;
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;

	window.open("searchPhoto.php?photoid="+id, "News", "width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
	return;
} 



function checkFeedBack() {
	document.forms[0].visitorName.value = trimSpaces(document.forms[0].visitorName.value);
	if(document.forms[0].visitorName.value.length <= 0) {
		alert("Please enter your name");
		document.forms[0].visitorName.focus();
		return false;
	}

	document.forms[0].emailAddress.value = trimSpaces(document.forms[0].emailAddress.value);
	if(document.forms[0].emailAddress.value.length <= 0) {
		alert("Please enter your email address");
		document.forms[0].emailAddress.focus();
		return false;
	}
	if(!checkEmail(document.forms[0].emailAddress.value)) {
		document.forms[0].emailAddress.focus();
		document.forms[0].emailAddress.select();
		return false;
	}

	document.forms[0].visitorComments.value = trimSpaces(document.forms[0].visitorComments.value);
	if(document.forms[0].visitorComments.value.length <= 0) {
		alert("Please enter your comments");
		document.forms[0].visitorComments.focus();
		return false;
	}
	document.forms[0].frmAction.value = "update";
}


function showPicture(gid,cid) {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	winWidth = 600;
	winHeight = 500;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;

	window.open("showPicture.php?galleryid=" + gid + "&category=" +cid, "picture", "width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
	return;
}

function checkEmail(emailString) {
	splitVal = emailString.split('@');
	if(splitVal.length <= 1) {
		alert("Please enter a valid email address");
		return false;
	}
	if(splitVal[0].length <= 0 || splitVal[1].length <= 0) {
		alert("Please enter a valid email address");
		return false;
	}
	
	splitDomain = splitVal[1].split('.');
	if(splitDomain.length <= 1) {
		alert("Please enter a valid email address");
		return false;
	}
	if(splitDomain[0].length <= 0 || splitDomain[1].length <= 1) {
		alert("Please enter a valid email address");
		return false;
	}
	return true;
}


function checkContacts() 
{
   	uname=trimSpaces(document.more.uname.value);
   	email=trimSpaces(document.more.email.value);
	address=trimSpaces(document.more.address.value);
	phone=trimSpaces(document.more.phone.value);
  
  if(uname.length<=0)
  { 
	 alert("You have to enter your name.");
		document.more.uname.focus();
		return false;
  }

  if(address.length<=0)
  { 
	 alert("You have to enter your address.");
		document.more.address.focus();
		return false;
  }
  if(phone.length<=0)
  { 
	 alert("You have to enter your phone number.");
		document.more.phone.focus();
		return false;
  }
  
		if(!checkEmail(email)) {
			document.more.email.focus();
			return false;
	 }
  
	document.more.frmAction.value="Update"; 
	return true;
}

	

function checkOrderForm() 
{
       
uname=trimSpaces(document.form1.Name.value);
Street=trimSpaces(document.form1.Street.value);
City=trimSpaces(document.form1.City.value);
State=trimSpaces(document.form1.State.value);
Post=trimSpaces(document.form1.Post.value);
Country=trimSpaces(document.form1.Country.value);
email=trimSpaces(document.form1.email.value);
Queries=trimSpaces(document.form1.Queries.value);
 
  if(uname.length<=0)
  { 
	 alert("You have to enter your name.");
		document.form1.Name.focus();
		return false;
  }

  if(Street.length<=0)
  { 
	 alert("You have to enter street name.");
		document.form1.Street.focus();
		return false;
  }
  
  if(City.length<=0)
  { 
	 alert("You have to enter city name.");
		document.form1.City.focus();
		return false;
  }
  if(State.length<=0)
  { 
	 alert("You have to enter State.");
		document.form1.State.focus();
		return false;
  }
  if(Post.length<=0)
  { 
	 alert("You have to enter Zip code.");
		document.form1.Post.focus();
		return false;
  }
  if(Country.length<=0)
  { 
	 alert("You have to enter country.");
		document.form1.Country.focus();
		return false;
  }
		if(!checkEmail(email)) {
			document.form1.email.focus();
			return false;
	 }
   if(Queries.length<=0)
  { 
	 alert("You have to enter Comment.");
		document.form1.Queries.focus();
		return false;
  }
 
  
	document.form1.frmAction.value="Update"; 
	return true;
}
