function ltrim(source){
  var index = 0;
  while( source.charAt(index) == " " ) 
  	index++;
	return 
		source.substr(index);
}
	
function rtrim(source){
	var index = source.length - 1;
	while( source.charAt(index) == " " ) index--;
	return source.substring(0, index + 1);
}
	
function trim(source){
	return ltrim(rtrim(source));
}

var $ = function (arg) {
	return document.getElementById(arg)		
}  
 

function toggle(pobj){

	if(0==pobj.length)
		alert('Не указан аргумент');
		
  var obj=document.getElementById(pobj);
  
  if(!obj) 
  	alert('не получен объект');
  
  "none"==obj.style.display ? (obj.style.display="block") : (obj.style.display="none");
		
}


function toggle2(arr){

	if(!arr)
		alert('Не указан аргумент')

  for(i=0;i<arr.length;i++) {
  	 var obj=document.getElementById(arr[i]);
  	
     if(!obj) 
  	    alert('не получен объект');	
  	
  	
  	"none"==obj.style.display ? (obj.style.display="") : (obj.style.display="none");	
  }
}


function wOpen(photo_id,W,H) {
	var x = window.screen.availHeight / 2;
	var y = window.screen.availWidth / 4;
	var a=window.open("imgwin.php?id="+photo_id,null,"fullscreen=no,location=0,menubar=no,width="+ W +",height="+ H+",top="+y+",left="+x+",toolbar=no");
}


function help(ths){
	if("photo"==ths.id){
		var answer="Загрузка фото на сайт\r\n\r\nРАЗМЕР: - до 300 килобайт\r\nФОРМАТЫ - jpg, gif, png\r\nДЛИНА-ШИРИНА - до 640 пикселов\r\n\r\nЗагружаемое новое фото замещает старое";
    alert(answer);
  }
}


function prov(strarr,regxarr,errxarr){
	
	var str="";
	
	for(i=0;i<strarr.length;i++) {
	   if(!regxarr[i].test(strarr[i])) {	
		  alert(errxarr[i])
		 	return false; 
		 }	
	}
	return true;
 	
} 



function hochilds(ths){
  var entry=ths.getElementsByTagName("div");	
  var elength = entry.length

  var here=new String();
  here+=window.location
  here=here.split("/")
	here=here[here.length-1]
	
	for(i=0; i<elength; i++) {

		if(entry[i].style.display=="none")
			entry[i].style.display="";
		else 
			entry[i].style.display="none";	
	}

}


function nselector(s){

	var selec = document.getElementById("country"); 
	var txt   = document.getElementById("n_country"); 
  var note  = document.getElementById("t_country"); 

	

  window.status = txt.value.length


  if(s.substr(0,2)=="n_") {
		if(txt.value.length > 0) { 
			selec.style.display="none"; 
			note.style.display="none"; 
		}
		else { txt.style.display="none"; selec.style.display="";	note.style.display="";   }	
  }      
	 else 
	{ 
	 	txt.style.display=""; selec.style.display="none";	note.style.display="none";
  }
    
    

}

