// JavaScript Document
$(document).ready(function() {	
});

function changePhotoProject(pathPhoto) {
	$("#photoLargeProject").html('<img src="images/projects/'+pathPhoto+'" />');
}

function changeProject(projectId) {
	
	idCurent=$(".projectNameSelected").attr("id");
	$("#"+idCurent).removeClass("projectNameSelected").addClass("projectName");
	$("#projectNo_"+projectId).removeClass("projectName").addClass("projectNameSelected");
	$("#rightContentProject").html('<img src="style/images/loadingAnimation.gif" />');
	$('#rightContentProject').load('ajaxProjectChange.php', { project: projectId}, function (){} );
}

function validCheckout() {
	var count = true;
	var mess_alert = "";
	if ((document.getElementById('txtName').value.length) == 0){
		mess_alert += "Your Name \n";
		count = false;
	}
	if ((document.getElementById('txtEmail').value.length) == 0){
		mess_alert += "E-mail Address \n";
		count = false;
	}
	if ((document.getElementById('txtCompany').value.length) == 0){
		mess_alert += "Company Name \n";
		count = false;
	}
	if ((document.getElementById('txtPhone').value.length) == 0){
		mess_alert += "Phone no.\n";
		count = false;
	}
	if ((document.getElementById('txtDateEvent').value.length) == 0){
		mess_alert += "Date of your event \n";
		count = false;
	}

	if (!count){
		alert("Required Field: \n\n"+mess_alert);
	} else {
		if (!isEmail(document.getElementById('txtEmail').value))
		{
			count = false;
		}
	}
	
	if (count) {
		document.frmCheckout.action='index.php?page=checkout2';
		document.frmCheckout.submit();
	} else {
		return false;
	}
}

function sendOrder() {
	document.frmOrder.action='index.php?page=order';
	document.frmOrder.submit();
}

function isEmail(str){
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Invalid E-mail ID")
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid E-mail ID")
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid E-mail ID")
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid E-mail ID")
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		alert("Invalid E-mail ID")
		return false
	 }

	 return true					
}
//-------------- contact form ---------------------------

function validateContactForm() {
	var isValid = true;
	if (document.sendMailForm.txtName.value == "")
	{
		isValid = false;
	}

	if (isValid) 
	{
		if (!isEmail(document.sendMailForm.txtEmail.value))
		{
			return false;
		}
		else 
		{
			document.sendMailForm.submit();
		}
	}
	else
	{
		alert("Please fill your name and your e-mail address!");
		return false;
	}
}

function registerEmail()
{
	var isValid = true;
	if (document.registerEmailNew.txtRegisterEmail.value == "")
	{
		isValid = false;
	}

	if (isValid) 
	{
		if (!isEmail(document.registerEmailNew.txtRegisterEmail.value))
		{
			return false;
		}
		else 
		{
			document.registerEmailNew.submit();
		}
	}
	else
	{
		alert("Please fill your e-mail address!");
		return false;
	}
}
/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/* Modified to support Opera */
function bookmarksite(title,url) {
	if (window.sidebar) 
	{
		// firefox
		window.sidebar.addPanel(title, url, "");
	}
	else if(window.opera && window.print)
	{ 
		// opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)
	{
		// ie
		window.external.AddFavorite(url, title);
	}
}
