
function get_id(id_name)
{
	if (document.all)
	{
		element_id = eval("document.all." + id_name);
	}
	else if (document.getElementById)
	{
		element_id = eval("document.getElementById('" + id_name + "')");
	}
	else if (document.layers)
	{
		element_id = eval("document." + id_name);
	}
	
	return element_id;
	
}


function toogle_div(div_id, status)
{
	id = get_id(div_id);
	
	switch (status)
	{
		case 1:
		{
			id.style.display = 'block';
			break;
		}
		case -1:
		{
			id.style.display = 'none';
			break;
		}
		default:
		{
			if (id.style.display == 'block')
			{
				id.style.display = 'none';
			}
			else
			{
				id.style.display = 'block';
			}
			break;
		}
		
	}
	
	return true;
}
function valid_send_mail(lang)
{
	
	
	if (lang=='ro')
	{
		if (get_id('send_name').value == '')
		{
			alert("Va rugam sa introduceti numele.");
			return  false;
		}
		if (!emailCheck(get_id('send_email').value))
		{
			alert("Va rugam sa introduceti o adresa de email valida.");
			return  false;
		}
		if (get_id('send_message').value == '')
		{
			alert("Va rugam sa introduceti mesajul.");
			return  false;
		}
	}
	if (lang=='en')
	{
		if (get_id('send_name').value == '')
		{
			alert("Plese insert name.");
			return  false;
		}
		if (get_id('send_message').value == '')
		{
			alert("Please insert message.");
			return  false;
		}
		if (!emailCheck(get_id('send_email').value))
		{
			alert("Plese insert a valid email address.");
			return  false;
		}
	}
	

	return true;
}
function show_photo(new_photo,param)
{
	
	document.images['main_photo'+param].src = new_photo;
	return true;
}
function change_border(id,param)
{
	document.getElementById('poza_3'+param).className = "poza_detaliu";
	document.getElementById('poza_1'+param).className = "poza_detaliu";
	document.getElementById('poza_2'+param).className = "poza_detaliu";
	document.getElementById(id).className = "poza_select";
	return true;
}

function emailCheck (emailStr) 
{
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		//alert("E-mail  incorect (verifica te rog @ si .s)")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	if (user.match(userPat)==null) {
		//alert("Id-ul de email este invalid!")
		return false
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		// this is an IP address
		  for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Adresa IP de destinatie este invalida!")
			return false
			}
		}
		return true
	}
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		//alert("Numele domeniului de mail este invalid!")
		return false
	}
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 ||
		domArr[domArr.length-1].length>3) {
	   //alert("Adresa de email se termina in numele domeniului (3 litere) sau indicativul tarii (2 litere)")
	   return false
	}
	if (len<2) {
	   //var errStr="Adresa de e-mail este incompleta!"
	  // alert(errStr)
	   return false
	}
	return true;
}

function createOverlay(width, height, url)
{
   if(!document.getElementById('overlay_wrapper')){
   	
	    var top = document.createElement('DIV');
	    top.className = 'transparency';
   	    top.id = 'transparency';
   	    top.onclick=function()
   	    {
    		close_form_subscribers('overlay_wrapper', 'transparency');
	    }
	    document.body.appendChild(top); 
   	    var ov = document.createElement('DIV');
	
   	ov.className = 'overlay_wrapper';
   	ov.id = 'overlay_wrapper';
   	ov.style.width = width + 'px';
   	ov.style.height = height + 'px';
   	ov.innerHTML = 'Loading...';
	left = (parent.document.body.clientWidth - width)/2;
	ov.style.left = left + 'px';
	ov.style.top = '50px';
	document.body.appendChild(ov);
	requestData(url, 'overlay_wrapper');
  
   return false;
}
}

function createXMLHttp() {

    if (typeof XMLHttpRequest != "undefined") {
        return new XMLHttpRequest();
    } else if (window.ActiveXObject) {
      var aVersions = [ "MSXML2.XMLHttp.5.0",
        "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
        "MSXML2.XMLHttp","Microsoft.XMLHttp"
      ];

      for (var i = 0; i < aVersions.length; i++) {
        try {
            var oXmlHttp = new ActiveXObject(aVersions[i]);
            return oXmlHttp;
        } catch (oError) {
            //Do nothing
        }
      }
    }
    throw new Error("XMLHttp object could be created.");
}

function requestData(url, div_id)
{
	xmlHttp = createXMLHttp();
	xmlHttp.open("get", url, true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4){
			
			    document.getElementById(div_id).innerHTML = xmlHttp.responseText;
			
		}
	}
	xmlHttp.send(null);

}

function close_form_subscribers(div_id, transparency_id)
{
	if(document.getElementById(div_id)){
		document.getElementById(div_id).parentNode.removeChild(document.getElementById(div_id));
		if(document.getElementById(transparency_id)){
			document.getElementById(transparency_id).parentNode.removeChild(document.getElementById(transparency_id));
		}
		ajax_in_progress = false;
		//window.location.reload();
	}
	if (document.getElementById('flash'))
		document.getElementById('flash').style.visibility='visible';
	else if (document.getElementById('jurizare'))
		frames['jurizare'].document.getElementById('flash').style.visibility='visible';
		//alert("a");
}