function openWindow(url, width, height) {
	var img = window.open(url,'img','status=no,toolbar=0,scrollbars=yes,menubar=0,titlebar=0,resizable=1 width=' + width + ' height=' + height + ''); 
	img.focus();
	
}


function mailTo(server,user) {
	document.location.href = "mailto:" + user + "@" + server;
}

function checkForm(frm, lang) {
	arr_messages = new Array();
	arr_messages = {'ro' : 5, 'en' : 5};
	
	//ro
	arr_messages['ro'] = {	'all' : 'Va rugam completati campurile marcate cu * !',
							'email' : 'Va rugam completati corect adresa de email !'};
	
	//en 
	arr_messages['en'] = {	'all' : 'The fields marked with * are mandatory !',
							'email' : 'Please fill-in a correct email address !'};
	
	if((frm.prs_name.value == "")) {
		alert(arr_messages[lang]['all']);
		frm.prs_name.focus();
		return false;
	}
	else if(frm.prs_surname.value == "") {
		alert(arr_messages[lang]['all']);
		frm.prs_surname.focus();
		return false;
	}
	else if(frm.prs_email.value == "") {
		alert(arr_messages[lang]['all']);
		frm.prs_email.focus();
		return false;
	}
	else if(!frm.prs_email.value.match(/^\S{1,}@\S{1,}\.\S{1,}$/)) {
		alert(arr_messages[lang]['email']);
		frm.prs_email.focus();
		return false;
	} 
}

function html2phpForm(form) {
	var l = form.length;
	var i = 0;
	while(i<l) {
		form[i].val = html2php(form[i].value);
		i++;
	}
	
}

function html2php(val) {
	
	//
	var regExp=new RegExp("ã","g");
	val.replace(regExp, "&#259;");
		
	return val;
}


function startCallback() {
	// make something useful before submit (onStart)
	
	blockButtons('off');
	
	return true;
}
 
function completeCallback(response) {
	// make something useful after (onComplete)
	//alert(response)
	response = response + "";
	var arrResult = response.split("|");
	// Eroare la incarcare
	if(arrResult[0] == 1) {
		//document.getElementById(arrResult[2]).value = arrResult[1];
		alert(arrResult[1]);
	}
	else {
		document.getElementById(arrResult[2]).value = arrResult[1];
		document.getElementById(arrResult[3]).innerHTML = arrResult[1];
		document.getElementById(arrResult[3]).href = arrResult[4];
	}
	
	blockButtons('on');
	
}

/**
*
*  AJAX IFRAME METHOD (AIM)
*  http://www.webtoolkit.info/
*
**/
 
AIM = {
 
	frame : function(c) {
 
		var n = 'f' + Math.floor(Math.random() * 99999);
		var d = document.createElement('DIV');
		d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
		document.body.appendChild(d);
 
		var i = document.getElementById(n);
		if (c && typeof(c.onComplete) == 'function') {
			i.onComplete = c.onComplete;
		}
 
		return n;
	},
 
	form : function(f, name) {
		f.setAttribute('target', name);
	},
 
	submit : function(f, c) {
		AIM.form(f, AIM.frame(c));
		if (c && typeof(c.onStart) == 'function') {
			return c.onStart();
		} else {
			return true;
		}
	},
 
	loaded : function(id) {
		var i = document.getElementById(id);
		if (i.contentDocument) {
			var d = i.contentDocument;
		} else if (i.contentWindow) {
			var d = i.contentWindow.document;
		} else {
			var d = window.frames[id].document;
		}
		if (d.location.href == "about:blank") {
			return;
		}
 
		if (typeof(i.onComplete) == 'function') {
			i.onComplete(d.body.innerHTML);
		}
	}
 
}


function blockButtons(type) {
	if(type == 'off') {
		disabled = '1';
	}
	else if(type == 'on') {
		disabled = '';
	}
	document.getElementById('submitMainForm').disabled = disabled;
	document.getElementById('resetMainForm').disabled = disabled;
	document.getElementById('closeMainForm').disabled = disabled;
}