//--------------------------------// Browsers



var OnLoadBody = function () {

}

opera = (window.opera) ? true : false;
ie = (document.all && !opera) ? true : false;
var _$ = function (id) {
	return document.getElementById(id);
}
var _$$ = function (tag) {
	return document.getElementsByTagName(tag);
}

var version = 6;
var flash = false;
if (navigator.plugins) {
	if(navigator.plugins["Shockwave Flash"]) {
		plugin = navigator.plugins["Shockwave Flash"].description;
		if ( parseInt(plugin.charAt(plugin.indexOf('.') - 2))) {
		    flash = parseInt(plugin.charAt(plugin.indexOf('.') - 2) * 10) >= version;
		}
		else {
		    flash = parseInt(plugin.charAt(plugin.indexOf('.') - 1)) >= version;
		}
	} else {
		if ((navigator.userAgent.indexOf('MSIE') != -1)&&(navigator.userAgent.indexOf('Win') != -1)) {
		  	var vb = '<script language="vbscript">\n'
			+ ' on error resume next\n'
			+ ' flash = IsObject(CreateObject('
			+ ' "ShockwaveFlash.ShockwaveFlash.' + version + '"))\n'
			+ '<' + '/script>';
			document.write(vb);
		}
	}
}

function ShowPhoto(url, width, height) {
	var scroll = (screen.width < 1000) ? "yes" : "no";
	var left = (self.screen.width >> 1) - (width >> 1);
	var top = (self.screen.height >> 1) - (height >> 1);
	var param = 'left='+left+',top='+top+',width='+width+',height='+height+',';
	window.open(url, '_blank', param+'menubar=no,scrollbars=' + scroll + ',status=no');
}

function GetObj(objId) {
	return document.getElementById(objId);
}

function GetAbsoluteTop(obj_id) {
   var obj;
   var result = 0;
   obj = GetObj(obj_id);
   while( obj.tagName != 'BODY' ) {
     result += obj.offsetTop;
     obj = obj.offsetParent;
   }
   return result;
}

function GetAbsoluteLeft(obj_id) {
   var obj;
   var result = 0;
   obj = GetObj(obj_id);
   while( obj.tagName != 'BODY' ) {
     result += obj.offsetLeft;
     obj = obj.offsetParent;
   }
   return result;
}
		
function SetFavorites() {
	window.external.AddFavorite('http://www.template.ru', '"TEMPLATE"')
}
//--------------------------------// Menu Functions
function hide_menu(id) {
	if(id_menu!='' ) {
		timer=window.setTimeout("GetObj('div"+id+"').style.visibility='hidden';id_menu='';",1000);			
	}		
}

var id_menu = 0;
var id_div = 0;
var id_submenu = 0;
var timer = '';

function menu_on (id,is_parent) {
	 var div;
	if(id_menu!=0){
		id_menu = 0;
	}
	if(id_div!=0){
		GetObj("div"+id_div).style.display="none";
		id_div = 0;
	}
	if(id_submenu!=0){
		id_submenu = 0;
	}
	id_menu = id;
	if(is_parent == 1){
		div = GetObj("div"+id);
		div.style.left = GetAbsoluteLeft("menu"+id) + 102 + 'px';
		div.style.top = GetAbsoluteTop("menu"+id) + 'px';
		div.style.display="block";
		id_div=id;
	}
	clearTimeout(timer);
}

function menu_off(id,is_parent) {
	if(is_parent == 1){
		timer = window.setTimeout(" GetObj('div"+id+"').style.display='none'; id_div = 0; id_menu = 0",1000);
	}
}

function submenu_off (id,id_parent) {	
	timer = window.setTimeout("GetObj('div"+id_div+"').style.display='none';id_div=0;id_menu = 0;",1000);
}

function submenu_on (id,id_parent) {
	if(id_menu!=0){
	}
	if(id_div!=0){
		GetObj("div"+id_div).style.display = 'block';
	}
	if(id_submenu!=0){
		id_submenu = 0;
	}
	id_submenu = id;
	clearTimeout(timer);
}

//--------------------------------// Check Mail Form
function CheckMail(form){	
	return (CheckField(form, "email", "Вы не ввели 'e-mail'", 3, 3, 200));
}

//--------------------------------// Print Flash
function PrintFlash(path, wid, heg, pic, lnk, paramz) {
	if(flash){
		document.open();
		document.write ('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="6,0,0,0" width="' + wid + '" height="' + heg + '">');
		document.write ('<param name=movie value="' + path + '">');
		document.write ('<param name="quality" value="high">');
		document.write ('<param name="menu" value="false">');
		document.write ('<param name="FlashVars" value="' + paramz + '">');
		document.write ('<embed src="' + path + '" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' + wid + '" height="' + heg +'" FlashVars="' + paramz + '" menu="false"></embed>');
  		document.write ('</object>');
		document.close();
	} else {
		document.open();
		if(lnk != '') document.write ('<a href="'+ lnk +'">');
		document.write('<img src="'+ pic +'" width="'+ wid +'" height="'+ heg +'">')
		if(lnk != '') document.write ('</a>');
		document.close();
	}
}

//--------------------------------// Get Splitted Link
function GetLink(splited_link,target) {
	newlink = unescape(splited_link).replace(/\|/g,"");
	if(!target || target == 1) {
		newwin = window.open(newlink,"_blank","toolbar=1,scrollbars=1,status=1,location=1,menubar=1,resizable=1,personalbar=1");
		if (newwin) {
			newwin.focus();
		}
	} else {
		window.location = newlink;
	}
}

//--------------------------------// Slide
function Slide(id) {
	if(!(obj = document.getElementById(id)))
		return;

	if(!obj.style.display || obj.style.display == 'none')
		obj.style.display = 'block';
	else
		obj.style.display = 'none';
}

//--------------------------------// Реализация аналога PHP-функции.
function number_format(number, decimals, point, separator) {
	if (!isNaN(number)) {
		point  = point ? point : '.';
		number = String(number).split('.');
		if (separator) {
			var tmp_number = new Array();
			for (var i = number[0].length, j = 0; i > 0; i -= 3) {
				var pos = i > 0 ? i - 3 : i;
				tmp_number[j++] = number[0].substring(i, pos);
			}
			number[0] = tmp_number.reverse().join(separator);
		}
		if (number[1]) {
			number[1] = Math.round(parseFloat(number[1].substr(0, decimals) + '.' + number[1].substr(decimals, number[1].length), 10));
			if (number[1] == 0 || decimals == 0) {
				number.splice(1, 1);
			}
		}
		return number.join(point);
	}
	return(null);
}


function OpenLeftMenu (id) {
	
	if (_$("ullm" + id)  && _$("ullm" + id).style.display == 'none') {
		_$("ullm" + id).style.display = "block";
		var pplid=_$("ullm" + id).parentNode.parentNode;
		pplid.style.display = "block";
	}
	else if (_$("ullm" + id)) {
		_$("ullm" + id).style.display = "none";
	}
}


function CloseAll () {
	var lid = _$$("ul");
	for (i=0; i<lid.length; i++) {
		if (lid[i].id.indexOf ("ullm")!=-1) {
			lid[i].style.display="none";
		}
	}
	Open___ ();
}

function Open___ () {
	if (IDS) {
	    for (i=0; i < IDS.length; i++) {
			OpenLeftMenu (IDS[i]);
	    }
	}
}

var W3CDOM = (document.createElement && document.getElementsByTagName);

function init () {
	if (!W3CDOM) return;
	like_yandex();
	OpenActiveMenu();
}

if (window.attachEvent) {
	window.attachEvent('onload', init);
} else if (window.addEventListener) {
	window.addEventListener('load', init, false);
}

function OpenActiveMenu() {
	return;
}

function like_yandex(){
	frm = document.getElementsByTagName('FORM');
	txt=[],inp=[];
	for (var i = 0; i < frm.length ; i++) {
		if (frm[i].className == 'common') {
		txt[i] = frm[i].getElementsByTagName('LABEL')[0];
		inp[i] = frm[i].getElementsByTagName('INPUT')[0];
		txt[i].number = i;
		inp[i].number = i;
		txt[i].style.position = 'absolute';
		txt[i].style.top = '2px';
		txt[i].style.left = '0';
		txt[i].style.cursor = 'text';
		txt[i].onclick = getLabel;
		inp[i].onblur = backToLabel;
		}
	}
}

function getLabel(){
		this.style.display = 'none';
		nextObject(this).focus();
	}
function backToLabel(){
	if ( !inp[this.number].value ) {
	 txt[this.number].style.display = 'block';
	}
}

