/*********************************************
* AJAX Module for MZ_CMS Vesion - 0.1
* Part for site 
* MZ_CMS Purpose - RSS-catalogue
*********************************************/
function createAjaxObj()
{
	var httprequest=false;
	
	if (window.XMLHttpRequest)
	{ // if Mozilla, Safari etc
		httprequest=new XMLHttpRequest();
		if (httprequest.overrideMimeType) httprequest.overrideMimeType('text/xml');
	} else if (window.ActiveXObject)
	{ // if IE
		try { httprequest=new ActiveXObject("Msxml2.XMLHTTP"); } 
		catch (e)
		{
			try { httprequest=new ActiveXObject("Microsoft.XMLHTTP"); }
			catch (e){}
		}
	}
	return httprequest
}

var ajaxpack=new Object();
ajaxpack.basedomain="http://"+window.location.hostname; //The root domain executing this ajax script, taking into account the possible "www" prefix.
ajaxpack.ajaxobj=createAjaxObj(); //points to the current ajax object
ajaxpack.filetype="txt"; //The expected file type of the external file ("txt" or "xml")
ajaxpack.addrandomnumber=0; //Set to 1 or 0. When set to 1, a random number will be added to the end of the query string of GET requests to bust file caching of the external file in IE. See docs for more info.
ajaxpack.result_div = "";

//1) ajaxpack.getAjaxRequest(url, parameters, callbackfunc, filetype)
ajaxpack.getAjaxRequest=function(url, parameters, callbackfunc, filetype)
{
	ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
	if (ajaxpack.addrandomnumber==1) //Further defeat caching problem in IE?
	var parameters=parameters+"&ajaxcachebust="+new Date().getTime()
	if (this.ajaxobj)
	{
		this.filetype=filetype
		this.ajaxobj.onreadystatechange=callbackfunc
		this.ajaxobj.open('GET', url+"?"+parameters, true)
		this.ajaxobj.send(null)
	}
}

//2) ajaxpack.postAjaxRequest(url, parameters, callbackfunc, filetype)
ajaxpack.postAjaxRequest=function(url, parameters, callbackfunc, filetype, result_div)
{
	ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
	if (this.ajaxobj)
	{
		document.getElementById(result_div).innerHTML = "<img src='/indicator.gif' width='20' height='20' vspace='5' hspace='5' align='absmiddle'><b>Обращаемся к базе...</b>";
		this.filetype=filetype
		this.result_div=result_div
		this.ajaxobj.onreadystatechange = callbackfunc;
		this.ajaxobj.open('POST', url, true);
		this.ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		this.ajaxobj.setRequestHeader("Content-length", parameters.length);
		this.ajaxobj.setRequestHeader("Connection", "close");
		this.ajaxobj.send(parameters);
	}
}

//Define call back function to process returned data
function processGetPost()
{
	var myajax=ajaxpack.ajaxobj
	var myfiletype=ajaxpack.filetype
	var mydiv=ajaxpack.result_div
	
	if (myajax.readyState == 4)
	{ //if request of file completed
		if (myajax.status==200 || window.location.href.indexOf("http")==-1)
		{ //if request was successful or running script locally
			if (myfiletype=="txt")
			{
				document.getElementById(mydiv).innerHTML = myajax.responseText;
			}
			else
			document.getElementById(mydiv).innerHTML = '<div class="Error">Response error!</div>';
		}
	}
}

function aricleVote(article_id)
{
	var vote=document.all? document.all.vote_button.value : document.getElementById("vote_button").value;
	ajaxpack.postAjaxRequest("/ajax/article_vote.php", "article_id="+article_id+"&vote="+vote, processGetPost, "txt","article_voting")
}
/*
function contentUpdate()
{
	// передаваемые параметры
	var width=document.all? document.all.width.value : document.getElementById("width").value;
	var height=document.all? document.all.height.value : document.getElementById("height").value;
	var quantity=document.all? document.all.quantity.value : document.getElementById("quantity").value;
	// работы
	// installation - монтаж
	// delivery - доставка
	// cleaning - уборка, вывоз мусора
	var installation=document.all.installation.checked;
	var delivery=document.all.delivery.checked;
	var cleaning=document.all.cleaning.checked;

	var outflow=document.all.outflow.value;
	var sill=document.all.sill.value;
	var slope=document.all.slope.value;
	
	var profile=document.all.profile.value;
//	var type=document.all.type.value;
	var type=document.all.real_type.value;

	ajaxpack.postAjaxRequest("calculate_price.php", 'width='+width+'&height='+height+'&quantity='+quantity+'&installation='+installation+'&delivery='+delivery+'&cleaning='+cleaning+'&outflow='+outflow+'&sill='+sill+'&slope='+slope+'&profile='+profile+'&type='+type, processGetPost, "txt","price");
}
*/
function contentUpdate()
{
	// передаваемые параметры
	var width=document.all? document.all.width.value : document.getElementById("width").value;
	var height=document.all? document.all.height.value : document.getElementById("height").value;
	var quantity=document.all? document.all.quantity.value : document.getElementById("quantity").value;
	// работы
	// installation - монтаж
	// delivery - доставка
	// cleaning - уборка, вывоз мусора
	var delivery=document.all.delivery.checked;

	var profile=document.all.profile.value;
//	var type=document.all.type.value;
	var type=document.all.real_type.value;

	ajaxpack.postAjaxRequest("calculate_price.php", 'width='+width+'&height='+height+'&quantity='+quantity+'&delivery='+delivery+'&profile='+profile+'&type='+type, processGetPost, "txt","price");
}

