String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
} // -------------------------------------------------------------------------------------------

function truncateForm( form ) {
	for( i = 0 ; i < form.length ; i++ )
	{
	    if( form.elements[i].type == 'text' || form.elements[i].type == 'textarea' )
			form.elements[i].value = form.elements[i].value.trim();
	};
}


function searchFormSubmit() {

 	var form = document.searchform;
	truncateForm(form);	

	if (form.keyword.value=="") {
		alert("LърцшЄх, яюцрыєщёЄр, ёыютю фы  яюшёър!");
		form.keyword.focus();
		return false;
	}

	return true;
	//document.searchform.submit();
}

function openWinnn(x,title,wid,hei) {
  myWin= open("", "_blank", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+wid+",height="+hei);
  myWin.document.open();
  myWin.document.write("<html><head><title>"+title+"</title></head>");
  myWin.document.write("<body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>");
  myWin.document.write("<img src='"+x+"' width='"+wid+"' height='"+hei+"'>");
  myWin.document.write("</body></html>");
  myWin.document.close();  
}

function isNumber( value ) {
    return !isNaN(value);
}


function checkItem(id,status) {
	document.getElementById('count'+id).disabled 	= status;
}

function checkProductsForm() {
	var form = document.productForm;
	truncateForm(form);	
	
	for(var i=0;i<form.length;i++) {
    	if( (form.elements[i].type == 'text') && (!form.elements[i].disabled) && (!isNumber(form.elements[i].value) || (form.elements[i].value==0)) ){
    		alert("Пожалуйста, введите корректные значения количества товаров!");
    		form.elements[i].focus();
    		return false;
    	}
	};
	
	return checkForm('pr[]',"Пожалуйста, укажите товары для добавления!");
}

				
function checkBasketForm() {
	var form = document.basketform;
	truncateForm(form);	
	
	for(var i=0;i<form.length;i++) {
    	if( (form.elements[i].type == 'text') && (!isNumber(form.elements[i].value) || (form.elements[i].value==0)) ){
    		if (document.getElementById('c'+form.elements[i].id.replace("count","")).checked) continue;
    			alert("Пожалуйста, введите корректные значения количества товаров!");
    			form.elements[i].focus();
    			return false;
    	}
	};

	return true;//checkForm('pr[]','¦¦ЎЁv¦•¬кЁ, ¦·ЁЎ°кї к¦ЄЁиv Їvа ¦ЇЁvї¤°а!');;
}

function setCheck(id,checked,bgcolor) {
	document.getElementById('count'+id).disabled=!checked;				
	//document.getElementById('line'+id).style.backgroundColor = (!checked)?bgcolor:"#FFFDE6";
}    			  


function checkForm(elName,msg,flag)
{
	if ( arguments.length < 3 ) flag = true;
	var elm = document.all[elName];
	if(elm.length>0)
    {
        for(var i=0;i<elm.length;i++)
        	if (elm[i].checked) return true;
    }
    else
    {
        if(elm.checked) return true;
    }
    if (flag) alert(msg);
    return false;
} // -------------------------------------------------------------------------------------------


function checkFeedForm() {	
	
	truncateForm(document.sendform);
	
	/*if (document.sendform.name.value=="") {
		alert('Пожалуйста, укажите свое имя!');
		document.sendform.name.focus();
		return false;
	}*/
	
	if (document.sendform.email.value!="" && !isEmail(document.sendform.email.value)) {
		alert('Пожалуйста, укажите свой E-Mail!');
		document.sendform.email.focus();
		return false;
	}
    

	if (document.sendform.message.value=="") {
		alert('Извините, Вы не можете отослать пустое сообщение!');
		document.sendform.message.focus();
		return false;
	}

}

