var PATH="http://www.miatravel.ro/"

function checkAll(checkname, exby) 
{
 if (!eval(checkname).length) { checkname.checked = exby.checked? true:false; }
 else
 for (i = 0; i < checkname.length; i++)
  {
  checkname[i].checked = exby.checked? true:false
  }
}

function checkAllArr(form, checkname, exby) 
{
 frm_eval=eval(form);
 frm=document.frm_eval;
 
  for (i = 1; document.getElementById(checkname+i)!=null ; i++)
  {
   x=document.getElementById(checkname+i);
   x.checked = exby.checked? true:false;
  }

}


function ask(str) {
 box=confirm(str);
 if (box==true){
 return true;
 }
 else {
 return false;
}
}


function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function format_number(field, number)
{	
	number=replace(number,".","");
	len=number.length;
	if (len>=4)
	{
		rest=len%3;

		if (rest>0) formated_no=number.substring(0,rest)+".";
		else formated_no="";
		start=rest; 
		
		if (rest==0) rest=1; 
		
		inc=3;

		while (start<=len-rest)
		{
			formated_no=formated_no+number.substring(start,start+inc)+".";
			inc+=3;
			start+=3; 
			//alert(formated_no);
		} 
		formated_no=formated_no.substring(0,formated_no.length-1);
	}
	else formated_no=number;
	
	field.value=formated_no;
}


function formatInt ( ctrl ) {  

  var myInt = ctrl.value.replace ( new RegExp ( "\\.", "g" ), "" );
  var regexp = new RegExp ( "\\B(\\d{3})(\\.|$)" );    

  do { 
   myInt = myInt.replace ( regexp, "." + "$1" ); 
  } 
while ( myInt.search ( regexp ) >= 0 )    
ctrl.value = myInt; 
}


function getCookie(NameOfCookie){
    if (document.cookie.length > 0) {              
    begin = document.cookie.indexOf(NameOfCookie+"=");       
    if (begin != -1) {           
      begin += NameOfCookie.length+1;       
      end = document.cookie.indexOf(";", begin);
      if (end == -1) end = document.cookie.length;
        return unescape(document.cookie.substring(begin, end));
    } 
  }
  return null;
}

function setCookie(NameOfCookie, value, expiredays) {
var ExpireDate = new Date();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));

  document.cookie = NameOfCookie + "=" + escape(value) + 
  ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}


function disp(el)
	{
		x=document.getElementById(el);
		y=document.getElementById("en_"+el);
		if (x.style.display=="none")
		{
			x.style.display="";
			y.style.display="";
			document.images[el+"_img0"].src=PATH+"images/up.gif";
			document.images[el+"_img0"].title="Inchide";
			document.images["en_"+el+"_img0"].src=PATH+"images/up.gif";
			document.images["en_"+el+"_img0"].title="Inchide";
			//setCookie(el,'1',365);
		}
		else
		{
			
			x.style.display="none";
			y.style.display="none";
			document.images[el+"_img0"].src=PATH+"images/down.gif";
			document.images[el+"_img0"].title="Deschide";
			document.images["en_"+el+"_img0"].src=PATH+"images/down.gif";
			document.images["en_"+el+"_img0"].title="Deschide";
			//setCookie(el,'0',365);
		}
	}
	
	
function loadEval(el)
{
		x=document.getElementById(el);
		y=document.getElementById("en_"+el);
		
		
		if (getCookie(el)=='0')
		{
			x.style.display="none";
			y.style.display="none";
			document.images[el+"_img0"].src=PATH+"images/down.gif";
			document.images["en_"+el+"_img0"].src=PATH+"images/down.gif";
		}
		else
		{
			x.style.display="";
			y.style.display="";
			document.images[el+"_img0"].src=PATH+"images/up.gif";
			document.images["en_"+el+"_img0"].src=PATH+"images/up.gif";
		}
}


function loadEval_(el)
{
		x=document.getElementById(el);
		x.style.display="none";
		document.images[el+"_img0"].src=PATH+"images/down.gif";
		document.images[el+"_img0"].title="Deschide";
}

function addChkNode()
{
	var args = addChkNode.arguments;
	frm=document.getElementById('form-box');
	
	obj=document.getElementsByTagName('fieldset');
	block_content=obj[0];
	
	var container = document.createElement("div");
	container.id='node-list';
	
	for (i=0;i<args.length-1;i+=2)
	{
		id=args[i];
		val=args[i+1];
	
		var newdiv = document.createElement("div");
		newdiv.setAttribute("className","form-item");
		newdiv.id='node-'+id;
		
			var newlabel = document.createElement("label");
			newlabel.setAttribute("className","option");
			

			
				var newchk = document.createElement('input');
				newchk.type = 'checkbox';
				newchk.name = 'node[' + id + ']';
				newchk.id = 'edit-node-' + id;
				newchk.defaultChecked = true;
				newchk.value = id;
				
			newlabel.appendChild(newchk);
			
			var txt=document.createTextNode(val);
			newlabel.appendChild(txt);
			
		//alert(newchk.value);	
		
		newdiv.appendChild(newlabel);
		
		var notsub=document.createElement('span');
		notsub.setAttribute("style","font-size:11px; color:#FF0000; font-style:italic;");
		var txt2=document.createTextNode(" (not submitted yet) ");
		notsub.appendChild(txt2);
		
		newdiv.appendChild(notsub);
		
		var del=document.createElement('a');
		del.href = 'javascript:deleteOpenerNode('+id+')';
		var txt3=document.createTextNode("Delete");
		del.appendChild(txt3);
			
		newdiv.appendChild(del);
		
		container.appendChild(newdiv);
		
	}

	frm.appendChild(container);
}

function deleteOpenerNode(id)
{
	box=confirm("Are you sure ?");
	if (box==false)
		return false;
	else
	{
		obj_div=document.getElementById('node-' + id);
		obj_chk=document.getElementById('edit-node-' + id);	
		obj_row=document.getElementById('row-node-' + id);;
	
		obj_chk.checked=false;
		obj_div.style.display='none';
		obj_row.style.display='none';
	}
}

function popupWin(url,name,properties) 
{ 
	var videoWindow="";
	videoWindow = window.open(url,name,properties);
	videoWindow.focus();
}