// JavaScript Document

var PathDomian ='/inti';

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;
	//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();
	}
	//alert ('sw0'+sw0+'sw1'+sw1+'sw2'+sw2+'sw3'+sw3);
	
	if ((sw0==true) && (sw1==true) && (sw2==true) )
	{
		document.getElementById('hOk').value='ok';
		document.getElementById('formReg').submit();
	}else
	{
		document.getElementById('hOk').value='';
	}
}
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();
	}
	/*else
	{
	var ct_mail = document.getElementById("ct_mail");
	ajax=objectAjax();
	ajax.open("POST","http://"+window.location.host+PathDomian+"/skin/CheckMail.php",true);
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("ct_mail="+ct_mail.value)	
	}*/
	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';
		$("#formA").attr('action','http://'+window.location.host+PathDomian+'/skin/usersAdd.php');
		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_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_area = document.getElementById('ct_area').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_area=ct_area.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_area="+ct_area)
	}else
	{
		document.getElementById('hOk').value='';
	}
 
}
function reptaAdmin(e,pag)
{
	$("#reptaIn").load("http://"+window.location.host+PathDomian+"/skin/infomed_repta.php?dou_uid="+e+"&pag="+pag.value);
}
function editAdmin(e,pag)
{
	$("#reptaIn").load("http://"+window.location.host+PathDomian+"/skin/infomed_edit.php?dou_uid="+e+"&pag="+pag.value);
}
function delAdmin(e)
{
	$("#label"+e).hide();
	$("#Tbox"+e).hide();
	ajax=objectAjax();
	ajax.open("POST", "http://"+window.location.host+PathDomian+"/skin/queAskDel.php",true);
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	//enviando los valores
	ajax.send("dou_uid="+e);
	return false;
}
function sendAdmin(e)
{
	$("#label"+e).hide();
	$("#Tbox"+e).hide();
	ajax=objectAjax();
	ajax.open("POST", "http://"+window.location.host+PathDomian+"/skin/queAskSend.php",true);
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	//enviando los valores
	ajax.send("dou_uid="+e);
	return false;
}

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 validateLoginUser()
	{
	document.getElementById('usr_email').className='';
	document.getElementById('usr_pass').className='';
	var usr_email = document.getElementById('usr_email').value;
	var usr_pass = document.getElementById('usr_pass').value;
	var sw=true;
	if (usr_email=="")
		{
		document.getElementById('usr_email').className='req';
		sw=false;
		}
	else
		{
		document.getElementById('usr_email').className='inputB';
		}
	if (usr_pass=="")
		{
		document.getElementById('usr_pass').className='req';
		sw=false;
		}
	else
		{
		document.getElementById('usr_pass').className='inputB';
		}	
	if(sw)
		{
		document.location.href='http://'+window.location.host+PathDomian+'/skin/Login.php?usr_email='+usr_email+'&usr_pass='+usr_pass;
		}
}
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 closeUser()
	{
		document.location.href='http://'+window.location.host+PathDomian+'/logout.php';
	}


function DocP(e)
{
	$("#ShowDoc").show();
		divx = document.getElementById('generateForm');
		ajax=objectAjax();
		ajax.open("POST", "http://"+window.location.host+PathDomian+"/skin/CatShow.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("job_category="+e.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 lookListCategory(e)
{	
	var domain = document.getElementById('rutaJs').value;
	divx = document.getElementById('ListAdrress');
	if (e.value=='00')
	{
	window.location.reload();	
	}
	else
	{
	divx.innerHTML = '';
	divx.style.display='';
	ajax=objectAjax();
	ajax.open("POST", domain+"/skin/ListCategory.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("cty_cod="+e.value);
	}
}	
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);
};
function validate()
{
	sw=true;
	if (document.getElementById('search').value=='')
		{
		sw=false;
		scroll(0,0);
		}
	else{
		dato=document.getElementById('search').value;
		domain=document.getElementById('dom').value;
		domainS=document.getElementById('domS').value;
		document.location.href=domain+domainS+'='+dato+'/'; 
		}
}
function validate2()
{
		AdvProd=document.getElementById('AdvProd').value;
		AdvLine=document.getElementById('AdvLine').value;
		AdvCode=document.getElementById('AdvCode').value;
		domain=document.getElementById('dom').value;
		domainS=document.getElementById('domS').value;
		document.location.href=domain+domainS+'='+AdvProd+'_'+AdvLine+'_'+AdvCode+'/'; 
}
 $(document).ready(function(){
	$("#search").keyup(function(e){
		if(e.keyCode==13) validate();
   	});
	$("#AdvProd").keyup(function(e){
		if(e.keyCode==13) validate2();
   	});
	$("#AdvLine").keyup(function(e){
		if(e.keyCode==13) validate2();
   	});
	$("#AdvCode").keyup(function(e){
		if(e.keyCode==13) validate2();
   	});
});
 function valForm()
{
	sw=true;
	if(!is_validate('mail', 'email', 'input', 'inputError', true, 'E-mail is required', 'E-mail error')) sw=false; 
	if(!is_validate('contact', 'text', 'input', 'inputError', true, 'Contact is required', 'Contact error')) sw=false; 
	if(!is_validate('description', 'text', 'input', 'inputError', true, 'Description is required', 'Description error')) sw=false; 
	if (sw)	
	 document.getElementById('ActionForm').value='ok';
	else
	{
		return false;
	}
}
