function trimLeft(str) { return str.replace(/^\s+/, ''); }
function trimRight(str) { return str.replace(/\s+$/, ''); }
function trimBoth(str) { return trimRight(trimLeft(str)); }
function trimSpaces(str) { return str.replace(/\s{2,}/g, ' '); }

function checkcomm() {
	var messagemail = '';
	var messagecomm = '';
	var email =  trimBoth(document.order.email.value);
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;	 
	if (!filter.test(email) && email != '') {messagemail='Введите правильный Email либо оставте поле пустым';} else {messagemail='';}
		if (trimBoth(document.order.comment.value)=="") {messagecomm='Поле с комментарием пустое';} else {messagecomm='';}
	    if (trimBoth(document.order.name.value)=="") {messagename='Поле с именем пустое';} else {messagename='';}
	if (messagemail != '' || messagecomm != '' ||  messagename != '' ) {alert(messagemail+'\n'+messagecomm+'\n'+messagename);return false;}
 }
 
 
function submitComment(id) {
	var commLogin=document.comment.login.value;
	var commMail=document.comment.mail.value;
	var commText=document.comment.text.value;
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;	 
	if (!filter.test(commMail) && commMail != '') {messagemail='Введите правильный Email либо оставте поле пустым';} else {messagemail='';}
	if (trimBoth(commText)=="") {messagecomm='Поле с комментарием пустое';} else {messagecomm='';}
	if (messagemail != '' || messagecomm != '') {alert(messagemail+'\n'+messagecomm);return false;}	
$(document).ready(function(){ // по окончанию загрузки страницы 
$.post('userInput/commentAdd.php',{gid:id,login:commLogin,mail:commMail,text:commText}, function(data) {
if (data!='NULL') {document.getElementById('commList').innerHTML=data; document.comment.text.value = document.comment.login.value = ''; window.location.href="#comm";}
}); // загрузку HTML кода из файла example.html 
});
}

function submitGbook() {
	var commLogin=document.comment.login.value;
	var commMail=document.comment.mail.value;
	var commText=document.comment.text.value;
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;	 
	if (!filter.test(commMail) && commMail != '') {messagemail='Введите правильный Email либо оставте поле пустым';} else {messagemail='';}
	if (trimBoth(commText)=="") {messagecomm='Поле с комментарием пустое';} else {messagecomm='';}
	if (messagemail != '' || messagecomm != '') {alert(messagemail+'\n'+messagecomm);return false;}	
$(document).ready(function(){ // по окончанию загрузки страницы 
$.post('userInput/gbookAdd.php',{login:commLogin,mail:commMail,text:commText}, function(data) {
if (data!='NULL') {document.getElementById('commList').innerHTML=data; document.comment.text.value = document.comment.login.value = ''; window.location.href="#comm";}
}); // загрузку HTML кода из файла example.html 
});
}

function submitMeet() {
	var commLogin=document.comment.login.value;
	var commMail=document.comment.mail.value;
	var commText=document.comment.text.value;
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;	 
	if (!filter.test(commMail) && commMail != '') {messagemail='Введите правильный Email либо оставте поле пустым';} else {messagemail='';}
	if (trimBoth(commText)=="") {messagecomm='Поле с комментарием пустое';} else {messagecomm='';}
	if (messagemail != '' || messagecomm != '') {alert(messagemail+'\n'+messagecomm);return false;}	
$(document).ready(function(){ // по окончанию загрузки страницы 
$.post('userInput/meetAdd.php',{login:commLogin,mail:commMail,text:commText}, function(data) {
if (data!='NULL') {document.getElementById('commList').innerHTML=data; document.comment.text.value = document.comment.login.value = ''; window.location.href="#comm";}
}); // загрузку HTML кода из файла example.html 
});
}

function submitArticle(id) {
	var commLogin=document.comment.login.value;
	var commMail=document.comment.mail.value;
	var commText=document.comment.text.value;
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;	 
	if (!filter.test(commMail) && commMail != '') {messagemail='Введите правильный Email либо оставте поле пустым';} else {messagemail='';}
	if (trimBoth(commText)=="") {messagecomm='Поле с комментарием пустое';} else {messagecomm='';}
	if (messagemail != '' || messagecomm != '') {alert(messagemail+'\n'+messagecomm);return false;}	
$(document).ready(function(){ // по окончанию загрузки страницы 
$.post('/userInput/articleAdd.php',{cid:id,login:commLogin,mail:commMail,text:commText}, function(data) {
if (data!='NULL') {document.getElementById('commList').innerHTML=data; document.comment.text.value = document.comment.login.value = ''; window.location.href="#comm";}
}); // загрузку HTML кода из файла example.html 
});
}

function submitFeedBack() {
$(document).ready(function(){ // по окончанию загрузки страницы 
	var commLogin=document.comment.login.value;
	var commText=document.comment.text.value;
$.post('userInput/feedBackAdd.php',{theme:commLogin,text:commText}, function(data) {
document.getElementById('feedbackmss').innerHTML=data;
document.comment.text.value = document.comment.login.value = '';
}); // загрузку HTML кода из файла example.html 
});
}

function order(id){	
$('#cart').ready(function(){ // по окончанию загрузки страницы 
$.post('/cart_short.php',{new_cart_add:id}, function(data) {
document.getElementById('cart').innerHTML=data;
if (null!=document.getElementsByName(id).item(0)) { document.getElementsByName(id).item(0).innerHTML="<font style='color:#2A1FAA;'>В корзине</font>";}
}); // загрузку HTML кода из файла example.html 
});
}
order();

// rating star
		$("h5").click(function(){
								  alert('fhfgj');
			val1 = $(":radio[name=star1]").filter(":checked").val();			
		});

// prettyPhoto
		$(document).ready(function(){
			$(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme:'dark_square'});
		});
