function validateEditProfile(){
	
	var root = document.register;
	
	var firstName = root.first_name.value;
	var lastName = root.last_name.value;
	var nationality = root.nationality.value;
	var gender = root.gender.value;
	var address = root.address.value;
	var city = root.city.value;
	var country = root.country.value;
	var phone = root.phone.value;
	var email = root.email.value;

	if (firstName == ''){
		alert('Please specify your first name');
		root.first_name.focus();
		return false;
	}
	
	if (lastName == ''){
		alert('Please specify your last name');
		root.last_name.focus();
		return false;
	}
	
	if (nationality == ''){
		alert('Please select your nationality');
		root.nationality.focus();
		return false;
	}
	
	if (gender == ''){
		alert('Please select your gender');
		root.gender.focus();
		return false;
	}
	
	if (address == ''){
		alert('Please provide your address');
		root.address.focus();
		return false;
	}
	
	if (city == ''){
		alert('Please provide your city');
		root.city.focus();
		return false;
	}
	
	if (country == ''){
		alert('Please select your country');
		root.country.focus();
		return false;
	}
	
	if (phone == ''){
		alert('Please give your phone');
		root.phone.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;
	}
	
	return true;
}

function passValidation(){
	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');
		root.old.focus();
		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.enc.value = '1';
	
	return true;
}

function validateRegistration(){
	
	var root = document.register;
	
	var firstName = root.first_name.value;
	var lastName = root.last_name.value;
	var nationality = root.nationality.value;
	var gender = root.gender.value;
	var country = root.countries.value;
	var address = root.address.value;
	var city = root.city.value;
	var phone = root.phone.value;
	var email = root.email.value;
	var password = root.password.value;
	var confirm_password = root.confirm_password.value;
	var secret_question = root.secret_question.value;
	var secret_answer = root.secret_answer.value;
	
	if (firstName == ''){
		alert('Please specify your first name');
		root.first_name.focus();
		return false;
	}
	
	if (lastName == ''){
		alert('Please specify your last name');
		root.last_name.focus();
		return false;
	}
	
	if (nationality == ''){
		alert('Please select your nationality');
		root.nationality.focus();
		return false;
	}
	
	if (gender == ''){
		alert('Please select your gender');
		root.gender.focus();
		return false;
	}
	
	if (address == ''){
		alert('Please specify your address');
		root.address.focus();
		return false;
	}
	
	if (city == ''){
		alert('Please specify your city');
		root.city.focus();
		return false;
	}
	
	if (country == ''){
		alert('Please select your country');
		root.countries.focus();
		return false;
	}
	
	if (phone == ''){
		alert('Please give your home phone');
		root.phone.focus();
		return false;
	}
	if (email == ''){
		alert('Please give your personal 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 (password == ''){
		alert('Please specify your 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 (secret_question == ''){
		alert('Please give your secret question');
		root.secret_question.focus();
		return false;
	}
	
	if (secret_answer == ''){
		alert('Please give your secret answer');
		root.secret_answer.focus();
		return false;
	}
	password = hex_md5(password);
	confirm_password = hex_md5(confirm_password);
	
	root.hashed.value = '1';
	root.password.value = password;
	root.confirm_password.value = confirm_password;
	return true;
}

function clearRegisterForm(){
	
	var root = document.register;
	
	if (confirm('Are you sure you want to clear the form?')){
		
		root.first_name.value = '';
		root.last_name.value = '';
		root.nationality.value = '';
		root.gender.value = '';
		root.countries.value = '';
		root.phone.value = '';
		root.email.value = '';
		root.password.value = '';
		root.confirm_password.value = '';
		root.secret_question.value = '';
		root.secret_answer.value = '';
		root.address.value = '';
		root.city.value = '';
		root.state_region.value = '';
		root.postal_code.value = '';
	}
	return false;
}

function validateVote(num){
	var root = document.poll_vote;
	
	for(i=0;i<num;i++){
		if (root.poll[i].checked == true) return true;
	}
	alert('Please select an answer');
	return false;
}
function validateSongVote(num){
	var root = document.song_vote;
	
	for(i=0;i<num;i++){
		if (root.poll[i].checked == true) return true;
	}
	alert('Please select an answer');
	return false;
}


function validateVoteSubmit(name){
	var root = eval('document.'+name);
	
	num_rows = root.num_rows.value;
	if(name!='new_release_vote'){
		for(i=0;i<num_rows;i++){
			if (root.c_vote[i].checked == true) return true;
		}
	}else{
		for(i=0;i<num_rows;i++){
			if (root.n_vote[i].checked == true) return true;
		}
	}
	alert('Please select an answer');
	return false;

}


function submitGuestbookForm(){
	
	var root = document.guestbook;
	var name = root.name.value;
	var email = root.email.value;
	var countryId = root.country_id.value;
	var comments = root.comments.value;
	var vcode = root.vcode.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 (countryId == ''){
		alert('Please select your country');
		root.country_id.focus();
		return false;
	}
	if (comments == ''){
		alert('Please give your comments');
		root.comments.focus();
		return false;
	}
	if (vcode == ''){
		alert('Please insert the visual code');
		root.vcode.focus();
		return false;
	}
	root.submit();
	return true;
}

function resetGuestbookForm(){
	
	if (confirm('Are you sure you want to reset the form?')){
	
		var root = document.guestbook;
		root.name.value = '';
		root.email.value = '';
		root.country_id.value = '';
		root.purpose.value = '';
		root.comments.value = '';
	}
	return false;
}


function submitContactForm(){
	
	var root = document.contact;
	var name = root.name.value;
	var email = root.email.value;
	var countryId = 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 (countryId == ''){
		alert('Please select your country');
		root.country_id.focus();
		return false;
	}
	if (purpose == ''){
		alert('Please select your purpose');
		root.purpose.focus();
		return false;
	}
	if (comments == ''){
		alert('Please give your comments');
		root.comments.focus();
		return false;
	}
	root.submit();
	return true;
}

function resetContactForm(){
	
	if (confirm('Are you sure you want to reset 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 submitDedicationForm(){
	
	var root = document.dedication;
	var name = root.name.value;
	var email = root.email.value;
	var countryId = 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 (countryId == ''){
		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;
	}
	root.submit();
	return true;
}

function resetDedicationForm(){
	
	if (confirm('Are you sure you want to reset the form?')){
	
		var root = document.dedication;
		root.name.value = '';
		root.email.value = '';
		root.country_id.value = '';
		root.purpose.value = '';
		root.comments.value = '';
	}
	return false;
}

function submitTellFriendForm(){
	
	var root = document.tell_friend;
	var name = root.name.value;
	var email = root.email.value;
	//var fname = root.fname.value;
	//var femail = root.femail.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;
	}
	
	root.submit();
	return true;
}

function resetTellFriendForm(){
	
	if (confirm('Are you sure you want to reset the form?')){
	
		var root = document.tell_friend;
		root.name.value = '';
		root.email.value = '';
		root.fname_1.value = '';
		root.femail_1.value = '';
		root.fname_2.value = '';
		root.femail_2.value = '';
		root.fname_3.value = '';
		root.femail_3.value = '';
		root.fname_4.value = '';
		root.femail_4.value = '';
		root.comments.value = '';
	}
	return false;
}

/**
 * duplicator.js
 *
 * Allow elements group duplication.
 *
 * Author: Hugo Ortega - hugorteg{drop-this-text}@gmail.com
 *
 * GPL Licence.
 */


/**
 * Add a new element group
 * @param parentId ID of the container parent
 * @param modelId ID of the elements group model to duplicate
 * @param counterId ID of the input hidden as counter
 * @param keepValues Boolean value that specify if the values of controls remain in the new element
 * @param typefocus Input type to focus at the new elements group (text, select, textarea, etc)
 * @return True on successful or false otherwise
 */
function addNewElementsGroup(parentId, modelId, counterId, keepValues, typefocus)
{
	if (!document.getElementById(counterId)) return false;
	var n = ++document.getElementById(counterId).value;
	var thebody = document.getElementById(parentId);
	if (!thebody) return false;
	var therow = document.getElementById(modelId);
	if (!therow) return false;
	var thecopy = duplicateElement(therow, n, keepValues);
	thebody.appendChild(thecopy);
	if (thecopy.getElementsByTagName(typefocus)[0])
		thecopy.getElementsByTagName(typefocus)[0].focus();
	return true;
}

/**
 * Creates a copy of an element and its children.
 * @param e The element to duplicate
 * @param n A numeric sufix to the Id and name attr
 * @param keepVal Flag to keep the value of new controls
 */
function duplicateElement(e, n, keepVal)
{
	var i;
	if (typeof e.tagName != "undefined"){
		var copia = document.createElement(e.tagName);
		// duplicate attributes
		var attr = e.attributes;
		if (attr){
			for (i=0; i<attr.length; i++){
				copia.setAttribute(attr[i].name, attr[i].value);
			}
		}
		if (e.id) copia.id = e.id + n; // id unicos...
		if (e.text) copia.text = e.text; // textos dentro de tags
		if (e.tagName.toLowerCase() == "textarea" && !keepVal){
			copia.text = "";
		}
		if (e.name){
			var thename = e.name.substring(0, e.name.length-1)+n;
			copia.name = thename;
		}
		copia.value = keepVal == true ?  e.value : null;
		// and make a recursive call for each child
		var hijos = e.childNodes;
		if (hijos){
			for (key in hijos){
				if (typeof hijos[key] != "undefined"){
					var hijocopia = duplicateElement(hijos[key], n, keepVal);
					if (hijocopia) copia.appendChild(hijocopia);
				}
			}
		}
		return copia;
	}
	return null;
}

function checkFrame(){
	if (document.parent == null){
		window.location = '/reheader.php?p='+window.self;
	}
	return flase;
}
 