//
// базовые функции
//
function fixPNG(element,sizingMethod) {
	// sizingMethod = [scale|crop]
	if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) {
		var src;
		if (element.tagName=='IMG') {
			if (/\.png$/.test(element.src)) {
				src = element.src;
				element.src = "/common/img/spacer.gif";
			}
		} else {
			src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i)
			if (src) {
				src = src[1];
				element.runtimeStyle.backgroundImage="none";
			}
		}
		if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='"+sizingMethod+"')";
	}
}

Array.prototype.in_array=function(needle) {
	var size=this.length;
	for (var i=0;i<size;i++) if (this[i]==needle) return true;
	return false;
}
Array.prototype.add=function(value) {
	if (!this.in_array(value)) this[this.length]=value;
}

function GetNumBlock(block_id) {
	var block_num;
	block_num=block_id.lastIndexOf("_");
	if (block_num==-1) return "";
	return block_id.substring(block_num+1);
}

function getBrowserName() {
	if (navigator.appName=="Opera") return "opera";
	else if (navigator.appName=="Netscape") return "nn";
	else if (navigator.appName=="Microsoft Internet Explorer") return "ie";
	else return "any";
}

function ap_getObj(name) {
	// сделать ссылку на объект
	if (document.getElementById) return document.getElementById(name);
	else if (document.all) return document.all[name];
	else if (document.layers) return document.layers[name];
}

function sh(e) {
	if ($('#'+e).css("display")!="none") $('#'+e).hide(); else $('#'+e).show();
}

function show_hide_obj(obj_id, view) {
	// скрыть или отобразить obj_id
	obj=ap_getObj(obj_id);
	if (view==1) {
		obj.style.display="block";
	} else {
		obj.style.display="none";
	}
}

function LoadBigImage(src,w,h) {
	var l=screen.width/2-w/2;
	var t=screen.height/2-h/2-30;
	var scroll="no";
	var dw=screen.width-w;
	var dh=screen.height-h;
	if (dw<20 || dh<20) scroll="yes";
	var param="resizable=yes,scrollbars="+scroll+",Toolbar=0,location=0,Directories=0,Status=0,Menubar=0,"+"width="+w+", height="+h+", left="+l+", top="+t;
	windowID=window.open('', target="_blank",param);
	windowID.document.write("<html>\n<head>\n<title></title>\n</head>\n");
	windowID.document.write("<body leftmargin=\"0\" topmargin=\"0\" rightmargin=\"0\" bottomargin=\"0\" marginwidth=\"0\" marginheight=\"0\">\n");
	windowID.document.write("<table cellpadding=\"0\" cellspacing=\"0\" style=\"width:100%;height:100%;text-align:center;vertical-align:middle;\">\n<tr>\n<td>");
	windowID.document.write("<img src=\""+src+"\" width=\""+w+"\" height=\""+h+"\">\n");
	windowID.document.write("</td>\n</tr>\n</table>\n</body>\n</html>\n");
}



// old open image func's
function photo_win(img_path,img_alt) {
	var str, StrBody;
	str = 'resizable=yes,width=100,height=100,screenX=100,screenY=100,left=30,top=30';
	if (document.all){ 
		StrBody = '<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="White" onblur="self.window.close();" onresize="self.window.location.reload();">';
	} else {
		StrBody = '<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="White" onblur="self.window.close();">';
	}		
	var win_op = window.open('','show', str);
	win_op.document.open();
	win_op.document.writeln('<html>');
	win_op.document.writeln('<head>');
	win_op.document.writeln('<title>' + img_alt + '</title>');
	win_op.document.writeln('<script>');
	win_op.document.writeln('function resize_img() {');
	win_op.document.writeln('var width = document.image.width;');
	win_op.document.writeln('var height = document.image.height;');
	win_op.document.writeln('if (!(document.all)){ self.resizeTo(width,height); } else { self.resizeTo((width+12),(height + 31));');
	win_op.document.writeln(' }');
	win_op.document.writeln('}');
	win_op.document.writeln('</script>');	
	win_op.document.writeln('</head>');
	win_op.document.writeln(StrBody);
	win_op.document.writeln('<img name="image" src='+ img_path + ' border=0 alt="'+img_alt+'" onload="resize_img();">');
	win_op.document.writeln('</body>');
	win_op.document.writeln('</html>');		
	win_op.document.close();
}

function photo_win2(img_path,img_alt, w, h) {
	var str, StrBody;
	str = 'resizable=yes,width='+(w+20)+',height='+(h+20)+',screenX=100,screenY=100,left=30,top=30';
	if (document.all){ 
		StrBody = '<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="White" onblur="self.window.close();" onresize="self.window.location.reload();">';
	} else {
		StrBody = '<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="White" onblur="self.window.close();">';
	}
	var win_op = window.open('','show', str);
	win_op.document.open();
	win_op.document.writeln('<html>');
	win_op.document.writeln('<head>');
	win_op.document.writeln('<title>' + img_alt + '</title>');
	win_op.document.writeln('<script>');
	win_op.document.writeln('function resize_img() {');
	win_op.document.writeln('var width = document.image.width;');
	win_op.document.writeln('var height = document.image.height;');
	win_op.document.writeln('if (!(document.all)){ self.resizeTo(width,height); } else { self.resizeTo((width+12),(height + 31));');
	win_op.document.writeln(' }');
	win_op.document.writeln('}');
	win_op.document.writeln('</script>');	
	win_op.document.writeln('</head>');
	win_op.document.writeln(StrBody);
	win_op.document.writeln('<img name="image" src='+ img_path + ' border=0 alt="'+img_alt+'" onload="resize_img();">');
	win_op.document.writeln('</body>');
	win_op.document.writeln('</html>');		
	win_op.document.close();
}

function open_win(x) {
	// открытие картинки в новом окне
	var strBody="<body onLoad='win_load()' style='padding:0px; margin:0px;'>";
	var strWin="width=100, height=100, top=100, left=100, scrollbars=0, resizable=yes";
	var win_op=window.open('', 'show', strWin);
	win_op.document.open();
	win_op.document.write('<html>');
	win_op.document.write('	<head>');
	win_op.document.write('	<title>Untitled</title>');
	win_op.document.write('	<script language="JavaScript">');
	win_op.document.write('	function win_load()');
	win_op.document.write('	{');
	win_op.document.write('	var imgH;');
	win_op.document.write('	var imgW;');
	//win_op.document.write('	var open_pic="'+x+'"; ');
	win_op.document.write('	var agent = navigator.userAgent;');
	win_op.document.write('	browserName = navigator.appName;');
	win_op.document.write('	browserVer = parseInt(navigator.appVersion);');
	win_op.document.write('	var broser;');
	win_op.document.write('	if (window.opera) { broser=3;}');
	win_op.document.write('	else if (browserName == "Microsoft Internet Explorer") { broser=1;}');
	win_op.document.write('	else if ((browserVer >3) &&(browserName == "Netscape")) { broser=2;}');
	win_op.document.write('	imgH=document.getElementById("big_pic").offsetHeight;');
	win_op.document.write('	imgW=document.getElementById("big_pic").offsetWidth;');
	win_op.document.write('	if (broser==1) {	self.resizeTo(imgW+9,imgH+30);}');
	win_op.document.write('	else if (broser==2) {	self.resizeTo(imgW+9,imgH+51);}');
	win_op.document.write('	else if (broser==3) {	self.resizeTo(imgW+10,imgH+44);}');
	//win_op.document.write('	document.getElementById("big_pic").src=open_pic;');
	win_op.document.write('	}');
	win_op.document.write('	</script>');
	win_op.document.write('	</head>');
	win_op.document.write('	<body onLoad="win_load();" style="padding:0px; margin:0px;">');
	win_op.document.write('	<img src="'+x+'" id="big_pic" onClick="window.close();">');
	win_op.document.write('	</body>');
	win_op.document.write('	</html>');
	win_op.document.close();
}
