//V3.00.A - http://www.openjs.com/scripts/jx/
jx = {
	http:false, //HTTP Object
	format:'text',
	callback:function(data){},
	error:false,
	//Create a xmlHttpRequest object - this is the constructor. 
	getHTTPObject : function() {
		var http = false;
		//Use IE's ActiveX items to load the file.
		if(typeof ActiveXObject != 'undefined') {
			try {http = new ActiveXObject("Msxml2.XMLHTTP");}
			catch (e) {
				try {http = new ActiveXObject("Microsoft.XMLHTTP");}
				catch (E) {http = false;}
			}
		//If ActiveX is not available, use the XMLHttpRequest of Firefox/Mozilla etc. to load the document.
		} else if (XMLHttpRequest) {
			try {http = new XMLHttpRequest();}
			catch (e) {http = false;}
		}
		return http;
	},
	// This function is called from the user's script. 
	//Arguments - 
	//	url	- The url of the serverside script that is to be called. Append all the arguments to 
	//			this url - eg. 'get_data.php?id=5&car=benz'
	//	callback - Function that must be called once the data is ready.
	//	format - The return type for this function. Could be 'xml','json' or 'text'. If it is json, 
	//			the string will be 'eval'ed before returning it. Default:'text'
	load : function (url,callback,format) {
		this.init(); //The XMLHttpRequest object is recreated at every call - to defeat Cache problem in IE
		if(!this.http||!url) return;
		if (this.http.overrideMimeType) this.http.overrideMimeType('text/xml');

		this.callback=callback;
		if(!format) var format = "text";//Default return type is 'text'
		this.format = format.toLowerCase();
		var ths = this;//Closure
		
		if (this.http.overrideMimeType) this.http.overrideMimeType('text/xml');

		//Kill the Cache problem in IE.
		var now = "uid=" + new Date().getTime();
		url += (url.indexOf("?")+1) ? "&" : "?";
		url += now;

		this.http.open("GET", url, true);

		this.http.onreadystatechange = function () {//Call a function when the state changes.
			if(!ths) return;
			var http = ths.http;
			if (http.readyState == 4) {//Ready State will be 4 when the document is loaded.
				if(http.status == 200) {
					var result = "";
					if(http.responseText) result = http.responseText;
					//If the return is in JSON format, eval the result before returning it.
					if(ths.format.charAt(0) == "j") {
						//\n's in JSON string, when evaluated will create errors in IE
						result = result.replace(/[\n\r]/g,"");
						result = eval('('+result+')'); 
					}
	
					//Give the data to the callback function.
					if(ths.callback) ths.callback(result);
				} else { //An error occured
					if(ths.error) ths.error()
				}
			}
		}
		this.http.send(null);
	},
	init : function() {this.http = this.getHTTPObject();}
}


function ShowLarge (sSrc,nWndW,nWndH)
{	
	x = (screen.width - nWndW) / 2;
	y = (screen.height - nWndH) / 2;
	window.open (sSrc, '', 'status=0,menubar=0,toolbar=0,scrollbars=0,resizable=0,width=' + (nWndW+30) + ',height=' + (nWndH+30) + ',left=' + x + ',top=' + y);
}


//BACK FORV

var rpageind = "";
var _title = document.title;
var cur_loc = "";
var firstload = true;
var firstloadEn = false;
var tmout = true;
var anchor_names = {};
var opera = Boolean(window["opera"]);
var MSIE = (navigator.appName.indexOf("Microsoft") != -1) && !opera;
var footru = '<div id="footlinks"><a href="javascript: set_var(\'main\')">главная</a>&nbsp;<a href="javascript: set_var(\'news\')">новости</a>&nbsp;<a href="javascript: set_var(\'history\')">история</a>&nbsp;<a href="javascript: set_var(\'pr\')">продукция</a>&nbsp;<a href="javascript: set_var(\'uslugi\')">услуги</a>&nbsp;<a href="javascript: set_var(\'partners\')">пертнеры</a>&nbsp;<a href="javascript: set_var(\'kont\')">контакты</a>&nbsp;<a href="javascript: set_var(\'present\')">презентация</a></div><div id="footlinksleft"><b>РАЗРАБОТКА САЙТА<br></b>&nbsp;<a href="http://www.belfortex.com"  >BELFORTEX 2008</a>';
var footen = '<div id="footlinks"><a href="javascript: set_var(\'mainEn\')">main</a>&nbsp;&nbsp;<a href="javascript: set_var(\'newsEn\')">news</a>&nbsp;&nbsp;<a href="javascript: set_var(\'historyEn\')">history</a>&nbsp;&nbsp;<a href="javascript: set_var(\'prEn\')">product</a>&nbsp;&nbsp;<a href="javascript: set_var(\'uslugiEn\')">services</a>&nbsp;&nbsp;<a href="javascript: set_var(\'partnersEn\')">partners</a>&nbsp;&nbsp;<a href="javascript: set_var(\'kontEn\')">contact</a>&nbsp;&nbsp;<a href="javascript: set_var(\'presentEn\')">presеntation</a></div><div id="footlinksleft"><b>©2008 All rights reserved<br></b>&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.belfortex.com"  >BELFORTEX </a>';
var langver = "";
var langver1 = "";

// this function work up transitions between pages
function set_var(page) {
   set_flash(page);
   setanchor(page)
   setloc(page);
}

function LoadPage() {
   setTimeout("timer()",500);
}

function receive(from_swf){
   setanchor(from_swf);
   setloc(from_swf);
}

function timer() {
   if (MSIE) {
      document.title = _title;
      var swf = getEl('refresh');
      swf.innerHTML = swf.innerHTML;
      var index = document.title.lastIndexOf("#");
      var hash1 = (index == -1) ? "" : document.title.substr(index);
      var hash = hash1.substr(1);
   } else {
      var hash1 = document.location.hash;
      var hash = hash1.substr(1);
   }
   var lang = "Ru";
   if (hash.lastIndexOf("En") > -1) { 
      lang = "En";
   }
   if (lang != langver1) {
      firstload = true;
      langver1 = lang;
   }
   if (firstload) {
      if (hash.lastIndexOf("En") > -1) {
         set_flash("En");
      } else {
         set_flash('main');
         if (hash.length) {
            setanchor(hash);
//            set_flash(hash);
//            setloc(hash);
         } else {
            setloc('');
         }
      }
      firstload = false;
   } else {
      if (hash != cur_loc) {
         if (hash.lastIndexOf("En") > -1 && firstload) {
            set_flash("En");
            firstload = false;
         } else {
            if (hash.length) {
              set_flash(hash);
              setloc(hash);
           } else {
              set_flash('main');
              setloc('');
           }
         }
      }
   }
   setTimeout("timer()",500);
}

function set_flash(val){
   var langmode = "";
   if (val.lastIndexOf("En") > -1) { 
      langmode = "En";
   }
   if (val.lastIndexOf("archiv") > -1) { 
      val = "archiv"+langmode;
   }
   if (val.lastIndexOf("foto") > -1) { 
      val = "foto"+langmode;
   }
//   alert("set "+val);
   window.document.menu.SetVariable("frame",val);
}

function setanchor(anch){
   if (!anchor_names[anch]) {        
      var dump = getEl('dump');
      dump.innerHTML += '<a name="'+anch+'">'+anch+'</a>';
      anchor_names[anch] = true;
   }
   location.hash = anch;
}

function setloc(val){
   cur_loc = val;
   var lang = "Ru";
   if (val.lastIndexOf("En") > -1) { 
      lang = "En";
   }
   showfoot(lang);
   if (!MSIE) {
      document.title = _title+" - #"+val;
   }
   //alert('current location was set to '+cur_loc);
   if (val.length) {
      showpage(val);
   } else {
      showpage('main');
   }
   var mnpage = '';
   if (val.lastIndexOf("prod") == -1 && val.lastIndexOf("mat") == -1 && val.lastIndexOf("specTeh") == -1) { 
      mnpage = 'r1';
   } else {
      mnpage = 'r2';
   }
   if ((mnpage != rpageind)||(lang != langver1)) {
      setTimeout("showrpage('"+mnpage+"')",500);
      rpageind = mnpage;
   }
}

function getEl(id){
   if(document.layers){
     return document.layers[id];
   }
   if(document.all && document.all.item){
       return document.all[id];
   }
   if(document.getElementById){
       return document.getElementById(id);
   }
}

function showpage(page) {
   var ob = getEl('left');
   jx.load('pages/'+page+'.htm', function(data) {
      ob.innerHTML = data;
   });
}

function showrpage(mnpage) {
   var r_m = getEl('right');
   var langmode = "";
   if(langver1 == "En") {
      langmode = "En";
   }
   jx.load('pages/'+mnpage+langmode+'.htm', function(data) {
      r_m.innerHTML = data;
   });
}

function showfoot(lng) {
   var ftobj = getEl('foot');
   if (langver!=lng) {
      if (lng =="Ru") {
         ftobj.innerHTML = footru;
      } else {
         ftobj.innerHTML = footen;
      }
   }
   lagnver = lng;
   lagnver1 = lng;
}

