function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
function cm_bwcheck(){
	//In theory we should use object detection, but this script needs work-arounds for almost every browser...
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent.toLowerCase()
	this.dom=document.getElementById?1:0
	this.ns4=(!this.dom && document.layers)?1:0;
	this.op=window.opera
	this.moz=(this.agent.indexOf("gecko")>-1 || window.sidebar)
	this.ie=this.agent.indexOf("msie")>-1 && !this.op
	if(this.op){
		this.op5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1)
		this.op6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1)
		this.op7=this.dom&&!this.op5&&!this.op6 //So all higher opera versions will use it
	}else if(this.moz) this.ns6 = 1
	else if(this.ie){
		this.ie4 = !this.dom && document.all
		this.ie5 = (this.agent.indexOf("msie 5")>-1)
		this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1)
		this.ie6 = this.dom && !this.ie4 && !this.ie5 && ! this.ie55
	}
	this.mac=(this.agent.indexOf("mac")>-1)
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6 || this.op7)
	this.usedom= this.ns6||this.op7//Use dom creation
	this.reuse = this.ie||this.op7||this.usedom //Reuse layers
	this.px=this.dom&&!this.op5?"px":""
	return this
}
var bw=new cm_bwcheck()


/*************************************************************************************************************************/
function trim(inputString) {
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") {
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") {
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) {
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
   }
   return retValue;
}
function isValidEmail(sn)
{
	s = trim(sn.value)+'';
	if(s && (/^\w+([\.\-]?\w+)*@\w+([\.\-]?\w+)*(\.\w{2,3})+$/.test(s)))
	{
	  	return true;
	}
	else
	{
		return false;
	}
}

var correct = true;
function CheckForm()
{
	correct = true ;
  var err_msg = "";

  if (!isValidEmail(document.newsletter.address))
  {
  	err_msg = err_msg + "Email invalid! \n";
    correct = false;
	 alert(err_msg);
  }

  return correct;
}

//layer handling
var myL=new String();
var myS=new String();

function verificaBrw()
{
	if(bw.ns6)
	{
		myL = ".getelementbyid";
		myS = ".css";
	}else
	if(navigator.appVersion.indexOf("MSIE") != -1)
  {
  	myL=".all";
    myS=".style";
  } else
  if(navigator.appVersion.indexOf("Nav") != -1)
  {
  	myL=".layer";
    myS="";
  }
}

verificaBrw();

function getRefToDiv(divID) {
	//customised to suit this particular page - DON'T COPY THIS UNLESS YOU KNOW WHAT YOU ARE DOING!!
	if( document.layers ) { return document.layers[divID+'C'].document.layers[divID]; }
	if( document.getElementById ) { return document.getElementById(divID); }
	if( document.all ) { return document.all[divID]; }
	if( document[divID+'C'] ) { return document[divID+'C'].document[divID]; }
	return false;
}

function showDiv(divID_as_a_string) {
	var myReference = getRefToDiv(divID_as_a_string);
	if( !myReference ) { window.alert('Nothing works in this browser'); return; }
	if( myReference.style ) { myReference.style.visibility = 'visible'; } else {
		if( myReference.visibility ) { myReference.visibility = 'show'; } else {
			window.alert('Nothing works in this browser'); return; } }
}

function hideDiv(divID_as_a_string) {
	var myReference = getRefToDiv(divID_as_a_string);
	if( !myReference ) { window.alert('Nothing works in this browser'); return; }
	if( myReference.style ) { myReference.style.visibility = 'hidden'; } else {
		if( myReference.visibility ) { myReference.visibility = 'hide'; } else {
			window.alert('Nothing works in this browser'); return; } }
}



function expand(id_layer)
{
	if(bw.ns6)
	{
		showDiv(id_layer);
	}
	else
	{

		eval("document"+myL+"['"+id_layer+"']"+myS+".visibility='visible'") ;
	}

}
function getAbsolutePosition(el) {
	var r = { x: el.offsetLeft, y: el.offsetTop };
	if (el.offsetParent) {
		var tmp = getAbsolutePosition(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
};
function colapse(id_layer){
	var tags = new Array ('applet', 'iframe', 'select');
	var el = getRefToDiv(id_layer);

	var p = getAbsolutePosition(el);
	var EX1 = p.x;
	var EX2 = el.offsetWidth + EX1;
	var EY1 = p.y;
	var EY2 = el.offsetHeight + EY1;

	for (var k = 0; k < tags.length; k++) {
		var ar = document.getElementsByTagName(tags[k]);
		var cc = null;

		for (var i = 0; i < ar.length; i++) {
			cc = ar[i];

			q = getAbsolutePosition(cc);
			var CX1 = q.x;
			var CX2 = cc.offsetWidth + CX1;
			var CY1 = q.y;
			var CY2 = cc.offsetHeight + CY1;

			if ((CX1 > EX2) || (CX2 < EX1) || (CY1 > EY2) || (CY2 < EY1)) {
				cc.style.visibility = "hidden";
			} else {
				cc.style.visibility = "visible";
			}
		}
	}

	if(bw.ns6)
	{
		hideDiv(id_layer);
	}
	else
	{

		eval("document"+myL+"['"+id_layer+"']"+myS+".visibility='hidden'") ;
	}
}
function expand_map(id_layer)
{
  document.map_img.src="./tpl/img/harta-arges.jpg";
	var tags = new Array ('applet', 'iframe', 'select');
	var el = getRefToDiv(id_layer);

	var p = getAbsolutePosition(el);
	var EX1 = p.x;
	var EX2 = el.offsetWidth + EX1;
	var EY1 = p.y;
	var EY2 = el.offsetHeight + EY1;

	for (var k = 0; k < tags.length; k++) {
		var ar = document.getElementsByTagName(tags[k]);
		var cc = null;

		for (var i = 0; i < ar.length; i++) {
			cc = ar[i];

			q = getAbsolutePosition(cc);
			var CX1 = q.x;
			var CX2 = cc.offsetWidth + CX1;
			var CY1 = q.y;
			var CY2 = cc.offsetHeight + CY1;

			if ((CX1 > EX2) || (CX2 < EX1) || (CY1 > EY2) || (CY2 < EY1)) {
				cc.style.visibility = "visible";
			} else {
				cc.style.visibility = "hidden";
			}
		}
	}

	if(bw.ns6)
	{
		showDiv(id_layer);
	}
	else
	{
  		eval("document"+myL+"['"+id_layer+"']"+myS+".visibility='visible'") ;
	}
}

