
function setBudgetVisitors(budgetdiv)
{
	var budgetnote = document.getElementById(budgetdiv);
	if (document.sidebar_contact_form.sidebar_contact_budget.value == '100E')
		budgetnote.innerHTML = 'minim 200 vizitatori targetati';
	if (document.sidebar_contact_form.sidebar_contact_budget.value == '200E')
		budgetnote.innerHTML = 'minim 400 vizitatori targetati';
	if (document.sidebar_contact_form.sidebar_contact_budget.value == '300E')
		budgetnote.innerHTML = 'minim 600 vizitatori targetati';
	if (document.sidebar_contact_form.sidebar_contact_budget.value == '400E')
		budgetnote.innerHTML = 'minim 800 vizitatori targetati';
	if (document.sidebar_contact_form.sidebar_contact_budget.value == '500E')
		budgetnote.innerHTML = 'minim 1000 vizitatori targetati';
	if (document.sidebar_contact_form.sidebar_contact_budget.value == '+500E')
		budgetnote.innerHTML = 'In functie de marimea bugetului iti putem garanta un numar de vizitatori targetati';
}

/* POSTING STUFF */
   var http_request = false;
   
   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
	  var loading_content = '<div align="center"><img src="images/loading.gif" border="0" width="220" height="19"></div>';
	  document.getElementById('sidebar_contact_form_response').innerHTML = loading_content;
	   
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('sidebar_contact_form_response').innerHTML = result;            
         } else {
            alert('Problema la postare.');
         }
      }
   }
   
   function sidebar_form_post() {
      var poststr = "sidebar_contact_name=" + encodeURI( document.getElementById("sidebar_contact_name").value ) +
                    "&sidebar_contact_email=" + encodeURI( document.getElementById("sidebar_contact_email").value ) +
					"&sidebar_contact_phone=" + encodeURI( document.getElementById("sidebar_contact_phone").value ) + 
					"&sidebar_contact_message=" + encodeURI( document.getElementById("sidebar_contact_message").value )
					;
      makePOSTRequest('includes/_sidebar_contact_form_post.php', poststr);
   }

/* END POSTING STUFF */

/* Obfuscating the contact email */
function getMainContactEmail()
{
	var erp = new Array;
	erp[0] = 1668247156;
	erp[1] = 1633907776;
	erp[2] = 2003133042;
	erp[3] = 1768384628;
	erp[4] = 1835361385;
	erp[5] = 1630433903;
	erp[6] = 1044266556;
	erp[7] = 1010590575;
	erp[8] = 1853120867;
	erp[9] = 1950381925;
	erp[10] = 1651665255;
	erp[11] = 1752460645;
	erp[12] = 1684627758;
	erp[13] = 29295;
	var em = '';
	var tmp;
	for(i=0;i<erp.length;i++){
		tmp = erp[i];
		if(Math.floor((tmp/Math.pow(256,3)))>0){
			em += String.fromCharCode(Math.floor((tmp/Math.pow(256,3))));
		};
		tmp = tmp - (Math.floor((tmp/Math.pow(256,3))) * Math.pow(256,3));
		if(Math.floor((tmp/Math.pow(256,2)))>0){
			em += String.fromCharCode(Math.floor((tmp/Math.pow(256,2))));
		};
		tmp = tmp - (Math.floor((tmp/Math.pow(256,2))) * Math.pow(256,2));
		if(Math.floor((tmp/Math.pow(256,1)))>0){
			em += String.fromCharCode(Math.floor((tmp/Math.pow(256,1))));
		};
		tmp = tmp - (Math.floor((tmp/Math.pow(256,1))) * Math.pow(256,1));
		if(Math.floor((tmp/Math.pow(256,0)))>0){
			em += String.fromCharCode(Math.floor((tmp/Math.pow(256,0))));
		};
	};
	var tmp = new Array;
	tmp = em.split('>>><<<');
	em = tmp[0];
	var an = tmp[1];
	var nl = document.createElement('a');
	nl.setAttribute('id', 'contact-email-link');
	nl.setAttribute('href', 'mailto:' + em);
	document.getElementById('contact-email-to-be-filled-in-with-javascript').appendChild(nl);
	document.getElementById('contact-email-link').innerHTML = an;
}

function getAPMail()
{
	var erp = new Array;
	erp[0] = 1633972841;
	erp[1] = 1634610800;
	erp[2] = 1869636979;
	erp[3] = 1668628599;
	erp[4] = 1700950633;
	erp[5] = 1734898797;
	erp[6] = 1701079393;
	erp[7] = 779251518;
	erp[8] = 1044266044;
	erp[9] = 1013015666;
	erp[10] = 1767992878;
	erp[11] = 1886351461;
	erp[12] = 1935897920;
	erp[13] = 2003133042;
	erp[14] = 1768384628;
	erp[15] = 1835361385;
	erp[16] = 1630433903;
	erp[17] = 0;
	var em = '';
	var tmp;
	for(i=0;i<erp.length;i++){
		tmp = erp[i];
		if(Math.floor((tmp/Math.pow(256,3)))>0){
			em += String.fromCharCode(Math.floor((tmp/Math.pow(256,3))));
		};
		tmp = tmp - (Math.floor((tmp/Math.pow(256,3))) * Math.pow(256,3));
		if(Math.floor((tmp/Math.pow(256,2)))>0){
			em += String.fromCharCode(Math.floor((tmp/Math.pow(256,2))));
		};
		tmp = tmp - (Math.floor((tmp/Math.pow(256,2))) * Math.pow(256,2));
		if(Math.floor((tmp/Math.pow(256,1)))>0){
			em += String.fromCharCode(Math.floor((tmp/Math.pow(256,1))));
		};
		tmp = tmp - (Math.floor((tmp/Math.pow(256,1))) * Math.pow(256,1));
		if(Math.floor((tmp/Math.pow(256,0)))>0){
			em += String.fromCharCode(Math.floor((tmp/Math.pow(256,0))));
		};
	};
	var tmp = new Array;
	tmp = em.split('>>><<<');
	em = tmp[0];
	var an = tmp[1];
	var nl = document.createElement('a');
	nl.setAttribute('id', 'ap-email-link');
	nl.setAttribute('href', 'mailto:' + em);
	document.getElementById('ap-email-to-be-filled-in-with-javascript').appendChild(nl);
	document.getElementById('ap-email-link').innerHTML = an;
}


function getBAMail()
{
	var erp = new Array;
	erp[0] = 1651468132;
	erp[1] = 1634610785;
	erp[2] = 1919905344;
	erp[3] = 2003133042;
	erp[4] = 1768384628;
	erp[5] = 1835361385;
	erp[6] = 1630433903;
	erp[7] = 1044266556;
	erp[8] = 1010590319;
	erp[9] = 1734631790;
	erp[10] = 778138223;
	erp[11] = 1849718629;
	erp[12] = 1651665255;
	erp[13] = 1752460645;
	erp[14] = 1684627758;
	erp[15] = 29295;
	var em = '';
	var tmp;
	for(i=0;i<erp.length;i++){
		tmp = erp[i];
		if(Math.floor((tmp/Math.pow(256,3)))>0){
			em += String.fromCharCode(Math.floor((tmp/Math.pow(256,3))));
		};
		tmp = tmp - (Math.floor((tmp/Math.pow(256,3))) * Math.pow(256,3));
		if(Math.floor((tmp/Math.pow(256,2)))>0){
			em += String.fromCharCode(Math.floor((tmp/Math.pow(256,2))));
		};
		tmp = tmp - (Math.floor((tmp/Math.pow(256,2))) * Math.pow(256,2));
		if(Math.floor((tmp/Math.pow(256,1)))>0){
			em += String.fromCharCode(Math.floor((tmp/Math.pow(256,1))));
		};
		tmp = tmp - (Math.floor((tmp/Math.pow(256,1))) * Math.pow(256,1));
		if(Math.floor((tmp/Math.pow(256,0)))>0){
			em += String.fromCharCode(Math.floor((tmp/Math.pow(256,0))));
		};
	};
	var tmp = new Array;
	tmp = em.split('>>><<<');
	em = tmp[0];
	var an = tmp[1];
	var nl = document.createElement('a');
	nl.setAttribute('id', 'ba-email-link');
	nl.setAttribute('href', 'mailto:' + em);
	document.getElementById('ba-email-to-be-filled-in-with-javascript').appendChild(nl);
	document.getElementById('ba-email-link').innerHTML = an;
}

/* sidebar form validation function */
function validate_sidebar_form(form) {
  var name = form.sidebar_contact_name.value;
  var email = form.sidebar_contact_email.value;
  var message = form.sidebar_contact_message.value;
  var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
  if(name == "") {
    inlineMsg('sidebar_contact_name','Completeaza numele',2);
    return false;
  }
  if(!name.match(nameRegex)) {
    inlineMsg('sidebar_contact_name','Completeaza numele corect!',2);
    return false;
  }
  if(email == "") {
    inlineMsg('sidebar_contact_email','Completeaza adresa de email.',2);
    return false;
  }
  if(!email.match(emailRegex)) {
    inlineMsg('sidebar_contact_email','Adresa de email este invalida',2);
    return false;
  }
  if(message == "") {
    inlineMsg('sidebar_contact_message','Completeaza mesajul');
    return false;
  }
  if(message.match(messageRegex)) {
    inlineMsg('sidebar_contact_message','Mesaj invalid');
    return false;
  }
  return true;
}

/* sidebar form validation function */
function validate_contact_form(form) {
  var name = form.contact_name.value;
  var email = form.contact_email.value;
  var message = form.contact_message.value;
  var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
  if(name == "") {
    inlineMsg('contact_name','Completeaza numele',2);
    return false;
  }
  if(!name.match(nameRegex)) {
    inlineMsg('contact_name','Completeaza numele corect!',2);
    return false;
  }
  if(email == "") {
    inlineMsg('contact_email','Completeaza adresa de email.',2);
    return false;
  }
  if(!email.match(emailRegex)) {
    inlineMsg('contact_email','Adresa de email este invalida',2);
    return false;
  }
  if(message == "") {
    inlineMsg('contact_message','Completeaza mesajul');
    return false;
  }
  if(message.match(messageRegex)) {
    inlineMsg('contact_message','Mesaj invalid');
    return false;
  }
  return true;
}



// START OF MESSAGE SCRIPT //
var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 3;

// build out the divs, set attributes and call the fade function //
function inlineMsg(target,string,autohide) {
  var msg;
  var msgcontent;
  if(!document.getElementById('msg')) {
    msg = document.createElement('div');
    msg.id = 'msg';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;
  var targetdiv = document.getElementById(target);
  targetdiv.focus();
  var targetheight = targetdiv.offsetHeight;
  var targetwidth = targetdiv.offsetWidth;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;  
  }
  window.setTimeout("hideMsg()", (autohide * 1000));
}

// hide the form alert //
function hideMsg(msg) {
  var msg = document.getElementById('msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}

// face the message box //
function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}

// calculate the position of the element in relation to the left of the browser //
function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}

// calculate the position of the element in relation to the top of the browser window //
function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}

// preload the arrow //
if(document.images) {
  arrow = new Image(7,80); 
  arrow.src = "../images/msg_arrow.gif"; 
}