function changelang(){
	if(lng.value=="arb"){
		window.location = "http://arabic.tarekalihassan.org";
	}
	else {
		window.location = "http://english.tarekalihassan.org";
	}
}


function validateSubform(ofrm){
	if(TrimStr(ofrm.name.value)==''){
		window.alert("you must enter your name");
		ofrm.name.focus();
		return false;
	}
	if(TrimStr(ofrm.email.value)==''){
		window.alert("you must enter your email");
		ofrm.email.focus();
		return false;
	}
	
	if(!checkemail(ofrm.email.value)){
		window.alert("you must enter correct email");
		ofrm.email.focus();
		return false;
	}
	return true;
}


function validateform(ofrm){
	if(TrimStr(ofrm.name.value)==''){
		window.alert("you must enter your name");
		ofrm.name.focus();
		return false;
	}
	if(TrimStr(ofrm.email.value)==''){
		window.alert("you must enter your email");
		ofrm.email.focus();
		return false;
	}
	if(!checkemail(ofrm.email.value)){
		window.alert("you must enter correct email");
		ofrm.email.focus();
		return false;
	}	
	if(TrimStr(ofrm.comment.value)==''){
		window.alert("you must enter your comment or question");
		ofrm.comment.focus();
		return false;
	}		
	return true;
}

function opengallery(sFile){
	window.open("../gallery/viewer.htm?"+sFile,"gallery","status=0,toolbar=0,width=600,height=476,left=10,top=10");
	return false;
}

function loadImg(){
	var strURL = new String();
	strURL = document.location.toString();

	var arrURL = strURL.split("?") //split using blank space as delimiter
	if(arrURL.length>1){
		document.images.img.src = "../gallery/large/" + arrURL[1] + ".jpg";
		//nWidth = document.images.img.width;
		//nHeight = document.images.img.height;
		//window.resizeTo(nWidth+25, nHeight+105)
		//window.alert(nWidth+" "+nHeight);
		
	}
}

function validateGuest(){
	if(TrimStr(frm.name.value)=='') {
		window.alert("Please, enter your name");
		frm.name.focus();
		return false;
	}
	if(TrimStr(frm.email.value)=='') {
		window.alert("Please, enter your email");
		frm.email.focus();
		return false;
	}
	if(TrimStr(frm.comments.value)=='') {
		window.alert("Please, enter your comment");
		frm.comments.focus();
		return false;
	}
return true;
}




function TrimStrLeft(str){
	var strt=new String(str);//strt=strt.substr(i+1,strt.length-(i+1));
	var count=0;
	for(i=0;i<strt.length;i++){
		if(strt.charAt(i)==" " )
			count++;
		else{
			if(count==strt.length)
			strt="";
			else if(count>0)
				strt=strt.substr(count,strt.length-count); 
				if(str=="undefined"||str=="null")
				strt="";	       
				return strt;
	    }
	}
}

function TrimStrRight(str){
	var strt=new String(str);//strt=strt.substr(i+1,strt.length-(i+1));
	var count=0;
	for(i=strt.length-1;i>=0;i--){
		if(strt.charAt(i)==" " )
			count++;
		else{
			if(count==strt.length)
				strt="";
			else if(count>0)
				strt=strt.substr(0,strt.length-count); 
				if(str=="undefined"||str=="null")
					strt="";	       
	       return strt;
	    }
	}
}

function TrimStr(str){
	str=TrimStrRight(str);
	str=TrimStrLeft(str);
	if(str=="undefined"||str=="null"||str==" "||str=="  " )
	   str="";	       
	return str;
}











function TrimStrLeft(str){
	var strt=new String(str);//strt=strt.substr(i+1,strt.length-(i+1));
	var count=0;
	for(i=0;i<strt.length;i++){
		if(strt.charAt(i)==" " )
			count++;
		else{
			if(count==strt.length)
			strt="";
			else if(count>0)
				strt=strt.substr(count,strt.length-count); 
				if(str=="undefined"||str=="null")
				strt="";	       
				return strt;
	    }
	}
}

function TrimStrRight(str){
	var strt=new String(str);//strt=strt.substr(i+1,strt.length-(i+1));
	var count=0;
	for(i=strt.length-1;i>=0;i--){
		if(strt.charAt(i)==" " )
			count++;
		else{
			if(count==strt.length)
				strt="";
			else if(count>0)
				strt=strt.substr(0,strt.length-count); 
				if(str=="undefined"||str=="null")
					strt="";	       
	       return strt;
	    }
	}
}

function TrimStr(str){
	str=TrimStrRight(str);
	str=TrimStrLeft(str);
	if(str=="undefined"||str=="null"||str==" "||str=="  " )
	   str="";	       
	return str;
}

function isEmail(str){
	var filter=/^.+@.+\..{2,3}$/
	return (!filter.test(str))
  }
  
  function checkemail(str){
	var filter=/^.+@.+\..{2,3}$/
	return (filter.test(str))
  }
