timgoff = new Array();
timgon = new Array();
timghover = new Array();
var TG_site_lang = 'ru';

function hideall(){
	var divs = document.getElementsByTagName("div");
	if(divs)
		for(j=0;j<divs.length;++j)
			if(divs[j].id && divs[j].id.substring(0,7)=='submenu')
				divs[j].style.visibility = 'hidden';
	for(k=0;k<timgoff.length;++k)			
		if(timgoff[k]) document.images['timg' + k].src = timgoff[k].src;	
}

function tshow(i){
	obj = document.getElementById('submenu'+i);
	if(obj) obj.style.visibility = 'visible';
	if(timghover[i]) document.images['timg' + i].src = timghover[i].src;
	else if(timgon[i]) document.images['timg' + i].src = timgon[i].src;

	var divs = document.getElementsByTagName("div");
	if(divs)
		for(j=0;j<divs.length;++j)
			if(divs[j].id && divs[j] != obj && divs[j].id.substring(0,7)=='submenu')
				{divs[j].style.visibility = 'hidden';}
	//if(timgoff[i]) document.images['timg' + i].src = timgoff[i].src;	
}

function thide(i){
	obj = document.getElementById('submenu'+i);
	if(obj) obj.style.visibility = 'hidden';
	if(timgoff[i]) document.images['timg' + i].src = timgoff[i].src;
}

function openwin(url) {
	var OpenWin;
	OpenWin=window.open(url);
	OpenWin.focus();
}

function showsmallwin(url,winname,wid,hei,winclose,winresize) {
	var SmallWin;
	var w = screen.width;
	var h = screen.height;
	var scroll;
	if(wid > 10000 && hei > 10000) {
		wid = wid-10000; hei = hei-10000;
		scroll = 'scrollbars=yes';
	}
	else if (w < wid || h < hei) {
		wid = w-80; hei = h-80;
		scroll = 'scrollbars=yes';
	}
	else if (wid==0 && hei==0) {
		scroll = 'scrollbars=yes';
	}
	else
		scroll = 'scrollbars=no';
//	if(winclose && SmallWin) SmallWin.resizeTo(wid,hei);
	SmallWin=window.open(url,winname,'toolbar=no,directories=no,status=no,'+scroll+','+winresize+',menubar=no,width='+wid+',height='+hei);
	SmallWin.focus();
}

var ImageWin;
function showimage(url,wid,hei) {
	ImageWin=window.open('','imagewin','toolbar=no,directories=no,location=no,status=no,0,resizable=no,copyhistory=no,menubar=no,width='+wid+',height='+hei+',top=50,left=50');
	ImageWin.document.clear();
	//ImageWin.resizeTo(wid+7,hei+45);
	ImageWin.document.write("<html>");
	ImageWin.document.write("<body style='margin-left:0px; margin-right:0px; margin-top:0px; margin-bottom:0px; top:0; left:0; padding:0; border-width:0;'>");
	ImageWin.document.write("<img src='"+url+"' width="+wid+" height="+hei+">");
	ImageWin.document.write("</body>");
	ImageWin.document.write("</html>");
	ImageWin.document.close();
	ImageWin.focus();
}

var ImageWin2;
function showimage2(url,wid,hei,header) {
	ImageWin2=window.open('','imagewin2','toolbar=no,directories=no,location=no,status=no,0,resizable=no,copyhistory=no,menubar=no,width='+wid+',height='+hei+',top=50,left=50');
	ImageWin2.document.clear();
	ImageWin2.resizeTo(wid+7,hei+45);
	ImageWin2.document.write("<html>");
	ImageWin2.document.write("<head><title>"+header+"</title></head>");
	ImageWin2.document.write("<body style='margin-left:0px; margin-right:0px; margin-top:0px; margin-bottom:0px; top:0; left:0; padding:0; border-width:0;'>");
	ImageWin2.document.write("<img src='"+url+"' width="+wid+" height="+hei+">");
	ImageWin2.document.write("</body>");
	ImageWin2.document.write("</html>");
	ImageWin2.document.close();
	ImageWin2.focus();
}

var ImageWin3;
function showimage3(url,wid,hei,header) {
	ImageWin3=window.open('','imagewin3','toolbar=no,directories=no,location=no,status=no,0,resizable=no,copyhistory=no,menubar=no,width='+wid+',height='+hei+',top=50,left=50');
	ImageWin3.document.clear();
	ImageWin3.resizeTo(wid+7,hei+45);
	ImageWin3.document.write("<html>");
	ImageWin3.document.write("<head><title>"+header+"..</title></head>");	
	ImageWin3.document.write("<body style='margin-left:0px; margin-right:0px; margin-top:0px; margin-bottom:0px; top:0; left:0; padding:0; border-width:0;'>");
	ImageWin3.document.write("<a href='javascript:window.close()'><img src='"+url+"' width='"+wid+"' height='"+hei+"' border='0' alt='Закрыть'></a>");
/*	ImageWin3.document.write("<p align='center'><a href='javascript:window.close()'><b>Close</b></a></p>");*/
	ImageWin3.document.write("</body>");
	ImageWin3.document.write("</html>");
	ImageWin3.document.close();
	ImageWin3.focus();
}

function trim(str) {
  return( (""+str).replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') );
}

function formcheck(form) {
	var checktag = new Array('input','textarea');
	var text1 = new Array();
	text1["ru"] = "Заполните обязательное поле ";
	text1["en"] = "Fill required field ";
	for(i=0;i<checktag.length;++i) {
		inp = form.getElementsByTagName(checktag[i]);
		if(inp) {
			for(j=0;j<inp.length;++j) {
				if(inp[j].required==1) {
					if(trim(inp[j].value).length==0) {
						//fieldLabel = inp[j].name;
						//if(fieldLabel) fieldLabel = fieldLabel.replace('p__','');
						fieldLabel = (inp[j].description) ? '"' + inp[j].description + '"' : '';
						alert(text1[TG_site_lang] + fieldLabel);
						inp[j].focus();
						return false;
					}	
				}
			}
		}			
	}	
	for(j=0; j<form.elements.length;++j) {
		ch = form.elements[j];
		if(ch.onsubmitfunc) {
			eval("ret = " + ch.onsubmitfunc + "(ch);");
			if(!ret)
				return false;
		}
	}
	return true;
}



function checkemail(emailform) {
	var email = emailform.value;
	var ret = true;
	var text1 = new Array();
	text1["ru"] = "Неправильный e-mail!";
	text1["en"] = "Incorrect e-mail!";
	if (email.indexOf('@') < 1 ) ret = false;
	if (email.lastIndexOf('.') < email.indexOf('@')) ret = false;
	if (email.length - email.lastIndexOf('.') <= 2) ret = false;
	if (email.indexOf(' ') != -1) ret = false;
	if (ret == false)
		alert(text1[TG_site_lang]);
	return ret;
}

function allDigits(str) {
	return inValidCharSet(str,"0123456789");
}

function inValidCharSet(str,charset) {
	for (i=0; i<str.length; i++)
		if (charset.indexOf(str.substr(i,1))<0)
			return false;
	return true;
}

function CopyContent() {
	a = document.getElementById('Content');
	if(a) window.clipboardData.setData('Text', a.innerText);
}
function CopyPage() {
	document.execCommand("SelectAll");
	document.execCommand("Copy");
	document.body.focus();
}
function PrintPage() {
	document.execCommand("Print");
	document.body.focus();
}
