
if( typeof XMLHttpRequest == "undefined" ){
	
	XMLHttpRequest = function(){
		
	  try{ return new ActiveXObject("Msxml2.XMLHTTP.6.0") }catch(e){}
	  try{ return new ActiveXObject("Msxml2.XMLHTTP.3.0") }catch(e){}
	  try{ return new ActiveXObject("Msxml2.XMLHTTP") }catch(e){}
	  try{ return new ActiveXObject("Microsoft.XMLHTTP") }catch(e){}
	  throw new Error("This browser does not support XMLHttpRequest or XMLHTTP.")
	}
	;
}

if( !xmlhttp && typeof(XMLHttpRequest) != 'undefined' ){
	
  var xmlhttp = new XMLHttpRequest();
}


/*function UpdateSelectOptions(TheSelect, OptionsString){
	
	for( var r = TheSelect.options.length-1; r >= 0; r-- ){
					
		TheSelect.remove(TheSelect.options[r]);
	}
							
	var OptionSArr = OptionsString.split("[&];"); 
	
	for( op=0; op < OptionSArr.length; op++ ){
		
		if( OptionSArr[op] !=""){
			
			var OneOptionStr = OptionSArr[op].split("[^];"); 					
			var OptioniK = document.createElement('option');
			
			OptioniK.text = OneOptionStr[1];
			OptioniK.value = OneOptionStr[0];
			
			if( OptioniK.value>=0 && OptioniK.text != "undefined" ){
				
				try {
				
					TheSelect.add(OptioniK, null);
				}
				catch(ex) {
					
					TheSelect.add(OptioniK);
				}
			}
		}
	}
}*/

function UpdateSelectByParent(GroupId, FormPrefix, ParentType, Lang, AjaxNum, ParentString){		
	
	var SelectsArray = document.getElementsByTagName("select");	
	var ParentValue = document.getElementById(FormPrefix).value;
	
	for( i=0; i<SelectsArray.length; i++ ){				
		
		TheSelect = SelectsArray[i];		
		var TheSelectId = TheSelect.id;		
		var TheSelectType = document.getElementById(TheSelectId + "_Type").value;
		
		if( TheSelectId.search("_ChangeMe" + GroupId + AjaxNum + ParentType) != -1 ){
			
			xmlhttp.open('POST', "ajax.php?action=update_select", false);
			xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');	
			sendString = "parent_id=" + ParentValue + "&type=" + TheSelectType + "&lang=" + Lang + "&parent_type=" + ParentType;	
			
			if( ParentString!="" ){
				
				sendString = sendString + "&parent_string=" + ParentString;
			}
			
			xmlhttp.send(sendString);
			
			if ( xmlhttp.readyState == 4 ){		
				
				var xmlResponse = xmlhttp.responseText;	
				
				UpdateSelectOptions(TheSelect, xmlResponse);		
				
				var ParentString = ";";
				
				var OptionsArr = TheSelect.options;
				
				var detect = 0;
				
				for( var o=0; o<OptionsArr.length; o++ ){
					
					ParentString = ParentString + OptionsArr[o].value + ";";
					if( parseInt(OptionsArr[o].value)>0 ){
						
						detect = 1;
					}
				}
					
				UpdateSelectByParent(GroupId, TheSelect.id, TheSelectType, Lang, AjaxNum, ParentString);							
			}
		}
	}
}


function BannerClick(banner, user, session_id){
	
	xmlhttp.open('POST', "baner_click.php", false);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	
	sendString = "banner=" + banner + "&user=" + user + "&session_id=" + session_id;
	
	xmlhttp.send(sendString);
}


function AddToFavorite(Id, CloneTd, customer){
	
	xmlhttp.open('POST', "add_to_favorite.php", false);
	
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');	
	
	sendString = "id=" + Id + "&clone=" + CloneTd + "&customer=" + customer;		
	
	xmlhttp.send(sendString);
	
	if ( xmlhttp.readyState == 4 ){	
	
		var xmlResponse = xmlhttp.responseText;
	}	
	
	document.getElementById("add_to_favorite_" + Id).innerHTML = '<span style="color:#666666; font-size:10px;"><u>В "портфель"</u></span> |';
}


function UpdatePic(pic_id, img_r){
	
	xmlhttp.open('POST', "update_picture.php", false);
	
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');	
	
	sendString = "Id=" + pic_id + "&img_r=" + img_r;	
	
	xmlhttp.send(sendString);
	
	if ( xmlhttp.readyState == 4 ){	
	
		var xmlResponse = xmlhttp.responseText;
	}	
	
	document.getElementById("popup_pic").innerHTML = xmlResponse;	
}


function AddAddonDates(Id){	
	
	xmlhttp.open('POST', "addon_in_shop.php", false);
	
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');	
	
	var address = document.getElementById('addon_address').value;
	var phone = document.getElementById('addon_phone').value;
	var postal_code = document.getElementById('addon_postal_code').value;
	
	sendString = "id=" + Id + "&address=" + address + "&phone=" + phone + "&postal_code=" + postal_code;
	
	xmlhttp.send(sendString);
	
	if ( xmlhttp.readyState == 4 ){	
	
		var xmlResponse = xmlhttp.responseText;
	}	
}

function UpdateSelect(id)
{
	xmlhttp.open('POST', "update_child.php?id="+id, false);
	
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');	
	
	parent_id = document.getElementById("id_izdanie").value;
	
	sendString = "parent_id=" + parent_id;	
	
	xmlhttp.send(sendString);
	
	if ( xmlhttp.readyState == 4 )
	{
		var xmlResponse = xmlhttp.responseText;
	}	
	
	document.getElementById("razdel").innerHTML = xmlResponse;	
}

function WorldTime() {
	
	document.getElementById("worldcity").disabled = true;
	xmlhttp.open('POST', "world_time.php", false);
	
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');	
	
	id = document.getElementById("worldcity").value;
	
	sendString = "id=" + id;
	
	xmlhttp.send(sendString);
	
	if ( xmlhttp.readyState == 4 ) {
		
		var xmlResponse = xmlhttp.responseText;
	}	
	
	document.getElementById("worldtime").innerHTML = xmlResponse;
	document.getElementById("worldcity").disabled = false;
}

function WorldDateTime() {
	
	var hour = document.getElementById("worldhour").value;
	var d = new Date();
	
	if ( document.getElementById("localhour").value == "" ) {
		
		document.getElementById("localhour").value = d.getHours();
	} else {
		
		if ( document.getElementById("localhour").value != d.getHours() ) {
			
			document.getElementById("serverhour").value = parseInt(document.getElementById("serverhour").value) + 1;
			document.getElementById("localhour").value = d.getHours();
		}
	}
	
	var hours = document.getElementById("serverhour").value;
	
	var newHour = parseInt(hour) + parseInt(hours);
	if ( newHour>23 ) {
		
		newHour = newHour - 24;
	}
	if ( newHour<0 ) {
		
		newHour = newHour + parseInt(24);
	}
	
	newHour = "" + newHour + "";
	if ( newHour.length==1 ) {
		
		newHour = "0" + newHour;
	}
	
	var newMinutes = d.getMinutes();
	newMinutes = "" + newMinutes + "";
	if ( newMinutes.length==1 ) {
		
		newMinutes = "0" + newMinutes;
	}
	
	var newSeconds = d.getSeconds();
	newSeconds = "" + newSeconds + "";
	if ( newSeconds.length==1 ) {
		
		newSeconds = "0" + newSeconds;
	}
	
	document.getElementById("worlddatetime").innerHTML = newHour + ":" + newMinutes + ":" + newSeconds;
	setTimeout("WorldDateTime()", 1000);
}


function HomeFile() {
	
	xmlhttp.open('POST', "home_file.php", false);
	
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');	
	
	sendString = "";
	
	xmlhttp.send(sendString);
	
	if ( xmlhttp.readyState == 4 ) {
		
		var xmlResponse = xmlhttp.responseText;
	}	
	
	document.getElementById("home_file").innerHTML = xmlResponse;
}
