var xmlHttp

function showSection(i) {
	for(r=1;r<100;r++)
		{
		if(document.getElementById('cloud'+r)) document.getElementById('cloud'+r).style.display='none';
		}
	document.getElementById('cloud'+i).style.display='block';
}

function setItemHeight(h1,h2,h3) {
 		height1=document.getElementById('item_block'+h1).offsetHeight;
		height2=document.getElementById('item_block'+h2).offsetHeight;
		height3=document.getElementById('item_block'+h3).offsetHeight;
//	alert(height1)
//	alert(height2)
//	alert(height3)
		if(height1>=height2) general=height1;
		if(height2>height1) general=height2;
		if(height3>=general) general=height3;
//		general=general;
		document.getElementById('item_block'+h1).style.height=general+'px';
		document.getElementById('item_block'+h2).style.height=general+'px';
		document.getElementById('item_block'+h3).style.height=general+'px';
//	alert(general)
//	alert(document.getElementById('item_block'+h1).offsetheight)
//	alert(document.getElementById('item_block'+h2).offsetheight)
//	alert(document.getElementById('item_block'+h3).offsetheight)
}

function showPic(pic,id) {
document.getElementById(current_pic).style.borderColor='#ffffff';
if(id=='main')
	{
	addpic='mainpic';
	addpiclink='mainpiclink';
	}
else
	{
	addpic='addpic'+id;
	addpiclink='addpic'+id+'link';
	}
document.getElementById('itempic').src=pic;
document.getElementById(addpic).style.borderColor='#435494';
document.getElementById(addpic).blur();
document.getElementById(addpiclink).blur();
if(id=='main')
	{
	current_pic='mainpic';
	}
else
	{
	current_pic='addpic'+id;
	}
}

function changeQuanty(id,lang) {
 if(lang=='ru')
	{
	if(id==1) wwe=q1;
	else if(id>1&&id<5) wwe=q2;
	else wwe=q3;
	}
 else
	{
	if(id==1) wwe=q4;
	else wwe=q5;
	}
	document.getElementById("order_quant_label").innerHTML=wwe;
}



function setDaysOff(lang) {
	var period=document.getElementById('order_period').value;
	if(period=='24hours')
		{
		document.getElementById('day_off1_container').style.display='inline';
		}
	else
		{
		document.getElementById("day_off1").checked=false;
		document.getElementById('day_off1_container').style.display='none';
		}
	if(period=='2d'||period=='3d'||period=='4d'||period=='5d'||period=='6d'||period=='7d')
		{
		document.getElementById('day_off2_container').style.display='inline';
		if(period=='2d') var inner2='<option value="0">0</option><option value="1">1</option><option value="2">2</option>'
		if(period=='3d') var inner2='<option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option>'
		if(period=='4d') var inner2='<option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option>'
		if(period=='5d') var inner2='<option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option>'
		if(period=='6d') var inner2='<option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option>'
		if(period=='7d') var inner2='<option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option>'
		document.getElementById('day_off2').innerHTML=inner2;
		}
	else
		{
		document.getElementById("day_off2").value=0;
		document.getElementById('day_off2_container').style.display='none';
		}
//	alert(period);

	if(period=="6d")
		{
		document.getElementById('day_off2').value=1;
		}
	else if(period=="7d")
		{
		document.getElementById('day_off2').value=2;
		}
	else   	document.getElementById('day_off2').value=0;

//	alert(document.getElementById('day_off2').selectedIndex)
	setDaysOffQuant(lang);
}

function setDaysOffQuant(lang) {
var days_off_quant=document.getElementById('day_off2').value;
	if(lang=="ru")
		{
		var d1="день";
		var d2="дня";
		var d3="дней";
		}
	else
		{
		var d1="day off";
		var d2="days off";
		var d3="days off";
		}
	if(days_off_quant==1)
		{
		var day=d1;
		}
	else if(days_off_quant>1&&days_off_quant<5)
		{
		var day=d2;
		}
	else {var day=d3;}
        document.getElementById('day_off3').innerHTML=day;
}


function setPeriod(lang) {
var id=document.getElementById("order_item").value;
xmlHttp2=GetXmlHttpObject()
if (xmlHttp2==null){alert ("Browser does not support HTTP Request");return;} 
var url="/set_period.php"
url=url+"?id="+id
url=url+"&lang="+lang
url=url+"&sid="+Math.random()
//alert(url)
xmlHttp2.onreadystatechange=stateSetPeriod
xmlHttp2.open("GET",url,true)
xmlHttp2.send(null)
}

function stateSetPeriod() { 
//alert(xmlHttp.responseText);
if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete")
	{ 
	document.getElementById("order_period").innerHTML=xmlHttp2.responseText;
	document.getElementById('order_period').selectedIndex=0;
	calculate();
	} 
} 


function calculate() {
var iid=document.getElementById("order_item").value;
var quant=document.getElementById("order_quant").value;
var period=document.getElementById("order_period").value;
if(document.getElementById("day_off1").checked)
	{
	var dayoff1=1;
	}
else
	{
	var dayoff1=0;
	}
var dayoff2=document.getElementById("day_off2").value;

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){alert ("Browser does not support HTTP Request");return;} 
var url="/calculate.php"
url=url+"?id="+iid
url=url+"&quant="+quant
url=url+"&period="+period
url=url+"&dayoff1="+dayoff1
url=url+"&dayoff2="+dayoff2
url=url+"&sid="+Math.random()
//alert(url)
xmlHttp.onreadystatechange=stateCalculate
xmlHttp.open("GET",url,true)
xmlHttp.send(null)

}

function stateCalculate() { 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
	document.getElementById("sum").innerHTML=xmlHttp.responseText;
	} 
} 



function setQuanty(id,lang) {
xmlHttp1=GetXmlHttpObject()
if (xmlHttp1==null){alert ("Browser does not support HTTP Request");return;} 
var url="/set_quanty.php"
url=url+"?id="+id
url=url+"&lang="+lang
url=url+"&sid="+Math.random()
//alert(url)
xmlHttp1.onreadystatechange=stateSetQuanty 
xmlHttp1.open("GET",url,true)
xmlHttp1.send(null)
} 



function stateSetQuanty() { 
//alert(xmlHttp.responseText);
if (xmlHttp1.readyState==4 || xmlHttp1.readyState=="complete")
	{ 
	tmp_array1=xmlHttp1.responseText.split('#');
	q1=tmp_array1[0];
	q2=tmp_array1[1];
	q3=tmp_array1[2];
	q4=tmp_array1[3];
	q5=tmp_array1[4];
	lang=tmp_array1[5];
	if(lang=="ru")
		{
		document.getElementById("order_quant_label").innerHTML=q1;
		}
	else
		{
		document.getElementById("order_quant_label").innerHTML=q4;
		}
	document.getElementById("order_quant").value=1;
	} 
} 



function GetXmlHttpObject() { 
var objXMLHttp=null
if (window.XMLHttpRequest)
	{
	objXMLHttp=new XMLHttpRequest()
	}
else if (window.ActiveXObject)
	{
	objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
return objXMLHttp
} 

