// JavaScript Document
//var DOMAIN="/mutual";
function objectAjax()
	{
	var xmlhttp=false;
	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 isMail(texto)
	{ 
	var mailres = true;             
	var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-"; 
	 
	var arroba = texto.indexOf("@",0); 
	if ((texto.lastIndexOf("@")) != arroba) arroba = -1; 
	 
	var punto = texto.lastIndexOf("."); 
				 
	for (var contador = 0 ; contador < texto.length ; contador++)
		{ 
		if (cadena.indexOf(texto.substr(contador, 1),0) == -1)
			{ 
			mailres = false; 
			break; 
		 	} 
		} 	
	if ((arroba > 1) && (arroba + 1 < punto) && (punto + 2 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1)) 
		 mailres = true; 
	else 
		 mailres = false; 
	return mailres; 
	} 
function validateForm()
{
	sw0=true;
	sw1=true;
	sw2=true;
	//is_validate (e, valType, nameClass, nameClassError, isRequired, msgRequired, msgErrorType)
	sw0 = is_validate('ct_name', 'text', 'input', 'inputError', true, 'Este es un campo requerido', 'Solo texto');
	if (sw0==false)
	{
	document.getElementById('ct_name').className='req';
	$('#ct_name2').show();
	}
	sw1 = is_validate('ct_mail', 'email', 'input', 'inputError', true, 'Este es un campo requerido', 'Solo E-mail');
	if (sw1==false)
	{
	document.getElementById('ct_mail').className='req';
	$('#ct_mail2').show();
	}
	sw2 = is_validate('ct_phone', 'number', 'input', 'inputError', true, 'Este es un campo requerido', 'Solo números');
	if (sw2==false)
	{
	document.getElementById('ct_phone').className='req';
	$('#ct_phone2').show();
	}
	//alert ('sw0'+sw0+'sw1'+sw1+'sw2'+sw2+'sw3'+sw3);
	
	if ((sw0==true) && (sw1==true) && (sw2==true))
	{
		
		var sendmail = document.getElementById("sendMail");
		var ct_name = document.getElementById('ct_name');
		var ct_mail = document.getElementById('ct_mail');
		var ct_phone = document.getElementById('ct_phone');
		var ct_query = document.getElementById('ct_query');
		var domain = document.getElementById('domain');
		ct_names=ct_name.value;
		ct_mails=ct_mail.value;
		ct_phones=ct_phone.value;
		//ct_deptos=ct_depto.value;
		ct_querys=ct_query.value;
		
		//document.getElementById('hOk').value='ok';
		sendmail.innerHTML= 'Enviando su consulta....';
		//instanciamos el objetoAjax
		ajax=objectAjax();
		//uso del medotod POST
		ajax.open("POST",domain.value + "/skin/contactSend.php",true);
		
		ajax.onreadystatechange=function() {
										  if (ajax.readyState==4) 
											{
											//mostrar resultados en esta capa
											
											document.location.href=domain.value + '/contactenos/';
											sendmail.innerHTML = ajax.responseText;
											//
											}
										}  
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		//enviando los valores
		ajax.send("ct_name="+ct_names+"&ct_mail="+ct_mails+"&ct_query="+ct_querys+"&ct_phone="+ct_phones+"&ct_city="+ct_city)
	}else
	{
		document.getElementById('hOk').value='';
	}
}

function validateForm2()
{
	sw0=true;
	sw1=true;
	sw2=true;
	sw3=true;
	//is_validate (e, valType, nameClass, nameClassError, isRequired, msgRequired, msgErrorType)
	sw0 = is_validate('ct_name', 'text', 'input', 'inputError', true, 'Este es un campo requerido', 'Solo texto');
	if (sw0==false)
	{
	document.getElementById('ct_name').className='req';
	$('#ct_name2').show();
	}
	sw1 = is_validate('ct_mail', 'email', 'input', 'inputError', true, 'Este es un campo requerido', 'Solo E-mail');
	if (sw1==false)
	{
	document.getElementById('ct_mail').className='req';
	$('#ct_mail2').show();
	}
	sw2 = is_validate('ct_phone', 'number', 'input', 'inputError', true, 'Este es un campo requerido', 'Solo números');
	if (sw2==false)
	{
	document.getElementById('ct_phone').className='req';
	$('#ct_phone2').show();
	}
	//alert ('sw0'+sw0+'sw1'+sw1+'sw2'+sw2+'sw3'+sw3);
	sw3 = is_validate('ct_city', 'text', 'input', 'inputError', true, 'Este es un campo requerido', 'Solo texto');
	if (sw3==false)
	{
	document.getElementById('ct_city').className='req';
	$('#ct_city2').show();
	}
	
	if ((sw0==true) && (sw1==true) && (sw2==true) && (sw3==true))
	{
		
		var sendmail = document.getElementById("sendMailOfi");
		var ct_name = document.getElementById('ct_name');
		var ct_mail = document.getElementById('ct_mail');
		var ct_phone = document.getElementById('ct_phone');
 		var ct_city = document.getElementById('ct_city').value;
		var ct_title = document.getElementById('ct_title').value;
		var ct_query = document.getElementById('ct_query');
		var domain = document.getElementById('domain');
		ct_names=ct_name.value;
		ct_mails=ct_mail.value;
		ct_phones=ct_phone.value;
		//ct_deptos=ct_depto.value;
		ct_querys=ct_query.value;
		
		//document.getElementById('hOk').value='ok';
		sendmail.innerHTML= 'Enviando su consulta....';
		//instanciamos el objetoAjax
		ajax=objectAjax();
		//uso del medotod POST
		ajax.open("POST",domain.value + "/skin/officerSend.php",true);
		
		ajax.onreadystatechange=function() {
										  if (ajax.readyState==4) 
											{
											//mostrar resultados en esta capa
											//document.location.href=domain.value + '/contactenos/';
											sendmail.innerHTML = ajax.responseText;
											//
											}
										}  
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		//enviando los valores
		ajax.send("ct_name="+ct_names+"&ct_mail="+ct_mails+"&ct_query="+ct_querys+"&ct_phone="+ct_phones+"&ct_title="+ct_title+"&ct_city="+ct_city)
	}else
	{
		document.getElementById('hOk').value='';
	}
 
}

function restoreNew(a)
{
 if (document.getElementById(a).className=='req')
 {
	 $("#div"+a).hide();
	 $("#"+a+'2').hide();
	 document.getElementById(a).className='inputB';
 }
}
function validateLoginUser()
	{
	document.getElementById('login_user').className='';
	document.getElementById('login_contrasena').className='';
	var login_user = document.getElementById('login_user').value;
	var login_contrasena = document.getElementById('login_contrasena').value;
	var sw=true;
	if (login_user=="")
		{
		document.getElementById('login_user').className='req';
		sw=false;
		}
	if (login_contrasena=="")
		{
		document.getElementById('login_contrasena').className='req';
		sw=false;
		}
	if(sw)
		{
		document.getElementById('frmLog').submit();
		}
	}
function validateComment(cli_uid,for_uid)
	{
	var comment = document.getElementById('comment').value;
	var sw=true;
	if (comment=="")
		{
		document.getElementById('comment').className='req';
		sw=false;
		}
	if (sw)
		{
		$("#comment_form").fadeOut(500);
		$("#comment_form_2").fadeOut(500);
		var newComment = document.getElementById('new_comment')	
		$("#new_comment").fadeIn(500);
		document.location.href='#tag_new_comment';
//		newComment.innerHTML= 'Enviando comentario....';
		//instanciamos el objetoAjax
		ajax=objectAjax();
		//uso del medotod POST
		ajax.open("POST", "../skin/sendComment.php",true);
		ajax.onreadystatechange=function() {
										  if (ajax.readyState==4) 
											{
											//mostrar resultados en esta capa
											newComment.innerHTML = ajax.responseText;
											}
										}  
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		//enviando los valores
		ajax.send("comment="+comment+"&cli_uid="+cli_uid+"&for_uid="+for_uid)
		}
	}
	
	function growTextarea(textarea)	
	{
	// Opera isn't just broken. It's really twisted.
	if (textarea.scrollHeight > textarea.clientHeight && !window.opera)
		{
		while(textarea.scrollHeight > textarea.clientHeight)
			{
			textarea.rows += 1;
			}
		}
	}
	
function showMap(long,lati,uid,ruta)
{	
	ajax=objectAjax();
	ajax.open("POST", "../../skin/gmap.php",false);
    ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    ajax.send("off_latitude="+lati+"&off_longitude="+long+"&uid="+uid);
	document.location.href=ruta;
	//window.reload();
}
function closeMap(uid)
{
	$("#boxMapTop"+uid).toggle();
}
function ShowOfiForm()
{
	$("#sendMailOfi").toggle();
}
function calculateYear(interes,aporte,domin,e)
{
		year=document.getElementById('simval'+e).value;
		if (year > 11)
		{
			$("#boxResP"+e).show();
			document.getElementById('timeYM'+e).innerHTML='<span>'+(Math.floor(year / 12) > 0 ? Math.floor(year / 12) + ' año(s) ' : '') + (year % 12 > 0 ? (year % 12) + ' mes(es)' : ''+'</span>');
		}
		else $("#boxResP"+e).hide();
		$('#simval'+e).keyup(function(d) {
		if (d.keyCode == 13) {
			simulateCre(interes,aporte,domin,e);
		}
		});
}

function simulateCre(interes,aporte,domin,e)
{
		months=document.getElementById('simval'+e).value;
		monto=document.getElementById('simmon'+e).value;
		if (months && monto)
		{
		$("#showCuo"+e).show();
		divx = document.getElementById('cuota'+e);
		divx.innerHTML = '';
		divx.style.display='';
		ajax=objectAjax();
		ajax.open("POST", "../../../formula.php",true);
    	ajax.onreadystatechange=function() { 
										
                                          if (ajax.readyState==4) 
                                            {
                                            divx.style.display='';
                                            divx.innerHTML=ajax.responseText;
                                            }
                                          }  
    	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    	ajax.send("interes="+interes+"&months="+months+"&monto="+monto);
		
		divx2 = document.getElementById('tea'+e);
		divx2.innerHTML = '';
		divx2.style.display='';
		ajax2=objectAjax();
		ajax2.open("POST", "../../../formulatea.php",true);
    	ajax2.onreadystatechange=function() { 
										
                                          if (ajax2.readyState==4) 
                                            {
                                            divx2.style.display='';
                                            divx2.innerHTML=ajax2.responseText;
                                            }
                                          }  
    	ajax2.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    	ajax2.send("interes="+interes+"&months="+months);
		
		$('#planCuentas'+e).attr('href',domin+'/generate.php?interes='+interes+'&months='+months+'&monto='+monto+'&aporte='+aporte);
		}
}

function PrintTable()
{
	$("#myPrintArea").printArea();
}
// Jquery print Area
jQuery.jPrintArea=function(el)
{ 
var iframe=document.createElement('IFRAME');
var doc=null;
$(iframe).attr('style','position:absolute;width:0px;height:0px;left:-500px;top:-500px;');
document.body.appendChild(iframe);
doc=iframe.contentWindow.document;
var links=window.document.getElementsByTagName('link');
for(var i=0;i<links.length;i++)
if(links[i].rel.toLowerCase()=='stylesheet')
doc.write('<link type="text/css" rel="stylesheet" href="'+links[i].href+'"></link>');
doc.write('<div class="'+$(el).attr("class")+'">'+$(el).html()+'</div>');
doc.close();
iframe.contentWindow.focus();
iframe.contentWindow.print();
alert('Printing...');
document.body.removeChild(iframe);
};
