// example registering simple callback function for messages
php.messages.myCallBack = function (msg, params){
    alert ("My messages CallBack func: " + msg);
}

// example registering simple callback function for errors
php.errors.myCallBack = function (msg, params){
    alert ("My errors CallBack func: " + msg);
}

// example registering simple callback function for data
php.data.myCallBack = function (key, value){
    alert ("My data CallBack func: " + key +" = " + value);
}

formAjax = function () {
    $.php(url, $('form#form').formToArray(true));
    return false;
    
    // do an ajax post request
    $.ajax({
       // AJAX-specified URL
       url: url,
       // JSON
       type: "POST",
       data: $('form#form').formToArray(true),
       dataType : "json",
       
       /* Handlers */       
       // Handle the beforeSend event
       beforeSend: function(){
           return php.beforeSend();
       },
       // Handle the success event
       success: function(data, textStatus){   
           return php.success(data, textStatus);
       },
       // Handle the error event
       error: function (xmlEr, typeEr, except) {
		return php.error(xmlEr, typeEr, except);                  
       },
       // Handle the complete event
       complete: function (XMLHttpRequest, textStatus) {              
           return php.complete(XMLHttpRequest, textStatus);
       }
    });
    return false;    
}

function makeRequest(url_add,id,price) {	
	var data = new Object();
	data.action = 'add';
	data.id = id;
	data.price = price;
	$.ajax({
		type: 'POST', url: url_add, dataType: 'html', data: data,
		success: function(data) {							
			$.php(url,{'act':'test0','prod':id})
		}
	});
}
	
function alertContents(http_request) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {			
		} else {
			alert('С запросом возникла проблема.');
		}
	}
}

function prod_refresh(id){
$(document).ready(function(){		
	var getCookies = $.cookie("dragg");
	var cookArr = getCookies.split(",");		
	for (var i=0;i<cookArr.length;i++){
		while (cookArr[i]==id){			
			for (var j=i;j<cookArr.length-1;j++){							
				cookArr[j] = cookArr[j+1];					
			}			
			cookArr.length--;
		}		
	}	

	var prodCount = document.getElementById('qty'+id);
	var minLength = cookArr.length;
	var maxLength = cookArr.length + parseInt(prodCount.value);	
	
	for (var i=minLength;i<maxLength;i++){		
		cookArr[i] = id;	
	};
	
	var data = new Object();
	data.action = 'app';
	data.cc = cookArr.join(",");
	$.ajax({
		type: 'POST', url: '/catalog/shoping_cart', dataType: 'html', data: data,
	});
	
});
location.reload();
if (navigator.appName == 'Opera'){alert('товар обновлён')};
}
function refresh(event,id){
	// alert(event.keyCode);
	if ((event.keyCode > "97") && (event.keyCode < "106") || (event.keyCode > "47") && (event.keyCode < "58") || (event.keyCode > "36") && (event.keyCode < "41") || (event.keyCode == "8") || (event.keyCode == "46")){
		if (((event.keyCode == "8") || (event.keyCode == "46")) && (document.getElementById('qty'+id).value=='')){
			document.getElementById('div'+id).style.visibility = "hidden";			
		} else if ((document.getElementById('qty'+id).value==0) && (document.getElementById('qty'+id).value!='') || (document.getElementById('qty'+id).value[0]==0)){
			document.getElementById('qty'+id).value = 1;			
		} else if (document.getElementById('qty'+id).value!='') {
			document.getElementById('div'+id).style.visibility = "visible";	
		}			
	} else if(event.keyCode==13){			
			prod_refresh(id);									
	} else {
		document.getElementById('qty'+id).value = 1;		
	} 	
};
