function addToCart(item_id, count, link, type)
{
	re = /[0-9]/;
	regtest = re.exec(count);
	if(regtest){
		var url = '/exec/cart.php';
	    var pars = 'item_id='+item_id+'&count='+count+'&link='+link+'&type='+type;
	    //alert(pars);
	    var myAjax = new Ajax.Updater({success: 'bag'}, url, {method: 'post', parameters: pars, onFailure: reportError});
	    
	    alert('Товар добавлен в корзину!');
	}
	else{
		alert("Поле количество должно быть целым числом.");
	}
}

function reportError(request)
{
	alert('Sorry. There was an error.');
}

function getHTML()
{
	var url = '/exec/cart.php';
    var pars = '';
    //alert(pars);
    var myAjax = new Ajax.Updater({success: 'bag'}, url, {method: 'post', parameters: pars, onFailure: reportError});
}

function validateForm(){
	var flags1, flags3, flags5, flags6 = false;
	if($("fio").value != ""){
		flags1 = true;
		$("fio").style.border = "1px solid #d4d1cb";
	}
	else{
		$("fio").style.border = "solid 1px red";
	}
	if($("email").value != ""){
		flags3 = checkEmail($("email").value);
		if(flags3 == false){
			$("email").style.border = "solid 1px red";
			alert("Недопустимый адрес");
		}
		else $("email").style.border = "1px solid #d4d1cb";
	}
	else{
		$("email").style.border = "solid 1px red";
		flags6 = true;
	}
	if($("dop").value != ""){
		flags5 = true;
		$("dop").style.border = "1px solid #d4d1cb";
	}
	else{
		$("dop").style.border = "1px solid red";
	}
	
	if(flags1 == true && flags3 == true && flags5 == true){
		$("formfeed").submit;
	}
	if(flags3 == true || flags6 == true) alert("Заполните обязательные поля для отправки заказа.");
	return false;
}

function checkEmail(email){
	em = /[A-Za-z0-9_]@[A-Za-z0-9_.]/;
	regEm = em.exec(email);
	if(regEm){
		return true;
	}
	else{
		return false;
	}
}

function delAttach(id, num){
	//alert(id+" - "+num);
	var url = '/exec/delAttach.php';
    var pars = 'id='+id+"&num="+num;
    //alert(pars);
    var myAjax = new Ajax.Updater({success: 'test1'}, url, {method: 'post', parameters: pars, evalScripts: true, onFailure: reportError});
    
    //location.reload();
	return false;
}

delReload = function(){
	location.reload();
}

function verifyLink(obj){
	//alert(obj.value);
	if($('oldName').value != $('link').value){
		var url = '/exec/checkLink.php';
		var pars = 'link='+encodeURI(obj.value)+'&old='+encodeURI($('oldName').value);
    	//alert(pars);
    	var myAjax = new Ajax.Updater({success: 'err'}, url, {method: 'post', parameters: pars, evalScripts: true, onFailure: reportError});
	}
}

function verifyLinkNews(obj){
	//alert($('oldName').value);
	if(document.getElementById("oldName").value != $('link').value){
		var url = '/exec/checkLinkNews.php';
		var pars = 'link='+encodeURI(obj.value)+'&old='+encodeURI($('oldName').value);
    	var myAjax = new Ajax.Updater({success: 'err'}, url, {method: 'post', parameters: pars, evalScripts: true, onFailure: reportError});
	}
}

function verifyLinkK(obj){
	//alert(obj.value);
	if($('oldName').value != $('link').value){
		var url = '/exec/checkLinkK.php';
		var pars = 'link='+encodeURI(obj.value)+'&old='+encodeURI($('oldName').value);
    	//alert(pars);
    	var myAjax = new Ajax.Updater({success: 'err'}, url, {method: 'post', parameters: pars, evalScripts: true, onFailure: reportError});
	}
}

function verifyLinkG(obj){
	//alert(obj.value);
	if($("oldName").value != $('link').value){
		var url = '/exec/checkLinkG.php';
		var pars = 'link='+encodeURI(obj.value)+'&old='+encodeURI($('oldName').value);
    	//alert(pars);
    	var myAjax = new Ajax.Updater({success: 'err'}, url, {method: 'post', parameters: pars, evalScripts: true, onFailure: reportError});
	}
}

function verifyLinkCatalog(obj){
	if($('oldName').value != $('link').value){
		var url = '/exec/checkLinkCatalog.php';
		var pars = 'link='+encodeURI(obj.value)+'&old='+encodeURI($('oldName').value);
    	var myAjax = new Ajax.Updater({success: 'err'}, url, {method: 'post', parameters: pars, evalScripts: true, onFailure: reportError});
	}
}

yes = function(link) {
	document.getElementById('link').style.border = '2px solid green';
	document.getElementById('link').value = link;
	document.getElementById('submit1').disabled = false;
	document.getElementById('submit2').disabled = false;
	//alert("123");
	//document.getElementById('err').innerHTML = link;
}

no = function(text) {
	document.getElementById('link').style.border = '2px solid red';
	document.getElementById('submit1').disabled = true;
	document.getElementById('submit2').disabled = true;
	alert(text);
}

function changeColOnPage(col){
	//alert(col.value);
	var url = '/exec/colOnPage.php';
    var pars = 'col='+col.value;
    //alert(pars);
    var myAjax = new Ajax.Request(url, {method: 'post', parameters: pars, onFailure: reportError});
    
    location.reload();
}
