function prepareRequest() {

                var http_request = false;

                if (window.XMLHttpRequest) { // Mozilla, Safari,...
                    http_request = new XMLHttpRequest();
                    if (http_request.overrideMimeType) {
                        // See note below about this line
                    }
                } else if (window.ActiveXObject) { // IE
                    try {
                        http_request = new ActiveXObject("Msxml2.XMLHTTP");
                    } catch (e) {
            	try {
            		http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
		if (!http_request) {
			alert('Ошибка при создании XMLHTTP'); return false;
		}
	return http_request;
}

function createJobj(){
	var xmlhttp=false;
	var appendix="";

 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
		appendix = "&utf=1";
	} catch (e) {
		xmlhttp=false;
		alert(e.toString());
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

if (xmlhttp.overrideMimeType) {
     //xmlhttp.overrideMimeType('text/xml; charset=UTF-8');
}

	return xmlhttp;
}

function showSelector(c){
	var xmlhttp = createJobj();
	var fields;
	
	if (xmlhttp){
		xmlhttp.open("GET", "/include/mainSelector.php", true);
		xmlhttp.onreadystatechange=function(){
			if (xmlhttp.readyState==4) {
  				data = xmlhttp.responseText.replace(/myrealgrad/gi,'mrdata');
				window.document.getElementById(c).innerHTML = data;
  			}else{
				window.document.getElementById(c).innerHTML = "<b>Loading ...</b>"
			}
		}
		xmlhttp.send(null)
	}else{
		alert("error");
	}
}

function selectCountry(code,c,sel){
	if(!sel){ var sel = ''; }
	var xmlhttp = createJobj();
	var fields;
	try{
		window.document.getElementById("city").innerHTML = "";
		window.document.getElementById("sector").innerHTML = "";
		window.document.getElementById("subsector").innerHTML = "";
		window.document.getElementById("cmps").innerHTML = "";
	}catch(e){
		//
	}
	if (xmlhttp){
		xmlhttp.open("GET", "/include/menu/citylist.php?country="+code+"&sel="+sel, true);
		xmlhttp.onreadystatechange=function(){
			if (xmlhttp.readyState==4) {
  				data = xmlhttp.responseText.replace(/myrealgrad/gi,'mrdata');
				window.document.getElementById(c).innerHTML = data;
  			}else{
				window.document.getElementById(c).innerHTML = "<b>Loading ...</b>"
			}
		}
		xmlhttp.send(null)
	}else{
		alert("error");
	}
}

function selectCity(code,c,sel){
	if(!sel){ var sel = ''; }
	var xmlhttp = createJobj();
	window.document.getElementById("sector").innerHTML = "";
	window.document.getElementById("subsector").innerHTML = "";
	window.document.getElementById("cmps").innerHTML = "";
	if (xmlhttp){
		if(code.length>0){
			xmlhttp.open("GET", "/include/menu/sectorlist.php?city="+code+"&sel="+sel, true);
			xmlhttp.onreadystatechange=function(){
				if (xmlhttp.readyState==4) {
  					data = xmlhttp.responseText.replace(/myrealgrad/gi,'mrdata');
					window.document.getElementById(c).innerHTML = data;
  				}else{
					window.document.getElementById(c).innerHTML = "<b>Loading ...</b>"
				}
			}
		
		xmlhttp.send(null)
		}
	}else{
		alert("error");
	}
}

function selectSector(code,c,land,sel){
	if(!sel){ var sel = ''; }
	window.document.getElementById("subsector").innerHTML = "";
	window.document.getElementById("cmps").innerHTML = "";
	var xmlhttp = createJobj();
	if (xmlhttp){
		xmlhttp.open("GET", "/include/menu/subsectorlist.php?sector="+code+"&city="+land+"&sel="+sel, true);
		xmlhttp.onreadystatechange=function(){
			if (xmlhttp.readyState==4) {
  				data = xmlhttp.responseText.replace(/myrealgrad/gi,'mrdata');
				window.document.getElementById(c).innerHTML = data;
  			}else{
				window.document.getElementById(c).innerHTML = "<b>Loading ...</b>"
			}
		}
		xmlhttp.send(null)
	}else{
		alert("error");
	}
}

function showCmpList(c,p,city,s,ss){
	if(!s){ var s = ''; }
	if(!ss){ var ss = ''; }
	var xmlhttp = createJobj();
	if (xmlhttp){
		xmlhttp.open("GET", "/cmp_list.php?sector="+s+"&subsector="+ss+"&city="+city+"&p="+p, true);
		xmlhttp.onreadystatechange=function(){
			if (xmlhttp.readyState==4) {
  				data = xmlhttp.responseText.replace(/myrealgrad/gi,'mrdata');
				window.document.getElementById(c).innerHTML = data;
  			}else{
				window.document.getElementById(c).innerHTML = "<b>Loading ...</b>"
			}
		}
		xmlhttp.send(null)
	}else{
		alert("error");
	}
}

function selectFromGroup(n,tar){
	var items = window.document.getElementsByName(n);
	for(i=0;i<items.length;i++){
		if(parseFloat(tar)==(i+1)){ 
			items[i].style.color = '#bd322d'; 
		}else{
			if(tar==items[i]){ 
				items[i].style.color = '#bd322d'; 
			}else{
				items[i].style.color = '';
			}
		}
	}
}

function s1electFromGroup(n,tar){
	var items = window.document.getElementsByName(n);
	for(i=0;i<items.length;i++){
		if(tar==items[i]){ 
			items[i].style.color = '#bd322d'; 
		}else{
			items[i].style.color = '';
		}
	}
}
function clearPanoRegion(){
	try{
		var cl = window.document.getElementById('krpanoContainer');
		//cl.innerHTML = "";
	}catch(e){
		//
	}
}
//http://www.realgrad.ru/include/openPano.php?id=48D4B34B-E265-4955-B778-EB7BD822266B&city=%D2%FE%EC%E5%ED%FC&sector=2000&subsector=&p=1
function open_pan1(id,city,sector,subsector,p){
	alert(id);
	newWin=window.open('http://www.realgrad.ru/include/openPano.php?id='+id+"&city="+city+"&sector="+sector+"&subsector="+subsector+"&p="+p,'pano','toolbar=no,scrollbars=no,copyhistory=no,height=700,width=620');
	//newWin.focus();
}

function open_pan(id,city,sector,subsector,p){
	newWin=window.open('../include/openPano.php?id='+id+"&city="+city+"&sector="+sector+"&subsector="+subsector+"&p="+p,'pano','toolbar=no,scrollbars=no,copyhistory=no,height=700,width=620');
	//newWin.focus();
}
function open_tour(id){
	newWin=window.open('http://www.realgrad.ru/myrealgrad/pano/Tour.aspx?id='+id,'pano','toolbar=no,scrollbars=no,copyhistory=no,height=800,width=600');
	//newWin.focus();
}

function vk_share_url(url){
	var v = window.open('http://vkontakte.ru/share.php?url='+url,'VK',"height=400,width=600,modal=yes,alwaysRaised=yes");
}
function fb_share_url(url){
	var v = window.open('http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.realgrad.ru%2Fjumpintour.php%3Fid%3D'+url,'FB',"height=400,width=600,modal=yes,alwaysRaised=yes");
}

