//----------------------------------------------------------------------------
// Назначение:              функция открытия окна
// Возвращаемое значение:	
// Параметры:				sURL - адрес, sName - имя окна, iWidth - ширина, iHeight - высота, iType - тип
function windowOpen( sURL, sName, iWidth, iHeight, iType) {
	if( iType == 0) {
		window.open( sURL, sName, 'toolbar=0,location=0,status=0,menubar=0,scrollbars=1,width=' + String( iWidth) + ',height=' + String( iHeight));
	}

	if( iType == 1) {
		//without scrollbars
		window.open( sURL, sName, 'toolbar=0,location=0,status=0,menubar=0,scrollbars=0,width=' + String( iWidth) + ',height=' + String( iHeight));
	}
	
	if( iType == 2) {
		//For brochure
		window.open( sURL, sName, 'resizable=1,toolbar=1,location=0,status=1,menubar=1,scrollbars=1,width=' + String( iWidth) + ',height=' + String( iHeight));
	}
	if( iType == 3) {
		//For brochure
		window.open( sURL, sName, 'resizable=1,toolbar=0,location=0,status=0,menubar=1,scrollbars=1,width=' + String( iWidth) + ',height=' + String( iHeight));
	}
	if( iType == 4) {
		//For brochure
		window.open( sURL, sName, 'resizable=1,toolbar=1,location=0,status=0,menubar=0,scrollbars=1,width=' + String( iWidth) + ',height=' + String( iHeight));
	}
	if( iType == 5) {
		//For brochure
		window.open( sURL, sName, 'resizable=1,toolbar=0,location=0,status=0,menubar=1,scrollbars=1,width=' + String( iWidth) + ',height=' + String( iHeight));
	}
	return false;
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		menu_03_over = newImage("images/menu_03-over.gif");
		menu_05_menu_03_over = newImage("images/menu_05-menu_03_over.gif");
		menu_07_menu_03_over = newImage("images/menu_07-menu_03_over.gif");
		menu_09_menu_03_over = newImage("images/menu_09-menu_03_over.gif");
		menu_11_menu_03_over = newImage("images/menu_11-menu_03_over.gif");
		menu_13_menu_03_over = newImage("images/menu_13-menu_03_over.gif");
		menu_15_menu_03_over = newImage("images/menu_15-menu_03_over.gif");
		preloadFlag = true;
	}
}
var showflag=false;
var id=null;
var onname="";

function getObject(id){
  if(document.getElementById) // IE >= 5.0 or NN >= 6.0
    return document.getElementById(id); 
  else if(document.all) // IE 4
    return document.all(id);
  else if(document.layers) // NN 4
    return document.layers[id];
  else  
    return false; 
}

function show(name, x, y){
	killtimer();
	if(showflag) hide();
			  
	if(document.all)
	  getObject(name).style.left=x;
	else if(!document.layers)	  
		getObject(name).style.left=x;
	else
	  getObject(name).left=x;
	
	if(!document.layers){	
	  getObject(name).style.top=y;
	  getObject(name).style.visibility='visible';
	} else {
	    getObject(name).top=y;
	    document.layers[name].visibility='show';
	  }
	  
	showflag=true;
	onname=name;
}

function killtimer(){
  if(id!=null){
		clearTimeout(id);
		id=null;
	}
	return true;
}

function hide(){
	if(id!=null) 
	  killtimer();
	
	if(showflag){
		if(document.layers)
		  getObject(onname).visibility='hide';
		else
		  getObject(onname).style.visibility='hidden';
	}
	showflag=false;
	onname="";
}

function resetcool(){
    killtimer();
	id = setTimeout('hide()', 100);
}



 /*
	Текст функции взят отсюда
		http://www.webtoolkit.info/javascript-url-decode-encode.html

		// Функция из нового движка сайта
		//    вставлена сюда, чтобы она была доступна из старого кода
		//     для присоединения к старым частям новых страниц

*/
function urlEncode( string_in ) {

	var string = new String(string_in);
	string = string.replace(/\r\n/g,"\n");
	var utftext = "";

	for (var n = 0; n < string.length; n++) {

		var c = string.charCodeAt(n);

		if (c < 128) {
			utftext += String.fromCharCode(c);
		}
		else if((c > 127) && (c < 2048)) {
			utftext += String.fromCharCode((c >> 6) | 192);
			utftext += String.fromCharCode((c & 63) | 128);
		}
		else {
			utftext += String.fromCharCode((c >> 12) | 224);
			utftext += String.fromCharCode(((c >> 6) & 63) | 128);
			utftext += String.fromCharCode((c & 63) | 128);
		}
	}
	return escape( utftext );
}
