/*Javascript File*/

function getHTTPObject() { 
	var xmlhttp; 
	
	if(window.XMLHttpRequest){ 
		xmlhttp = new XMLHttpRequest(); 
	} 
	else if (window.ActiveXObject){ 
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		if (!xmlhttp){ 
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
		}
	} 
	return xmlhttp;
}
var http = getHTTPObject(); 


function setBackground(background){	
	var newBack = document.getElementById('backgroundId');
	
	newBack.style.backgroundImage = 'url(images/' + background +')';	

}

function searchDoc(){
	var eName = document.getElementById('eName').checked;
	var data = document.getElementById('data').value;
	
	if (data != '' && data.length > 2){	
		document.fr.submit();
/*		var url = 'includes/ajax_search_doc_.php?eName=';
		http.open("GET", url + escape(eName) + '&data=' + data , true); 	
		http.onreadystatechange = handleSearchDoc;
		http.send(null);*/	
	}
}

function handleSearchDoc(){
	if (http.readyState == 4) { 
		if(http.status == 200) { 			
			document.getElementById('results').innerHTML = http.responseText;	
		}else{
			alert('Error code: ' + http.status == 200 + ' \n\nDump:' + http.responseText);
		}
	} 	
}

function rowOver(control, id){
	control.style.backgroundColor = '#AE9F77';
	control.style.color = "#595959";
	control.style.cursor = 'pointer';
	if (document.getElementById(id))
		document.getElementById(id).style.backgroundColor = '#E3D8BC';

}

function rowOut(control){
	control.style.backgroundColor='#E3D8BC';
	control.style.color="#595959";
}

function showResults(iduser){
		var url = 'includes/ajax_search_results.php?iduser=';
		http.open("GET", url + escape(iduser), true); 	
		http.onreadystatechange = handleShowResults;
		http.send(null);
}

function handleShowResults(){
	if (http.readyState == 4) { 
		if(http.status == 200) { 	
			document.getElementById('results').innerHTML=http.responseText;			
		}else{
			alert('Error code: ' + http.status == 200 + ' \n\nDump:' + http.responseText);
		} 
	} 	
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		var pass = true;
						
		if (str.indexOf(at)==-1)   pass = false

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)   pass = false

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)  pass = false

		 if (str.indexOf(at,(lat+1))!=-1)  pass = false

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)  pass = false

		 if (str.indexOf(dot,(lat+2))==-1)   pass = false
		
		 if (str.indexOf(" ")!=-1)   pass = false

		
 		 return pass;
}

function addNewsletter(){
	var emailID = document.getElementById('email');
	var exclude = document.getElementById('exclude').checked;
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Por favor ingrese un correo electronico")
		emailID.focus()
		
	}else if (echeck(emailID.value)==false){
	 	alert("E-mail incorrecto")
		emailID.value=""
		emailID.focus();		
	}else{
		
		var url = 'includes/ajax_add_email.php?email='+ escape(emailID.value) + '&erase=' + escape(exclude);
		//alert(emailID.value + ' ' + url);
		http.open("GET", url  , true); 	
		http.onreadystatechange = handleAddNewsletter;
		http.send(null);			
	}	
 }
 
function handleAddNewsletter(){
	if (http.readyState == 4) { 
		if(http.status == 200) { 	
			alert(http.responseText);
			document.getElementById('email').value="Digite su e-mail";
		}else{
			alert('Error code: ' + http.status + ' \n\nDump:' + http.responseText);
		} 
	} 	
}

function loadToolTip(selector){
	var msg = '';
	
	switch(selector){
		case 1:
		msg = 'Después del trigésimo día (30 días) del nacimiento, hasta antes de cumplir los dieciocho años. Los nacimientos dentro de los 30 días no requieren cita';
		break;
		default:
		msg = '...';
		break;
	}
	document.getElementById('tooltip_text').innerHTML = msg;
}
function launchDocs(){

	var parameters = "scrollbars=no,status=no,location=no,toolbar=no,menubar=no,directories=no,resizable=no,width=900,height=700,top=10%,left=15%";	
	var url = 'https://intranet.consuladoperutokio.org/citas/launchCitas.php';
	var randomnumber = Math.floor(Math.random()*11);
	var name = 'citas_' +  randomnumber;
	window.open(url, name, parameters);
}

<!----------------------------MESAGE BOX ------------------------------>
var new_win = new Array();
var new_wait = '';

function msgBox(message, title, width, height){
	
	if (width === undefined) width = 400;
	if (height === undefined) height = 250;	
	var index = new_win.length;	
	var extraPos = (index > 0)?50:0;	
	var rand = Math.floor(Math.random()*1501);
	new_wait = document.getElementsByTagName("BODY")[0];
	new_win[index] = document.createElement("DIV");
	new_win[index].setAttribute('id','messageBox_'+ rand);
	//new_win.setAttribute('class','shadow');
	new_win[index].style.width = width+'px';
	new_win[index].style.height = height+'px';
	new_win[index].style.position = "absolute";
	new_win[index].style.borderWidth  = "1px";
	new_win[index].style.borderColor = "#CCCCCC";									
	new_win[index].style.borderStyle = "solid";												
	new_win[index].style.left = ((document.body.offsetWidth/2)-(width/2)) + extraPos;
	new_win[index].style.top = ((document.body.offsetHeight/2))-100 + extraPos;						
	new_win[index].style.backgroundColor = "#ffffff";
	new_win[index].style.opacity = 1;
	new_win[index].style.filter = "alpha(opacity=100)";					
	new_wait.appendChild(new_win[index]);	

	var url = 'msgBox.php?message=';	
	http.open("GET", url + escape(message) + '&title='+escape(title) + '&window_id=' + escape('messageBox_'+ rand), true); 	
	http.onreadystatechange = function(){
		if (http.readyState == 4) { 
			if(http.status == 200) { 			
				document.getElementById('messageBox_'+ rand).innerHTML = http.responseText;		
			}else{
				alert("Error code " + http.status);
			}
		} 			
	}
	http.send(null);		
	return;
}


function unloadMsgBox(){
	if (new_win.length > 0){
		new_wait.removeChild(new_win.pop());
		//new_win = '';
	}	
}

function handleMsgBoxCont(){

	if (http.readyState == 4) { 
		if(http.status == 200) { 			
			document.getElementById('messageBox').innerHTML = http.responseText;		
		}else{
			alert("Error code " + http.status);
		}
	} 	
}