function popImage(imageURL,imageTitle){
	//alert(imageURL);
	defaultWidth  = 500;
	defaultHeight = 500;
	//alert(imageURL);
	var optNN='scrollbars=yes,width='+defaultWidth+',height='+defaultHeight+',left=100,top=100,resizable=1';
	var optIE='scrollbars=yes,width='+defaultWidth+',height='+defaultHeight+',left=100,top=100,resizable=1';

	var AutoClose = true;

	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=yes,width='+defaultWidth+',height='+defaultHeight+',left=10,top=10,resizable=1';
		var optIE='scrollbars=yes,width='+defaultWidth+',height='+defaultHeight+',left=10,top=10,resizable=1';

		//if (isNN){imgWin=window.open('about:blank','',optNN);}
		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(100,100);');
			writeln('width=100-(document.body.clientWidth-document.images[0].width);');
			writeln('height=100-(document.body.clientHeight-document.images[0].height);');
			writeln('window.resizeTo(width,height);}');
			writeln('if (isNN){');
			writeln('window.innerWidth=document.images["Image"].width;');
			writeln('window.innerHeight=document.images["Image"].height;}}');
			writeln('function doTitle(){document.title="'+imageTitle+'";}');
			writeln('</sc'+'ript>');
			if (!AutoClose) writeln('</head><body bgcolor=#000000 onload="reSizeToImage();doTitle();self.focus()">')
			else writeln('</head><body bgcolor=#000000 onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
			writeln('<img name="Image" src="'+imageURL+'" style="display:block"></body></html>');
			close();
		}
}



function validateContactForm(){
	
	var root = document.contact;
	var name = root.name.value;
	var email = root.email.value;
	var country = root.country_id.value;
	var purpose = root.purpose.value;
	var comments = root.comments.value;
	
	if (name == ''){
		alert('Please give your name');
		root.name.focus();
		return false;
	}
	
	if (email == ''){
		alert('Please give your email');
		root.email.focus();
		return false;
	}
	
	if (country == ''){
		alert('Please select your country');
		root.country_id.focus();
		return false;
	}
	
	if (purpose == ''){
		alert('Please give your purpose');
		root.purpose.focus();
		return false;
	}
	
	if (comments == ''){
		alert('Please give your comments');
		root.comments.focus();
		return false;
	}
	
	return true;
}

function validateLogin(){
	
	var root = document.sign_in;
	var username = root.username.value;
	var password = root.password.value;
	
	if (username == ''){
		alert('Please give your username');
		root.username.focus();
		return false;
	}
	if (password == ''){
		alert('Please give your password');
		root.password.focus();
		return false;
	}
	
	// password = hex_md5(password);
	// root.password.value = password;
	// root.hashed.value = 'yes';
	return true;
	
}

function validateRegistration(){
	
	var root = document.register;
	
	var firstName = root.first_name.value;
	var lastName = root.last_name.value;
	var age = root.age.value;
	var gender = root.gender.value;
	var countryId = root.country_id.value;
	var email = root.email.value;
	var username = root.username.value;
	var password = root.password.value;
	var confirm_password = root.confirm_password.value;
	
	if (firstName == ''){
		alert('Please give your first name');
		root.first_name.focus();
		return false;
	}
	if (lastName == ''){
		alert('Please give your last name');
		root.last_name.focus();
		return false;
	}
	if (age == ''){
		alert('Please give your age');
		root.age.focus();
		return false;
	}
	if (isNaN(age)){
		alert('Please give a numeric age');
		root.age.focus();
		return false;
	}
	if (gender == ''){
		alert('Please select your gender');
		root.gender.focus();
		return false;
	}
	if (countryId == ''){
		alert('Please select a country');
		root.country_id.focus();
		return false;
	}
	if (email == ''){
		alert('Please give your email');
		root.email.focus();
		return false;
	}
	
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;

	flag=email.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		root.email.focus();
		return false;
	}
	
	if (username == ''){
		alert('Please give your username');
		root.username.focus();
		return false;
	}
	if (password == ''){
		alert('Please give a password');
		root.password.focus();
		return false;
	}
	if (password != confirm_password){
		alert('Your password and its confirmation do not match');
		root.confirm_password.focus();
		return false;
	}
	if (password.length < 6){
		alert('Your password must be at least 6 chracters');
		root.password.focus();
		return false;
	}
	password = hex_md5(password);
	confirm_password = hex_md5(confirm_password);
	root.password.value = password;
	root.confirm_password.value = confirm_password;
	root.hashed.value = 'yes';
	return true;
}

function validateEditProfileForm(){
	var root = document.edit_profile;
	
	var firstName = root.first_name.value;
	var lastName = root.last_name.value;
	var age = root.age.value;
	var gender = root.gender.value;
	var countryId = root.country_id.value;
	var email = root.email.value;
	
	if (firstName == ''){
		alert('Please give your first name');
		root.first_name.focus();
		return false;
	}
	if (lastName == ''){
		alert('Please give your last name');
		root.last_name.focus();
		return false;
	}
	if (age == ''){
		alert('Please give your age');
		root.age.focus();
		return false;
	}
	if (isNaN(age)){
		alert('Please give a valid age');
		root.age.focus();
		return false;
	}
	if (gender == ''){
		alert('Please select your gender');
		root.gender.focus();
		return false;
	}
	if (countryId == ''){
		alert('Please select your country');
		root.country_id.focus();
		return false;
	}
	if (email == ''){
		alert('Please give your email');
		root.email.focus();
		return false;
	}
	return true;
}

function clearEditProfileForm(){
	if (!confirm('Are you sure you want to Clear the form?')) return false;
	var root = document.edit_profile;
	
	root.first_name.value = '';
	root.last_name.value = '';
	root.age.value = '';
	root.gender.value = '';
	root.country_id.value = '';
	root.email.value = '';
	
	return false;
}

function fcPassValidation(){
	
	var root = document.change_password;
	var oldp = root.old.value;
	var newp = root.newp.value;
	var confnew = root.confnew.value;
	
	if (oldp == '' || newp == '' || confnew == ''){
		alert('Please fill up all the fields');
		return false;
	}
	if (!isNaN(newp)){
		alert('Please insert a password that contains characters.');
		root.newp.focus();
		return false;
	}
	
	if (newp != confnew){
		alert('The password and it\'s confirmation do not match');
		root.confnew.focus();
		return false;
	}
	
	oldp = hex_md5(oldp);
	newp = hex_md5(newp);
	confnew = hex_md5(confnew);
	
	root.old.value = oldp;
	root.newp.value = newp;
	root.confnew.value = confnew;
	root.hashed.value = 'yes';
	
	return true;
}
function fcForgotValidation(){
	
	var root = document.forgot_password;
	var username = root.username.value;
	var email = root.email.value;
	
	if (username == '' || email == ''){
		alert('Please fill up all the fields');
		return false;
	}
	return true;
}

function clearFCChangePassword(){
	
	if (confirm('Are you sure you want to clear the form?')){
		var root = document.change_password;
		root.old.value = '';
		root.newp.value = '';
		root.confnew.value = '';
	}
	return false;
}
function clearFCForgotPassword(){
	
	if (confirm('Are you sure you want to clear the form?')){
		var root = document.forgot_password;
		root.username.value = '';
		root.email.value = '';
	}
	return false;
}

function clearRegisterForm(){
	
	if(confirm('Are you sure you want to clear the form?')){
		var root = document.register;
		root.first_name.value = '';
		root.last_name.value = '';
		root.age.value = '';
		root.gender.value = '';
		root.country_id.value = '';
		root.email.value = '';
		root.username.value = '';
		root.password.value = '';
		root.confirm_password.value = '';
	}
	
	return false;
}

function clearContactForm(){
	if(confirm('Are you sure you want to clear the form?')){
		var root = document.contact;
		root.name.value = '';
		root.email.value = '';
		root.country_id.value = '';
		root.purpose.value = '';
		root.comments.value = '';
	}
	
	return false;
}

function submitNewsletter(){
	var root = document.newsletter;
	
	var name = root.name.value;
	var email = root.email.value;
	
	if (name == ''){
		alert('Please give your name');
		root.name.focus();
		return false;
	}
	if (email == ''){
		alert('Please give your email');
		root.email.focus();
		return false;
	}
	return true;
}

function validateVote(){
	var root = document.poll;
	if (root.poll[0].checked == false && root.poll[1].checked == false && root.poll[2].checked == false && root.poll[3].checked == false){
		alert('Please select an option');
		return false;
	}
	return true;
}

function validateToursLogin(){
	
	var root = document.tours_login;
	var username = root.username.value;
	var password = root.password.value;
	
	if (username == ''){
		alert('Please give your username');
		root.username.focus();
		return false;
	}
	if (password == ''){
		alert('Please give your password');
		root.password.focus();
		return false;
	}
	
	password = hex_md5(password);
	root.password.value = password;
	root.hashed.value = 'yes';
	return true;
}
