var regexp = new RegExp(" ","g");
var myDir = 'L';
var nbsp = nbsp2 =  "          ";
var fst = true;
var next=0;
var count1 = 0;
var idf = 1;

DOM = (document.getElementById) ? 1 : 0;

NS4 = (document.layers) ? 1 : 0;

Konqueror = (navigator.userAgent.indexOf("Konqueror") > -1) ? 1 : 0;
Konqueror21 = (navigator.userAgent.indexOf("Konqueror 2.1") > -1 || navigator.userAgent.indexOf("Konqueror/2.1") > -1) ? 1 : 0;
Konqueror22 = (navigator.userAgent.indexOf("Konqueror 2.2") > -1 || navigator.userAgent.indexOf("Konqueror/2.2") > -1) ? 1 : 0;
Konqueror2 = Konqueror21 || Konqueror22;

Opera = (navigator.userAgent.indexOf("Opera") > -1) ? 1 : 0;
Opera5 = (navigator.userAgent.indexOf("Opera 5") > -1 || navigator.userAgent.indexOf("Opera/5") > -1) ? 1 : 0;
Opera6 = (navigator.userAgent.indexOf("Opera 6") > -1 || navigator.userAgent.indexOf("Opera/6") > -1) ? 1 : 0;
Opera56 = Opera5 || Opera6;

IE = (document.all) ? 1 : 0;
IE4 = IE && !DOM;

isIE = false;
navVer = navigator.appVersion;
ver = parseFloat(navVer);
IEPos = navVer.indexOf('MSIE');

if (IEPos !=-1) {
	isIE = true;
	ver = parseFloat(navVer.substring(IEPos+5,navVer.indexOf(';',IEPos)));
}

isIE5up = (isIE && ver >= 5);

function CheckObject(ID){
	if ((DOM && !Opera56 && !Konqueror2) || IE4) {
		if (!IE4) {
			objLayer = document.getElementById(ID);
		} else {
			objLayer = document.all(ID);
		}
	} else {
		objLayer = null;
	}

	return objLayer;
}

function addFile(ID,FORM){
	obj = CheckObject(ID);
	obj.innerHTML += "<input type=file name=file" + idf + " id=file" + idf + " class=i2><br><br>";
	idf++;
}



function changeValue(formID,inpID,inpVal){
	obj = CheckObject(inpID);
	obj.value = inpVal;
	obj = CheckObject(formID);
	obj.submit();
}

function ShowProducts(ID) {
	obj = CheckObject(ID);
	if(obj != null){
		if (objLayer.style.display == "none")
			objLayer.style.display = "block";
		else
			objLayer.style.display = "none";		
	}
}

function show(url,wi,he,ran_win) {
	myWindow = window.open(url,ran_win,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,height=" + he + ",width=" + wi);
}

function show2(url,wi,he,ran_win) {
	myWindow=window.open(url,ran_win,"toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,height=" + he + ",width=" + wi);
}

function GetTime() {
	var dt = new Date();
	var def = dt.getTimezoneOffset()/60;
	var gmt = (dt.getHours() + def);
	document.clock.local.value = (IfZero(dt.getHours()) + ":" + IfZero(dt.getMinutes()) + ":" + IfZero(dt.getSeconds()));
	var ending = ":" + IfZero(dt.getMinutes()) + ":" +  IfZero(dt.getSeconds());
	setTimeout("GetTime()", 1000);
}

function IfZero(num) {
	return ((num <= 9) ? ("0" + num) : num);
}

function setBookmark() {
	HomePage = top.location.href;
	window.external.AddFavorite(HomePage,'TOURUA.COM - Туристические сервисы, информация, аналитика');
}

function setNSHomepage(URL) {  // this HAS to be signed if it is to run on the web
	var Text = 'Ваш броузер не поддерживает функцию\n';

	Text += ' автоматического добавления сайта\n';
	Text += 'в \'Избранное\'\n';
	Text += 'Вы можете добавить его вручную.';

	if (confirm(Text)) {
			netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesWrite");
  		navigator.preference('browser.startup.homepage',URL);
	}
}

function preSetHome(lnk){
	HomePage = top.location.href;
	if (document.layers) {
		setNSHomepage(HomePage);
	} else if (isIE5up) {
 		lnk.style.behavior='url(#default#homepage)';
 		lnk.setHomePage(HomePage);
	} else {
		alert('К сожалению, Ваш броузер не поддерживает даную функцию.\n Измените даную настройку вручную');
	}
	return false;
}

function hideLogin(ID) {
	if ((DOM && !Opera56 && !Konqueror2) || IE4) {
		obj = CheckObject(ID);
		if(window.innerWidth){
			obj.style.left = window.innerWidth / 4;
			obj.style.top = window.innerHeight / 4;
		} else {
			obj.style.left = 0;
			obj.style.top = 400;
		}
		
		with(obj.style){
			display = display!='block'?'block':'none';
		}
		
		/*if (obj.style.visibility == "hidden") {
			obj.style.visibility = "visible";
		} else {
			obj.style.visibility = "hidden";
		}*/
	}
}

function displayImage(targetURL, caption, width, height,cat){
	if (width == null || width == "")
		width = 600;
	if (height == null || height == "")
		height = 430;
	if(targetURL.indexOf(".jpg") != -1 || targetURL.indexOf(".gif") != -1
		|| targetURL.indexOf(".jpeg") != -1 || targetURL.indexOf(".png") != -1)
		window.open("http://www.tourua.com/displayImage.php?image="+targetURL+"&title="+caption+"&cat="+cat,"","titlebar=no,toolbar=no,location=no,directories=no,menubar=no,resizable=yes,scrollbars=no,width="+width+",height="+height+",status=no");
}

function displayImage2(targetURL, caption, width, height,cat){
	if (width == null || width == "")
		width = 600;
	if (height == null || height == "")
		height = 430;
	if(targetURL.indexOf(".jpg") != -1 || targetURL.indexOf(".gif") != -1
		|| targetURL.indexOf(".jpeg") != -1 || targetURL.indexOf(".png") != -1)
		window.open("http://www.tourua.com/displayImage.php?image="+targetURL+"&title="+caption+"&cat="+cat,"","titlebar=no,toolbar=no,location=no,directories=no,menubar=no,resizable=yes,scrollbars=yes,width="+width+",height="+height+",status=no");
}

function displaySPO(id,width, height){
	if (width == null || width == "")
		width = 600;
	if (height == null || height == "")
		height = 430;
	window.open("http://www.tourua.com/displaySPO.php?id="+id+"&width="+width+"&height="+height,"titlebar=no,toolbar=no,location=no,directories=no,menubar=no,resizable=yes,scrollbars=no,width="+width+",height="+height+",status=no");
}

function checkEmail(VAL){
    VAL = new String(VAL.value);
    if ((VAL.indexOf('@', 0)<1) || (VAL.indexOf('@', 0)==VAL.length-1)){
	alert("Вы не указали E-mail");
	return 0;
    }
    return 1;
}

function getAbsPos(p) {
	var s = { x:0, y:0 };
	while (p.offsetParent) {
		s.x += p.offsetLeft;
		s.y += p.offsetTop;
		p = p.offsetParent;
	}
	return s;
}

function showF(obj){
    var s = getAbsPos(obj);
    var obj = document.getElementById('login-form');
    
    with(obj.style){
	left = s.x;
	top = s.y - 20;
	visibility = (visibility == 'hidden')?'visible':'hidden';
    }
    return false;
}


