// JavaScript Document
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 validateForm2()
{
	sw0=true;
	sw1=true;
	sw2=true;
	sw3=true;
	sw4=true;
	//is_validate (e, valType, nameClass, nameClassError, isRequired, msgRequired, msgErrorType)
	sw0 = is_validate('re_name', 'text', 'input', 'inputError', true, 'Este es un campo requerido', 'Solo texto');
	if (sw0==false)
	{
	document.getElementById('re_name').className='req';
	$('#re_name2').show();
	}
	sw1 = is_validate('re_lastName', 'text', 'input', 'inputError', true, 'Este es un campo requerido', 'Solo texto');
	if (sw1==false)
	{
	document.getElementById('re_lastName').className='req';
	$('#re_lastName2').show();
	}
	sw2 = is_validate('re_phone', 'number', 'input', 'inputError', true, 'Este es un campo requerido', 'Solo números');
	if (sw2==false)
	{
	document.getElementById('re_phone').className='req';
	$('#re_phone2').show();
	}
	sw3 = is_validate('re_ci', 'number', 'input', 'inputError', true, 'Este es un campo requerido', 'Solo números');
	if (sw3==false)
	{
	document.getElementById('re_ci').className='req';
	$('#re_ci2').show();
	}
	sw4 = is_validate('re_office', 'text', 'input', 'inputError', true, 'Este es un campo requerido', 'Solo texto');
	if (sw4==false)
	{
	document.getElementById('re_office').className='req';
	$('#re_office2').show();
	}
	//alert ('sw0'+sw0+'sw1'+sw1+'sw2'+sw2+'sw3'+sw3);
	
	if ((sw0==true) && (sw1==true) && (sw2==true) && (sw3==true) && (sw4==true))
	{
		var sendConsulta = document.getElementById("sendReclamo");
		var re_name = document.getElementById('re_name');
		var re_lastname = document.getElementById('re_lastName');
		var re_ci = document.getElementById('re_ci');
		var re_phone = document.getElementById('re_phone');
 		var re_mail = document.getElementById('re_mail');
		var re_depto = document.getElementById('re_depto');
		var re_city = document.getElementById('re_city');
		var re_office = document.getElementById('re_office');
		var re_query = document.getElementById('re_query');
		var domain = document.getElementById('domain');
		ct_names=re_name.value;
		ct_lastnames=re_lastname.value;
		ct_phones=re_phone.value;
		ct_mails=re_mail.value;
		ct_deptos=re_depto.value;
		ct_cities=re_city.value;
		ct_querys=re_query.value;
		ct_ci=re_ci.value;
		ct_office=re_office.value;
		
		sendConsulta.innerHTML= 'Enviando su consulta....';
		ajax=objectAjax();
		ajax.open("POST",domain.value + "/skin/reclamosAdd.php",true);
		ajax.onreadystatechange=function() {
										  if (ajax.readyState==4) 
											{
											sendConsulta.innerHTML = ajax.responseText;
											}
										}  
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		//enviando los valores
		ajax.send("ct_name="+ct_names+"&ct_lastname="+ct_lastnames+"&ct_phone="+ct_phones+"&ct_mail="+ct_mails+"&ct_depto="+ct_deptos+"&ct_city="+ct_cities+"&ct_query="+ct_querys+"&cOk=ok&ct_ci="+ct_ci+"&ct_office="+ct_office)
	}
}
function validateForm3()
{
	sw0=true;
	sw1=true;
	sw2=true;
	sw3=true;
	sw4=true;
	//is_validate (e, valType, nameClass, nameClassError, isRequired, msgRequired, msgErrorType)
	sw0 = is_validate('ct_name', 'text', 'inputB', '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', 'inputB', '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', 'inputB', 'inputError', true, 'Este es un campo requerido', 'Solo números');
	if (sw2==false)
	{
	document.getElementById('ct_phone').className='req';
	$('#ct_phone2').show();
	}
	sw3 = is_validate('ct_pass', 'text', 'inputB', 'inputError', true, 'Este es un campo requerido', 'Solo texto');
	if (sw3==false)
	{
	document.getElementById('ct_pass').className='req';
	$('#ct_pass2').show();
	}
	//alert ('sw0'+sw0+'sw1'+sw1+'sw2'+sw2+'sw3'+sw3);
	userCat=document.getElementById('usr_category').value;
	if (userCat==0) {
			sw3=false;
			document.getElementById('usr_category').className='req';
	}
	
	if ((sw0==true) && (sw1==true) && (sw2==true) && (sw3==true)  && (sw4==true))
	{
		document.getElementById('hOk').value='ok';
		document.getElementById('formA').submit(); 
		
	}else
	{
		document.getElementById('hOk').value='';
	}
}
function validateForm4()
{
	sw1=true;
	//is_validate (e, valType, nameClass, nameClassError, isRequired, msgRequired, msgErrorType)
	sw1 = is_validate('ct_mail', 'email', 'inputB', 'inputError', true, 'Este es un campo requerido', 'Solo E-mail');
	if (sw1==false)
	{
	document.getElementById('ct_mail').className='req';
	$('#ct_mail2').show();
	}
	//alert ('sw0'+sw0+'sw1'+sw1+'sw2'+sw2+'sw3'+sw3);
	if ((sw1==true))
	{
		document.getElementById('hOk').value='ok';
		document.getElementById('formA').submit();
	}else
	{
		document.getElementById('hOk').value='';
	}
}

function valEnterSearch()
{
$('#search').keyup(function(d) {
		if (d.keyCode == 13) {
			validateSearch();
		}
		});
}

function validateSearch()
	{
	var sw=true;	
	var searchMain = document.getElementById('search').value;
	if (searchMain=="")
		{
		sw=false;
		}
	if(sw)
		{
		document.getElementById('formBH').submit();
		}
	}
function valEnterAdvSearch2()
{
$('#search').keyup(function(d) {
		if (d.keyCode == 13) {
			validateSearch2();
		}
		});
}
function validateSearch2()
	{
	var sw=true;	
	var searchMain = document.getElementById('search').value;
	if (searchMain=="")
		{
		sw=false;
		}
	if(sw)
		{
		document.getElementById('formBHP').submit();
		}
	}
function valEnterAdvSearch()
{
$('#AdvLine').keyup(function(d) {
		if (d.keyCode == 13) {
			validateSearchAdv();
		}
		});
$('#AdvCode').keyup(function(e) {
		if (e.keyCode == 13) {
			validateSearchAdv();
		}
		});
$('#AdvProd').keyup(function(f) {
		if (f.keyCode == 13) {
			validateSearchAdv();
		}
		});
}	
function validateSearchAdv()
	{
		document.getElementById('formA').submit();
	}	

function validateForm()
{
	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_lastName', 'text', 'input', 'inputError', true, 'Este es un campo requerido', 'Solo texto');
	if (sw1==false)
	{
	document.getElementById('ct_lastName').className='req';
	$('#ct_lastName2').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 sendConsulta = document.getElementById("sendConsulta");
		var ct_name = document.getElementById('ct_name');
		var ct_lastname = document.getElementById('ct_lastName');
		var ct_phone = document.getElementById('ct_phone');
 		var ct_mail = document.getElementById('ct_mail');
		var ct_depto = document.getElementById('ct_depto');
		var ct_city = document.getElementById('ct_city');
		var ct_query = document.getElementById('ct_query');
		var domain = document.getElementById('domain');
		ct_names=ct_name.value;
		ct_lastnames=ct_lastname.value;
		ct_phones=ct_phone.value;
		ct_mails=ct_mail.value;
		ct_deptos=ct_depto.value;
		ct_cities=ct_city.value;
		ct_querys=ct_query.value;
		
		sendConsulta.innerHTML= 'Enviando su consulta....';
		ajax=objectAjax();
		ajax.open("POST",domain.value + "/skin/consultaAdd.php",true);
		ajax.onreadystatechange=function() {
										  if (ajax.readyState==4) 
											{
											sendConsulta.innerHTML = ajax.responseText;
											}
										}  
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		//enviando los valores
		ajax.send("ct_name="+ct_names+"&ct_lastname="+ct_lastnames+"&ct_phone="+ct_phones+"&ct_mail="+ct_mails+"&ct_depto="+ct_deptos+"&ct_city="+ct_cities+"&ct_query="+ct_querys+"&cOk=ok")
	}
}

function validateCalc()
{
	sw0=true;
	//is_validate (e, valType, nameClass, nameClassError, isRequired, msgRequired, msgErrorType)
	sw0 = is_validate('monto', 'text', 'input', 'inputError', true, 'Este es un campo requerido', 'Solo números');
	if (sw0==false)
	{
	document.getElementById('monto').className='req';
	}

	if (sw0==true)
	{
		var Consulta = document.getElementById("CalcMont");
		var monto = document.getElementById("monto");
		var plazo = document.getElementById('plazo');
		var tipomonto = document.getElementById('tipomonto');
		var domain = document.getElementById('domain');
		monto=monto.value;
		plazo=plazo.value;
		tipomonto=tipomonto.value;
		
		Consulta.innerHTML= 'Enviando su consulta....';
		ajax=objectAjax();
		ajax.open("POST",domain.value + "/skin/consultaSim.php",true);
		ajax.onreadystatechange=function() {
										  if (ajax.readyState==4) 
											{
											Consulta.innerHTML = ajax.responseText;
											}
										}  
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		//enviando los valores
		ajax.send("monto="+monto+"&plazo="+plazo+"&tipomonto="+tipomonto)
	}
}


function restoreNew(a)
{
 if (document.getElementById(a).className=='req')
 {
	 $("#div"+a).hide();
	 $("#"+a+'2').hide();
	 document.getElementById(a).className='inputB';
 }
}

function valEnter()
{
$('#usr_pass').keyup(function(d) {
		if (d.keyCode == 13) {
			validateLoginUser();
		}
		});
}

function viewMore(a,b)
{
	 $("#"+a).hide();
	 $("#"+b).slideToggle("slow");
	 return false;
}
function toggleMore(a,b)
{
	 $("#"+b).hide();
	 $("#"+a).slideToggle("slow");
	 return false;
}
function viewMore2(b)
{
	 $("#"+b).slideToggle("slow");
	 document.getElementById('question').value='';
	 return false;
}
function viewMore3(b)
{
	 $("#"+b).slideToggle("slow");
/*	 document.getElementById('linkSend').value='';
	 document.getElementById('docsSend').value='';*/
	 return false;
}
function toggleMore2(b)
{
	 $("#"+b).hide();
	 document.getElementById('question').value='';
	 return false;
}
function showHide(a,b)
{
	 $("#"+b).toggle();
	 $("#"+a).toggle();
	 return false;
}
function showHide2(a,b)
{
	 $("#"+b).toggle();
	 $("#"+a).toggle();
	 document.getElementById('ct_pass').value='';
	 return false;
}

function ShowDepto(e)
{
		divx = document.getElementById('changeDepto');
		ajax=objectAjax();
		ajax.open("POST", "http://"+window.location.host+"/skin/ShowDep.php",true);
		ajax.onreadystatechange=function() {
					if (ajax.readyState==4) 
						{
						//mostrar resultados en esta capa
						divx.innerHTML=ajax.responseText;
						}
					}  
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		//enviando los valores
		ajax.send("uid="+e)	
}
function changeCity(e,f)
{
		divx = document.getElementById('newCity'+e);
		ajax=objectAjax();
		ajax.open("POST", "http://"+window.location.host+"/skin/ListCity.php",true);
		ajax.onreadystatechange=function() {
					if (ajax.readyState==4) 
						{
						//mostrar resultados en esta capa
						divx.innerHTML=ajax.responseText;
						}
					}  
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		//enviando los valores
		ajax.send("cty_cod="+f.value)	
}
	
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 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);
};