// check register form

function tForm(form) { 
	if(form.em.value == "") { 
		alert("Please provide an email as it is used as your Username!"); 
		form.em.focus(); 
		return false; 
	} 
	re = /^([a-zA-Z0-9_\-\.]+)@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/; 
	if(!re.test(form.em.value)) { 
		alert("Please check the email address you entered!"); 
		form.em.focus(); 
		return false; 
	} 
	if(form.ps.value != "" && form.ps.value == form.pss.value) { 
		if(form.ps.value.length < 6) { 
			alert("Error: Password must contain at least six characters!");
			form.ps.focus(); 
			return false; 
			}
	} else {	
		alert("Error: Please check that you've entered and confirmed your password!"); 
		form.ps.focus();
		return false;
	}
	return true; 
}

//promo form check
function pForm(form) { 
	if(form.remails.value == "") { 
		alert("Please provide at least one recepeint email!"); 
		form.remails.focus(); 
		return false; 
	} 
	re = /^([a-zA-Z0-9_\-\.]+)@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/;
	var str = form.remails.value;
	var rmails = new Array();
	rmails = str.split(",");
	for (i=0;i<rmails.length;i++)
		{
		if(!re.test(rmails[i])) { 
			alert("Please check the email address you entered!"); 
			form.remails.focus(); 
			return false; 
		}
	}
	if(form.mstext.value == "") { 
		alert("Please provide some text in email!"); 
		form.mstext.focus(); 
		return false; 
	}
	return true; 
}

//sms code form check
function smsForm(form) { 
	if(form.crc.value == "") { 
		form.crc.style.background = 'yellow';
		form.crc.focus(); 
		return false; 
	} 
	return true; 
}

//addinstruct form check
function aForm(form) { 
	if(form.atodo.value == "" || form.atodo.value.length < 5) { 
		form.atodo.style.background = 'yellow';
		form.atodo.focus(); 
		return false; 
	} 
	return true; 
}

//upload form check
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 
//english function
function uForm(form) {
	form.todo.style.background = 'White';
	if(form.todo.value.length == 0) { 
		alert("Please explain what do you want to be done with your photo(s)!");
		form.todo.value = "Explain us here what do you want to be done on this photo.";
		form.todo.style.background = 'Yellow';
		form.todo.focus(); 
		return false; 
	}
	var txt=new RegExp(/^Explain us here what do you want to be done on this photo.$/);
	if (txt.test(trim(form.todo.value))) {
		alert("Please explain us what do you want to be done with your photo(s)!");
		form.todo.value = "Explain us here what do you want to be done on this photo.";
		form.todo.style.background = 'Yellow';
		form.todo.focus();
		return false;
	}
	if (form.pics[0]) {
		if (form.pics[0].value.length == 0) {
		alert("Select a photo first!");
		return false;
		}
	} else {
		if (form.pics.value.length == 0) {
			alert("Select a photo first!");
			return false;
		}
	}
	if (form.subservices) {
		if (!form.sservice_01.checked && !form.sservice_02.checked && !form.sservice_03.checked) {
			alert("Please choose your subservice!");
			form.subservices.style.background = 'Yellow';
			return false;
		}
		form.subservices.style.background = 'White';
	}
	return true;
}

//bg function
function ubForm(form) {
	form.todo.style.background = 'White';
	if(form.todo.value.length == 0) { 
		alert("Моля, обясни какво желаеш да се промени по снимката!");
		form.todo.value = "Обясни ни тук какво желаеш да се промени по тази снимка.";
		form.todo.style.background = 'Yellow';
		form.todo.focus(); 
		return false; 
	}
	var txt=new RegExp(/^Обясни ни тук какво желаеш да се промени по тази снимка.$/);
	if (txt.test(trim(form.todo.value))) {
		alert("Моля, обясни ни какво желаеш да се промени по снимката!");
		form.todo.value = "Обясни ни тук какво желаеш да се промени по тази снимка.";
		form.todo.style.background = 'Yellow';
		form.todo.focus();
		return false;
	}
	if (form.pics[0]) {
		if (form.pics[0].value.length == 0) {
		alert("Моля, избери снимка за обработка!");
		return false;
		}
	} else {
		if (form.pics.value.length == 0) {
			alert("Моля, избери снимка за обработка!");
			return false;
		}
	}
	if (form.subservices) {
		if (!form.sservice_01.checked && !form.sservice_02.checked && !form.sservice_03.checked) {
			alert("Моля, избери подуслуга!");
			form.subservices.style.background = 'Yellow';
			return false;
		}
		form.subservices.style.background = 'White';
	}
	return true;
}

// blog comments check
function ctForm(form) {
	if(form.caname.value == "") { 
		alert("Please provide your name or nickname!");
		form.caname.style.background = 'Yellow';
		form.caname.focus(); 
		return false; 
	}
	if(form.camail.value != "") {
		re = /^([a-zA-Z0-9_\-\.]+)@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/; 
		if(!re.test(form.camail.value)) { 
			alert("Please check the email address you entered!");
			form.camail.style.background = 'Yellow';
			form.camail.focus(); 
			return false; 
		}
	}
	if (form.ctext.value == "") {
		form.ctext.style.background = 'Yellow';
		form.ctext.focus();
		return false;
	}
	return true; 
}

// toggle visibility of layers

function toggleLayer( whichLayer )
{
	var elem, vis;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];
	vis = elem.style;
	// if the style.display value is blank we try to figure it out here
	if( vis.display == '' && elem.offsetWidth != undefined && elem.offsetHeight != undefined )
		vis.display = ( elem.offsetWidth != 0 && elem.offsetHeight != 0 ) ? 'block':'none';
	vis.display = ( vis.display == '' || vis.display == 'block' ) ? 'none':'block';
}

