var window_inline = false;
var mail_input_err = false;

var mouseonMailSetup=false;

function showMailSetup(){
	if(!window_inline){
		main_obj = document.getElementById("mail_setup");
		main_obj.style.top = main_obj.parentNode.offsetHeight + "px";
		main_obj.style.left = "0px";		
		main_obj.style.display='inline';	
		window_inline = true;
		document.body.onclick=function(){			
			if (mouseonMailSetup==false && window_inline==true){
				close_mail_window();
			}
		}
	}else{
		//window_inline = !window_inline;		
		close_mail_window();
	}
}
function sendMail(pid){
	var mail_ad = TrimString(document.getElementById("user_mail").value);
	var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (!filter.test(mail_ad)){
		 document.getElementById("user_mail").style.color = "red";
		 mail_input_err = !mail_input_err;
		}else{
			asinh_ajax(mail_ad,pid);
		}
}

function close_mail_window(){
	main_obj = document.getElementById("mail_setup");
	main_obj.style.display='none';	
	window_inline = false;
}

function mail_input(){
		document.getElementById("user_mail").style.color = "#000000";	
}
function TrimString(sInString){
sInString = sInString.replace(/ /g,'');
return sInString.replace(/(^\s+)|(\s+$)/g, '');
}

function getXmlHttp(){
  var xmlhttp;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      xmlhttp = false;
    }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}

function sinh_ajax(){
	var xmlhttp = getXmlHttp()
	xmlhttp.open('GET', '/xhr/test.html', false);
	xmlhttp.send(null);
	if(xmlhttp.status == 200) {
	  alert(xmlhttp.responseText);
	}	
}
function asinh_ajax(add,pid){
	var xmlhttp = getXmlHttp()
	req = '/assets/ajax/mail_form.php?add='+add+'&pid='+pid;
	xmlhttp.open('GET', req, true);
	xmlhttp.onreadystatechange = function() {
	  if (xmlhttp.readyState == 4) {
	     if(xmlhttp.status == 200) {
	       //alert(xmlhttp.responseText);
	        close_mail_window();
	     }
	  }
	};
xmlhttp.send(null);
}
