
//----------------------------------------//
//   © Roman Kislitsin (work@tvvins.ru)   //
//----------------------------------------//

function go(when){ self.parent.location = when; }
function swap(img,ref) { document.images[img].src = ref; }
function send_form(name){ document.forms[name].submit(); }

dom = (document.getElementById)? true : false;
nn4 = (document.layers)? true : false;
ie4 = (!dom && document.all)? true : false;

function showNagr(n){
	if (dom) document.getElementById(n).style.visibility = "visible";
	else if (ie4) document.all[n].style.visibility = "visible";
	else if (nn4) document.layers[n].visibility = "show";
}
function hideNagr(n){
	document.getElementById(n).style.visibility = "hidden";
}

function shl(n){
  path=document.getElementById(n);
  if(path.style.display=='none') path.style.display='block';
  else path.style.display='none';
}

function askBeforeDel(link){
	text="Вы уверены?";
	if(confirm(text)) window.location.href=link;
}

function resetDate(){
	tdate = new Date();
	window.document.getElementById('date_add').value = tdate.getHours()+":"+tdate.getMinutes()+" "+tdate.getDate()+"."+(tdate.getMonth()+1)+"."+tdate.getYear();
	window.document.getElementById('tek_date').value = 'now';
}

function resetAll(){
	resetRegion();
	path = window.document;
	path.getElementById('razd').value = path.getElementById('span_razd').innerHTML = 'Выберите раздел';
	path.getElementById('what').value = path.getElementById('span_what').innerHTML = 'Выберите вид';
	path.getElementById('type').value = path.getElementById('span_type').innerHTML = 'Выберите тип';

	window.document.getElementById('span_alert').innerHTML = '<BR>Для окончательного сброса нажмите кнопку - "Применить фильтр"';
}


function resetRegion(){
	path = window.document;
	path.getElementById('country').value = path.getElementById('span_country').innerHTML = 'Россия';
	path.getElementById('area').value = path.getElementById('span_area').innerHTML = 'Выберите область/город';
	path.getElementById('block_area').style.display = '';
	path.getElementById('city').value = path.getElementById('span_city').innerHTML = 'Выберите город';
	path.getElementById('block_city').style.display = 'none';
	path.getElementById('district').value = path.getElementById('span_district').innerHTML = 'Выберите район';
	path.getElementById('block_district').style.display = 'none';
}

function changecontent(what,text,iarea,icity,idistrict){
	what2="";
	skip=true;
	reset_area=reset_city=reset_district=false;
	path = window.opener.document;
	path.getElementById(what).value = text;
	path.getElementById('span_'+what).innerHTML = text;

	//alert(path.getElementById('district2'));

	if(what=='country'){
		what2='area'; 
		what2_txt='область/город'; 
		what2_i=iarea; 
		reset_area=reset_city=reset_district=true;
		skip=false;
	}
	else if(what=='area'){
		if(icity==1){
			what2='city'; 
			what2_txt='город'; 
			what2_i=icity; 
			reset_city=reset_district=true;
			skip=false;
		}else if(idistrict==1){
			what2='district';
			what2_txt='район'; 
			what2_i=idistrict;
			reset_city=true;
			skip=false;
		}else if(idistrict==0) reset_district=true;
	}
	else if(what=='city'){
		what2='district';
		what2_txt='район'; 
		what2_i=idistrict; 
		skip=false;
	}

// сброс 
	if(reset_area){
		path.getElementById('area').value = 'Выберите область/город'; 
		path.getElementById('block_area').style.display = 'none';
	}
	if(reset_city){
		path.getElementById('city').value = 'Выберите город'; 
		path.getElementById('block_city').style.display = 'none';
	}
	if(reset_district){
		path.getElementById('district').value = 'Выберите район'; 
		path.getElementById('block_district').style.display = 'none';
	}

// установка 
	if(!skip){
		if(what2_i==1){
			path.getElementById(what2).value = path.getElementById('span_'+what2).innerHTML = 'Выберите '+what2_txt;
			path.getElementById('block_'+what2).style.display = '';
		} else{
			path.getElementById(what2).value = 'Выберите '+what2_txt;
			path.getElementById('span_'+what2).innerHTML = '';
			path.getElementById('block_'+what2).style.display = 'none';
		}
	}

	window.close();
}

function showSlect(what,slect){
	width=650; height=500;
	//alert('/drop.php?doit=show'+what+'&what='+slect);
	window.open('/drop.php?doit=show'+what+'&what='+slect,'showr'+what,'width='+width+',height='+height+',scrollbars=1,resizable=1,status=1,toolbar=0,location=0');
}

function showRegion(country,area,city,district){
	width=650; height=500;
	//alert('/drop.php?doit=showregion&country='+country+'&area='+area+'&city='+city+'&district='+district);
	window.open('/drop.php?doit=showregion&country='+country+'&area='+area+'&city='+city+'&district='+district,'showregion','width='+width+',height='+height+',scrollbars=1,resizable=1,status=1,toolbar=0,location=0');
}

function rotImg(id,img1,img2){
	path = document.getElementById(id);
	//alert(path.src.indexOf(img1));
	if(path.src.indexOf(img1)!=-1) path.src = img2; 
	else path.src = img1;		
}

function shl(n){
  path = document.getElementById(n);
  if(path.style.display == 'none') path.style.display = 'block';
  else path.style.display = 'none';
}

function onoff2(n1,n2){
  path1 = document.getElementById(n1);
  path2 = document.getElementById(n2);
  if(path1.checked == true) path2.disabled = false;
  else path2.disabled = true;
}

function shl_sel(n){
  path = document.getElementById(n); 
  if (path.style.display == 'none'){
	  document.getElementById('type').value='Представитель компании';
	  path.style.display = 'block';
  }
  else{
	  document.getElementById('type').value='Частное лицо';
	  path.style.display = 'none';
  }
}

function checkLogin(){
	width=300;
	height=50;
	n = document.getElementById('login').value;
	window.open('/drop.php?doit=checklogin&checklogin='+n,'checklogin','width='+width+',height='+height+',scrollbars=yes,resizable=yes,status=0,toolbar=0');
}

function onoff(n,type){
  path = document.getElementById(n);
  path1 = document.getElementById(n+'1');
  path2 = document.getElementById(n+'2');
  switch(type){
	  case "change":
		  if(path.style.display=='none') path.style.display = 'block';
		  else path.style.display='none';
		  break;
	  case "on1":
		  if(path2.value=='') path.disabled = false;
		  break;
	  case "on2":
		  if(path2.value!='') path1.value=path2.value;
		  path2.value='';
		  break;
	  case "disabled":
		  path.disabled = true;
		  break;
	  case "enable":
		  path.disabled = false;
		  break;
  }
}

function check_form(what){
	document.getElementById('butt').disabled = true;
	alert_string = alert_string2 = "";
	pref = document.forms[what];
	switch(what){
		case "add_user":
			if(document.images['login_pic_check'].src == document.referrer+"i/ico_false.gif") alert_string = "Ваш логин не прошел проверку, выберите другой";
			else if(pref.login.value == "") alert_string = "Вы не заполнили поле - Логин";
			else if(pref.login.value.length < 5) alert_string = "Логин слишком короткий (не менее 5 символов)";
			else if(pref.pass1.value == "" || pref.pass2.value == "") alert_string = "Вы не заполнили поле - Пароль";
			else if(pref.pass1.value.length < 5 || pref.pass2.value.length < 5) alert_string = "Пароль слишком короткий (не менее 5 символов)";
			else if(pref.pass1.value != pref.pass2.value) alert_string = "Пароли не одинаковые";
			else if(pref.question.value == "") alert_string = "Вы не заполнили поле - Контрольный вопрос";
			else if(pref.answer.value == "") alert_string = "Вы не заполнили поле - Ответ на контрольный вопрос";

		case "edit_user":
			if(pref.name.value == "" && alert_string == "") alert_string = "Вы не заполнили поле - Имя";
			else if(pref.fam.value == "" && alert_string == "") alert_string = "Вы не заполнили поле - Фамилия";
			else if(pref.email.value == "" && alert_string == "") alert_string = "Вы не заполнили поле - Email";
			else if(pref.acceptcode.value == "" && alert_string == "") alert_string = "Вы не заполнили поле - Код проверки";
			break;
	}

	document.getElementById('butt').disabled = false;
	if(alert_string != ""){
		alert(alert_string2+alert_string+"      ");
	}
	else{
		pref.submit();
		document.getElementById('butt').disabled = true;
	}
}