function ShowMail(user, domain1, domain2) {
	var email = user+'&#64;'+domain1+'&#46;'+domain2;
	if (ShowMail.arguments[3]) name = ShowMail.arguments[3];
	else name = email;
	document.writeln('<a href="mailto:'+email+'">'+name+'</a>');
}

function SendLink(link_name) {
	window.open("/send/?link="+link_name, "SendLink", "scrollbars=0, resizable=1, width=370, height=230").focus();
}
function setFields(obj) {
		if(!obj.checked && obj.type=='checkbox' && obj.parentNode.childNodes.length>3) obj.parentNode.childNodes[3].value='';
		else if(obj.type=='radio') {
			coll = document.getElementsByTagName('input');
			for (i=0;i<coll.length;i++) {
				if (coll[i].type=='radio' && coll[i].name.substr(0,5)=='item[' && coll[i].parentNode.childNodes.length>3)
					coll[i].parentNode.childNodes[3].value='';
			}
		}
}

function cbSet(caller) {
	var cb = caller.parentNode.childNodes[0];
	cb.checked = true;
}

function MM_findObj(n, d) { 
  	var p,i,x;  
	if(!d) d=document; 
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
	    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) x=d.all[n]; 
	for (i=0;!x&&i<d.forms.length;i++) 
		x=d.forms[i][n];
  	for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
		x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) 
		x=d.getElementById(n); 
	return x;
}

function wopen(wurl,wname,h,w)
	 {
	  	window.open(wurl,wname,'height='+h+',width='+w+',resizable=0,scrollbars=no,menubar=no,status=no').focus();
	 }
function ipixopen(wurl,wname,h,w)
	 {
	  	window.open("/ipix/"+wurl,wname,'height='+h+',width='+w+',resizable=0,scrollbars=no,menubar=no,status=no').focus();
	 }
function openPhoto(id) {
	if (id) window.open("/popupf/"+id, "popup", "scrollbars=0, resizable=0, width=700, height=450").focus();
//	return false;
}
function openGallery(id,page_id) {
	
	if (id) {
		if (lang=='ru') window.open("/pop/?page_id="+page_id+"&id="+id, "pop", "scrollbars=0, resizable=0, width=700, height=450").focus();
		else window.open("/en/pop/?page_id="+page_id+"&id="+id, "pop", "scrollbars=0, resizable=0, width=700, height=450").focus();
	}
//	return false;
}

function openImage(image, ev) {
    var ev = window.event || ev;
	if (ev == undefined) {
		if (image) window.open("/popup.php?img="+image, "popupimage", "scrollbars=1, resizable=1, width=750, height=500").focus();
		return false;
	}
    var obj = ev.srcElement || ev.target;
    if (obj.tagName == 'IMG') obj = obj.parentNode;
    return hs.expand(obj);
}

function openObject(url) {
	window.open(url,'_blank','toolbar=0,width=600,height=400,scrollbars=1');
}

function preload() {
	b=preload.arguments; 
	preload_images = new Array();
	for(i=0; i<b.length; i++) {
		preload_image = new Image;
		preload_image.src=b[i];
		preload_images[i]=preload_image;
	}
}



function menu_sw(x,name,turn) {
	td2=x.parentElement;
	tr=td2.parentElement;
	td1=tr.children(0);
	img=td1.children(0);
	img.src='/images/smenu/'+name+'_ico'+turn+'.gif';
}

function mout(myId,ext){
		s = document.getElementById('img'+myId).src;
		l = s.length;
		s = s.substr(0,l-5);

		document.getElementById('img'+myId).src = s+'.' + ext;
		
}
function mout_menu(myId){
	document.getElementById('smenu'+myId).style.backgroundColor = '#489442';
}
function mover_menu(myId){
	document.getElementById('smenu'+myId).style.backgroundColor = '#6DA968';
}
//____________________________________________________________________________

function menu_show(id){
	if (document.getElementById('submenu'+id).style.display == 'block') {
		document.getElementById('submenu'+id).style.display = 'none';
		document.getElementById('arr'+id).src = 'images/arr.gif';
	}
	else {
		document.getElementById('submenu'+id).style.display = 'block';
		document.getElementById('arr'+id).src = 'images/arr_act.gif';
	}


}
function checkContestForm()
{
 	var string = '';
	var name = document.getElementById('siteName').value;
	if (name == '') string += "Название\n";
	name = document.getElementById('siteLink').value;
	if (name == '') string += "Веб-адрес (URL)\n";
	name = document.getElementById('siteDeveloper').value;
	if (name == '') string += "Разработчик – организация или частное лицо\n";
	name = document.getElementById('kcaptcha').value;
	if (name == '') string += "Проверочный код\n";
	name = document.getElementById('siteImg').value;
	if (name == '') string += "Изображения сайта\n";
	name = document.getElementById('site_lang').value;
	if (name == '') string += "Языки ресурса\n";
	name = document.getElementById('siteDescr').value;
	if (name == '') string += "Краткое описание ресурса\n";
	name = document.getElementById('site_owner').value;
	if (name == '') string += "Владелец ресурса (Заказчик)\n";
	name = document.getElementById('site_hosting').value;
	if (name == '') string += "Размещение сайта (хостинг)\n";
	name = document.getElementById('date_start').value;
	if (name == '') string += "Дата официального открытия сайта\n";
	name = document.getElementById('contactName').value;
	if (name == '') string += "Имя контактного лица\n";
	name = document.getElementById('sitePhone').value;
	if (name == '') string += "Телефон\n";
	name = document.getElementById('siteEmail').value;
	if (name == '') string += "E-mail\n";
	
	if (string == '') return true;
	else 
	{
		alert("Не все поля заполнены,\nобратите внимание на следующие поля:\n\n" + string);
		return false;
	}
}

function showBanner() {
	if (document.getElementById('popupBanner').style.display = 'block') 
		{
		document.getElementById('popupBanner').style.display = 'none';
	}
	else {
		document.getElementById('popupBanner').style.display = 'none';
	}
}

function getClientWidth(){
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function showCenterBanner(img_width){
    var banner = document.getElementById("popupBanner");
    if (!banner) return;
	client_width = getClientWidth();
	left = (client_width/2) - (img_width/2);	
	banner.style.left = left;
	banner.style.display = 'block';
}

// обратный счетчик дней

function TimeToString (value, str1, str2, str5) { 
   if (!value) return 0
   mod = value % 10
   if ((value%100)>=10 && (value%100)<=19) return str5
   if (mod == 1) return str1
   if (mod >= 2 && mod <= 4) return str2
   return str5
} 

function DaysLeftText (Year, Month, Day, Hour, Minute, Second) {
   tYear   = TimeToString (Year, 'год', 'года', 'лет')
   tMonth  = TimeToString (Month, 'месяц', 'месяца', 'месяцев')
   tDay    = TimeToString (Day, 'день', 'дня', 'дней')
   tHour   = TimeToString (Hour, 'час', 'часа', 'часов')
   tMinute = TimeToString (Minute, 'минута', 'минуты', 'минут')
   tSecond = TimeToString (Second, 'секунда', 'секунды', 'секунд')

   preValues = new Array (Year, Month, Day, Hour, Minute, Second)
   preTexts = new Array (tYear, tMonth, tDay, tHour, tMinute, tSecond)

   numPartsPresent=0
   for (i=5; i>=0; i--) if (preValues[i]!=0) numPartsPresent++

   text=''
   for (i=5; i>=0; i--) {
	  if (preValues[i]!=0) {
		 text='<span class="num">' + preValues[i]+ '</span>&nbsp;&nbsp;'+preTexts[i]+' '+text
		 if (numPartsPresent>1) {
			text='и '+text
			numPartsPresent=0
		 } 
	  }
   }
   return text
}

function countdown_clock(id, year, month, day, hour, minute, format) {
	//html_code  = '<div class="count" id="countdown' + id + '"></div>';
   //html_code += '<div class="count" id="countdown' + id + '"></div>';

   //document.write(html_code);
 
   countdown(id, year, month, day, hour, minute, format);                
}
		 
function countdown(id, year, month, day, hour, minute, format) {
   Today = new Date();
   Todays_Year = Today.getFullYear() - 2000;
   Todays_Month = Today.getMonth();                  
   
   Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), 
						   Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();                                 
   Target_Date = (new Date(year, month - 1, day, hour, minute, 00)).getTime();                  
   
   Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
   
   if(Time_Left < 0)
	  Time_Left = 0;

   switch(format) {
	 case 0:
		  document.all.countdown.innerHTML = Time_Left + ' seconds';
		  break;
	 case 1:
		  days = Math.floor(Time_Left / (60 * 60 * 24));
		  Time_Left %= (60 * 60 * 24);
		  hours = Math.floor(Time_Left / (60 * 60));
		  Time_Left %= (60 * 60);
		  minutes = Math.floor(Time_Left / 60);
		  Time_Left %= 60;
		  seconds = Time_Left;
		  
		  dps = 's'; hps = 's'; mps = 's'; sps = 's';

		  if(days == 1) dps ='';
		  if(hours == 1) hps ='';
		  if(minutes == 1) mps ='';
		  if(seconds == 1) sps ='';

		  elem = document.getElementById("countdown" + id);
		  elem.innerHTML = DaysLeftText (0, 0, days, 0, 0, 0);
		  //elem.innerHTML += hours + ' hour' + hps + ' ';
		  //elem.innerHTML += minutes + ' minute' + mps + ' and ';
		  //elem.innerHTML += seconds + ' second' + sps;
		  break;
	 default: 
		  elem.innerHTML = Time_Left + ' seconds';
   } 
   setTimeout('countdown(' + id + ',' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + format + ');', 1000);
}

var a=0;
var curr_screen_id=0;

function InsertGallery1(name) {
	if (a>6) return;
	a++;
	curr_screen_id++;
	
	var myTable = document.getElementById('tab_'+name);
	var myRow = myTable.insertRow(-1);

	myRow.insertCell(0).innerHTML = "<input type=file name="+name+"[] accept='image/jpeg' class='textInput' size='40'> &nbsp; <a href='javascript:void(0);' onclick=\"DeleteGallery1("+curr_screen_id+",'"+name+"'); return false;\">X</a>";

    myRow.id='scrn'+curr_screen_id;
}

function DeleteGallery1(id,name)
{
	var myTable = document.getElementById('tab_'+name);
	myTable.deleteRow(document.getElementById('scrn'+id).rowIndex);
	a--;
}

function reloadCaptcha1(sess_name,sess_id,id)
{
	document.getElementById(id).src="kcaptcha/index.php?"+sess_name+"="+sess_id+"&"+Math.random();
}