<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Carrito de Compras</title>
<style type="text/css">
.talla_error{ height:20px;}

</style>
<script type="text/javascript" src="../js/jquery-1.11.1.js"></script>
<script type="text/javascript" src="../js/valida_ci_ruc_112.js"></script>


<script type="text/javascript">
window.onload = function (){
	//document.getElementById('frm_contenedor').clientwidth=screen.width;
	//document.getElementById('frm_contenedor').clientheight=screen.height;
	
	document.getElementById('frm_contenedor').style.width=screen.width+'px';
	document.getElementById('frm_contenedor').style.height=screen.height+'px';
	document.getElementById('frm_contenedor').style.display='none';
//document.getElementById('frm_contenedor').clientwidth=800;
console.log(screen.width);
console.log(screen.height);
};
var errorx=99;
var ci_tmp='';
var email_tmp='';

var obj_chk;
function _imagen(foto,archivo)
{
	document.getElementById(foto).src='../imgi/'+archivo+'?abc='+Math.floor((Math.random() * 10) + 1);
}

function _carro(rad){
document.getElementById(rad+'_error').innerHTML='';
var nele=document.getElementsByClassName(rad).length-1;
var chk=0;
var item='';
for(i=0;i<=nele;i++){
		if(document.getElementsByClassName(rad).item(i).checked){
			chk=1;
			item=document.getElementsByName(rad).item(i).value;
			break;
		}
	}

if(chk!=1){return false;}

document.getElementById(rad).disabled=true;
document.body.style.cursor='wait';	

$.ajax({
		url:'carr2.php',
		type:'POST', 
		async:false,
		data:{item:item},
		success:function(dato){
			console.log(dato);
			document.body.style.cursor='auto';
			document.getElementById(rad+'_error').innerHTML=dato;
			//alert(dato);
			document.getElementById(rad).disabled=false;
			document.getElementsByClassName(rad).item(i).checked=false;
			obj_chk=rad+'_error';
			if(dato==='Debe iniciar sesion'){ 
			document.getElementById('frm_contenedor').style.display='block';
			
			}
			
		}, 

		error:function(jqXHR,textStatus,errorThrown )
		{
           if (jqXHR.status === 0) {
              alert('Not connect: Verify Network..');
           } else if (jqXHR.status == 404) {
               console.log('Requested page not found [404]');
           } else if (jqXHR.status == 500) {
               console.log('Internal Server Error [500].');
           } else if (exception === 'parsererror') {
               console.log('Requested JSON parse failed.');
           } else if (exception === 'timeout') {
               //console.log('Time out error.');
			   alert('Servidor no Responde');
           } else if (exception === 'abort') {
               console.log('Ajax request aborted.');
           } else {
               console.log('Uncaught Error: ' + jqXHR.responseText);
           }

		}, 

	    complete:function(jqXHR, textStatus){
			if(textStatus==='success'){setTimeout(_limpia, 5000);}
			},
		timeout:30000
	});
	
chk=0;

}
function _limpia()
{
	//obj_chk
	document.getElementById(obj_chk).innerHTML='';
	//setTimeout(document.getElementById(div_err).innerHTML='', 100000);
//var 	myVar = setTimeout(console.log('abc'), 10000);
//var 	myVar =setInterval(console.log('abc'), 10000);
 	console.log('123');
	//clearTimeout(myVar);
}






function usuario(e,t)
{

	if(t.length!=0)
	{	
		if(e.keyCode==13)
		{
			$('#txt_clave').focus();
		}
	}

}
function clave(e)
{
	if(e.keyCode==13)
	{
		valida_ci_ingreso();
	}
}

function valida_ci_ingreso()
{
	document.getElementById('boton').disabled=true;
	var ci=document.getElementById('txt_ci').value;
	var clave=document.getElementById('txt_clave').value;
	var error_ci=valida_ci_ruc(ci);

	var email = ci.indexOf("@");
	if (email>0){error_ci=0;}
	clave=clave.substring(0,6);
	clave=clave.trim();
	
	if(error_ci!=0)
	{
		document.getElementById('error').innerHTML='Ci/Ruc Incorrecto';
		document.getElementById('boton').disabled=false;
		return false;
	}
	else
	{
		document.getElementById('error').innerHTML='';
	}
	if(clave.length!=6)
	{
		document.getElementById('error').innerHTML='Clave debe ser 6 Digitos';
		document.getElementById('boton').disabled=false;
		return false;
	}
	else
	{


	$.ajax({
		cache:false,
		url:'procesa_usr.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{txt_ci:document.getElementById('txt_ci').value,txt_clave:document.getElementById('txt_clave').value}, 
    	beforeSend: function(jqXHR, textStatus)
		{
                
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
			
			document.getElementById('boton').disabled=false;
			
			if(dato==='0')
			{
				document.getElementById('frm_contenedor').style.display='none';
				
				//window.location ='main/index.php';
			}
			else
			{
				document.getElementById('error').innerHTML=dato;
			}
		},
		error:function(jqXHR,textStatus,errorThrown )
		{
           if (jqXHR.status === 0) {
              document.getElementById('error').innerHTML='Sin conexion: Verifique Red.';
           } else if (jqXHR.status == 404) {
               document.getElementById('error').innerHTML='Respuesta pagina not encontrada [404]';
           } else if (jqXHR.status == 500) {
               document.getElementById('error').innerHTML='Internal Server Error [500].';
           } else if (exception === 'parsererror') {
               document.getElementById('error').innerHTML='Requested JSON parse failed.';
           } else if (exception === 'timeout') {
			   document.getElementById('error').innerHTML='Servidor no Responde';
           } else if (exception === 'abort') {
               document.getElementById('error').innerHTML='Ajax request aborted.';
           } else {
               document.getElementById('error').innerHTML='Uncaught Error: ' + jqXHR.responseText;
           }

		}, 
	    complete:function(jqXHR, textStatus)
    	{
			
			if(textStatus==='success')
	        {
    	    	

			}           
		},
		timeout:60000
	});		
	}
}


function val_form1()
{
var ci=document.getElementById('frm_reg_ci').value;
var ci_error=valida_ci_ruc(ci);
var email=document.getElementById('frm_reg_email').value;
var fono=document.getElementById('frm_reg_fono').value;
var nombre=document.getElementById('frm_reg_descri').value;
var clave=document.getElementById('frm_reg_clave').value;



//+++++++++++++++
	
 if(ci_error!=0 )
 {
	document.getElementById('frm_reg_error').innerHTML='Cedula Incorrecta';
	document.getElementById('frm_reg_ci').focus();
	return false;
 }
 else
 {

	if(ci!=ci_tmp)
	{
	
	$.ajax({
		cache:false,
		url:'vrvalusrt.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{valor:ci,tipo:'cedula'}, 
    	beforeSend: function(jqXHR, textStatus)
		{
    	  document.getElementById('frm_reg_error').innerHTML='procesando.....';
	      document.body.style.cursor='wait';
	      document.getElementById('reg_btn').style.cursor='wait';
		  document.getElementById('reg_btn').style.background='#C1FFFF';
	      document.getElementById('reg_btn').disabled=true;
                
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
			errorx=dato;
		},
		error:function(jqXHR,textStatus,errorThrown )
		{
           if (jqXHR.status === 0) {
              document.getElementById('frm_reg_error').innerHTML='Sin conexion: Verifique Red.';
           } else if (jqXHR.status == 404) {
               document.getElementById('frm_reg_error').innerHTML='Respuesta pagina not encontrada [404]';
           } else if (jqXHR.status == 500) {
               document.getElementById('frm_reg_error').innerHTML='Internal Server Error [500].';
           } else if (exception === 'parsererror') {
               console.log('Requested JSON parse failed.');
           } else if (exception === 'timeout') {
               //console.log('Time out error.');
			   document.getElementById('frm_reg_error').innerHTML='Servidor no Responde';
           } else if (exception === 'abort') {
               console.log('Ajax request aborted.');
           } else {
               console.log('Uncaught Error: ' + jqXHR.responseText);
           }

		}, 
	    complete:function(jqXHR, textStatus)
    	{
			
			if(textStatus==='success')
	        {
    	    	

			}           
		},
		timeout:30000
	});
	
	if(errorx!='0')
	{
		document.body.style.cursor='auto';
		document.getElementById('reg_btn').style.cursor='pointer';
  		document.getElementById('reg_btn').disabled=false;
		document.getElementById('reg_btn').style.background='#09c';
		
		document.getElementById('frm_reg_error').innerHTML='CI Ya Existe';
		document.getElementById('frm_reg_ci').focus();
		return false;
	}
	else
	{
		document.getElementById('frm_reg_error').innerHTML='';
		ci_tmp=ci;
	}

 }
}


//++++++++++++

 
 var filtro_email=/[\w-\.]{3,}@([\w-]{2,}\.)*([\w-]{2,}\.)[\w-]{2,4}/;
 if(!filtro_email.test(email))
 {
	document.body.style.cursor='auto';
	document.getElementById('reg_btn').style.cursor='pointer';
	document.getElementById('reg_btn').disabled=false;
	document.getElementById('reg_btn').style.background='#09c';	
	 
	document.getElementById('frm_reg_error').innerHTML='Email Incorrecto';
	document.getElementById('frm_reg_email').focus();
	return false;
 }
 else
 {
	if(email!=email_tmp)
	{

	$('#frm_reg_error').html('');
	$.ajax({
		cache:false,
		url:'vrvalusrt.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{valor:email,tipo:'email'},
    	beforeSend: function(jqXHR, textStatus)
		{
    	  document.getElementById('frm_reg_error').innerHTML='procesando.....';
	      document.body.style.cursor='wait';
	      document.getElementById('reg_btn').style.cursor='wait';
		  document.getElementById('reg_btn').style.background='#C1FFFF';
	      document.getElementById('reg_btn').disabled=true;
                
		},
		success:function(dato, textStatus, jqXHR)
		{
			errorx=dato;
			
		},
		error:function(jqXHR,textStatus,errorThrown )
		{
           if (jqXHR.status === 0) {
              console.log('Not connect: Verify Network.');
           } else if (jqXHR.status == 404) {
               console.log('Requested page not found [404]');
           } else if (jqXHR.status == 500) {
               console.log('Internal Server Error [500].');
           } else if (exception === 'parsererror') {
               console.log('Requested JSON parse failed.');
           } else if (exception === 'timeout') {
               //console.log('Time out error.');
			   alert('Servidor no Responde');
           } else if (exception === 'abort') {
               console.log('Ajax request aborted.');
           } else {
               console.log('Uncaught Error: ' + jqXHR.responseText);
           }

		},
	    complete:function(jqXHR, textStatus)
    	{
			if(textStatus==='success')
	        {
    	    	
			}           
		},
		timeout:30000
		
	});
	
	if(errorx!='0')
	{

		document.body.style.cursor='auto';
		document.getElementById('reg_btn').style.cursor='pointer';
  		document.getElementById('reg_btn').disabled=false;
		document.getElementById('reg_btn').style.background='#09c';

		document.getElementById('frm_reg_error').innerHTML='Email Ya Existe';
		document.getElementById('frm_reg_email').focus();
		return false;
	}
 	else
 	{
 		document.getElementById('frm_reg_error').innerHTML='';
		email_tmp=email;
 	}
 }
 
}





//****


if(fono.length<5)
{
	document.body.style.cursor='auto';
	document.getElementById('reg_btn').style.cursor='pointer';
	document.getElementById('reg_btn').disabled=false;
	document.getElementById('reg_btn').style.background='#09c';	
	
	document.getElementById('frm_reg_error').innerHTML='Telefono Obligatorio';
	document.getElementById('frm_reg_fono').focus();
	return false;
}
else
{
	document.getElementById('frm_reg_error').innerHTML='';
}


if(nombre.length<5)
{
	document.body.style.cursor='auto';
	document.getElementById('reg_btn').style.cursor='pointer';
	document.getElementById('reg_btn').disabled=false;
	document.getElementById('reg_btn').style.background='#09c';	
	
	document.getElementById('frm_reg_error').innerHTML='Nombre Completo';
	document.getElementById('frm_reg_descri').focus();
	return false;
}
else
{
	document.getElementById('frm_reg_error').innerHTML='';
}

if(clave.length!=6)
{
	document.body.style.cursor='auto';
	document.getElementById('reg_btn').style.cursor='pointer';
	document.getElementById('reg_btn').disabled=false;
	document.getElementById('reg_btn').style.background='#09c';	
	
	document.getElementById('frm_reg_error').innerHTML='Clave debe ser de 6 Digitos';
	document.getElementById('frm_reg_clave').focus();
	return false;
}
else
{
	document.getElementById('frm_reg_error').innerHTML='';
}

if(clave!=document.getElementById('frm_reg_rclave').value)
{
	document.body.style.cursor='auto';
	document.getElementById('reg_btn').style.cursor='pointer';
	document.getElementById('reg_btn').disabled=false;
	document.getElementById('reg_btn').style.background='#09c';	
		
	document.getElementById('frm_reg_error').innerHTML='Claves no Coinciden';
	document.getElementById('frm_reg_rclave').focus();
	return false;
}
else
{
	document.getElementById('frm_reg_error').innerHTML='';
}

															

	
$.ajax({
	cache:false,
	url:'correo.php',
	datatype: "text",
    async:false,
	type:'POST',
	data:{nombre:nombre,email:email,cedula:ci,clave:clave,fono:fono},
   	beforeSend: function(jqXHR, textStatus)
	{
		document.getElementById('frm_reg_error').innerHTML='procesando.....';
		document.body.style.cursor='wait';
		document.getElementById('reg_btn').style.cursor='wait';
		document.getElementById('reg_btn').style.background='#C1FFFF';
		document.getElementById('reg_btn').disabled=true;
    },
	success:function(dato)
	{

		document.getElementById('frm_reg_error').innerHTML=dato;
		
	},
	error:function(jqXHR,textStatus,errorThrown )
	{
           if (jqXHR.status === 0) {
              console.log('Not connect: Verify Network.');
           } else if (jqXHR.status == 404) {
               console.log('Requested page not found [404]');
           } else if (jqXHR.status == 500) {
               console.log('Internal Server Error [500].');
           } else if (exception === 'parsererror') {
               console.log('Requested JSON parse failed.');
           } else if (exception === 'timeout') {
               //console.log('Time out error.');
			   alert('Servidor no Responde');
           } else if (exception === 'abort') {
               console.log('Ajax request aborted.');
           } else {
               console.log('Uncaught Error: ' + jqXHR.responseText);
           }

	},
	complete:function(jqXHR, textStatus)
    {
		if(textStatus==='success')
	    {
			document.getElementById('frm_reg_ci').value='';
			document.getElementById('frm_reg_email').value='';
			document.getElementById('frm_reg_descri').value='';
			document.getElementById('frm_reg_fono').value='';
		    document.getElementById('frm_reg_clave').value='';
     		document.getElementById('frm_reg_rclave').value='';
			
			document.body.style.cursor='auto';
			document.getElementById('reg_btn').style.cursor='pointer';
			document.getElementById('reg_btn').style.background='#09c';
    	  	document.getElementById('reg_btn').disabled=false;
			errorx=99;
			ci_tmp='';
			semail_tmp='';

		}
	},
	timeout:30000

});								
								
}



</script>
<style type="text/css">
body{ margin:0px; padding:0px;}
</style>
</head>

<body>
<div align="right"><a href="ces.php"><img src="http://vcrxol.com/_img/carrito.png" /></a></div>
<?php
require('../cfg/res.php');
$item_sql='select *,LEFT(item_codigo,6)as codigo from item0 where item_carr="1"  GROUP BY codigo';
//echo $item_sql;
$item_res=mysql_query($item_sql,$link_vcrx);?>
<div>
<table border="0" cellpadding="4" cellspacing="0" style="border-collapse:collapse;">

<?php
while($item_r=mysql_fetch_assoc($item_res)){?>
<tr valign="top" style="border-bottom: #CCC solid 1px;">
<td  style="">
<?php 
//$img_sql='select *from imgi0 where imgi_item="'.$item_r['item_codigo'].'" and imgi_status!="X" order by imgi_defa desc';
$img_sql='select *from imgi0 where left(imgi_item,6)="'.$item_r['codigo'].'" and imgi_status!="X" order by imgi_defa desc';
//echo $img_sql;
$img_res=mysql_query($img_sql,$link_vcrx);
if(mysql_num_rows($img_res)!=0){
while($img_r=mysql_fetch_assoc($img_res)){?>
		<?php if(file_exists('../imgi/'.$img_r['imgi_file'])){?> <div style="padding-bottom:5px;"><img src="../imgi/<?php echo $img_r['imgi_file'];?>" width="100" id="<?php echo $img_r['imgi_file'];?>"  onmouseover="_imagen('img_<?php echo $item_r['codigo'];?>',this.id);"  /></div><?php } ?>
<?php } }?>
</td>
<td >
<?php if(mysql_num_rows($img_res)!=0){
	if(file_exists('../imgi/'.mysql_result($img_res,0,'imgi_file'))){?> 
	<img src="../imgi/<?php echo mysql_result($img_res,0,'imgi_file');?>" width="300"  id="img_<?php echo $item_r['codigo'];?>" />
	<?php  } } ?>
</td>

<td>
<div align="center"><?php echo $item_r['item_descri'].' ('.$item_r['codigo'].')';?></div>
<div>
<?php 
// 	$talla_sql='select RIGHT(item_codigo,2)as talla from item0 where item_codigo like "'.$item_r['codigo'].'%" and LENGTH(item_codigo)=8';
	$talla_sql='select *, RIGHT(item_codigo,2)as talla from item0 where item_codigo like "'.$item_r['codigo'].'%" and LENGTH(item_codigo)=8';
	$talla_res=mysql_query($talla_sql,$link_vcrx); 
?>
<table><tr>
<?php while($talla_r=mysql_fetch_assoc($talla_res)){?>
	<td>
	<div>
		<?php //echo $talla_r['talla']; ?>
		<?php echo substr($talla_r['item_codigov'],6,3); ?>
	</div>
	<div>
		<input type="radio" name="talla_<?php echo $item_r['codigo'];?>" value="<?php echo $item_r['codigo'].$talla_r['talla']; ?>" class="talla_<?php echo $item_r['codigo'];?>"  />
		<?php //$pname="talla_".$item_r['codigo']; $pidtxt=$item_r['codigo'].$talla_r['talla']; $pcaption=substr($talla_r['item_codigov'],6,3); include('vrradio.php'); ?>	
	</div>
	</td>
<?php } ?>
</tr></table>
</div>
<div><input type="button" value="Agregar Carrito" id="talla_<?php echo $item_r['codigo'];?>" onclick="_carro(this.id);" /></div>
<div id="talla_<?php echo $item_r['codigo'];?>_error" class="talla_error" ></div>
</td>
</tr>
<?php } ?>
</table>
</div>



<div id="frm_contenedor" style="position: fixed; z-index:1; top:0px; left:0px; right:0px; bottom:0px;  background:#CCC;">

	<div id="frm_login" align="center" style=" padding-top:50px;">
    <div id="frm_cerrar" align="right" style="padding-right:50px;"><input type="button" value="Cerrar" onclick="document.getElementById('frm_contenedor').style.display='none';" /></div>
	<table>
	<tr>
	<td><label for="edula" style="font-weight:bolder;">e-mail/cedula</label></td>
	<td><label for="clave"  style="font-weight:bolder;">clave</label></td>
	<td></td>
	</tr>
	<tr>
	<td><input type="txt_ci" id="txt_ci" name="txt_ci" size="25" class="frm_ingreso_txt" placeholder="CI/RUC" autocomplete="off" onKeyPress="usuario(event,this);"/></td>
	<td><input type="password" id="txt_clave" name="txt_clave" size="25"  class="frm_ingreso_txt" placeholder="Clave" onKeyPress="clave(event);"/></td>
	<td><input type="button" value="Iniciar sesion" id="boton" onClick="valida_ci_ingreso();" style="background:#09c; border:solid 1px #039; font-size:12px; font-weight:bolder; padding:3px;" /></td>
	</tr>
	<tr>
	<td></td>
	<td><a href="../pas.php" style="color:#09c; font-weight:bolder;">Olvido su Clave?</a></td>
	<td></td>
	</tr>
	<tr>
	<td></td>
	<td colspan="2"><div id="error"></div></td>
	</tr>
	</table>
	</div>
	
    <div align="center" id="frm_contenedor2">
	<div>Si no tienes una cuenta</div>
	<div><h1 style="margin:0px; padding:0px;">REGÍSTRATE</h1></div>
	<div class="frm_reg_lbl">Cedula</div>
	<input type="text" id="frm_reg_ci" class="frm_reg" placeholder="Cedula" maxlength="13"  style="border-radius:4px; padding:4px;"/>
	<div class="frm_reg_lbl">Email</div>
	<input type="text" id="frm_reg_email" class="frm_reg" placeholder="Email" maxlength="40"   style="border-radius:4px; padding:4px;"/>
	<div class="frm_reg_lbl">Telefono</div>
	<input type="text" id="frm_reg_fono" class="frm_reg" placeholder="Telefono" maxlength="14"   style="border-radius:4px; padding:4px;"/>
	<div class="frm_reg_lbl">Nombres</div>
	<input type="text" id="frm_reg_descri" class="frm_reg" placeholder="Nombre Completo" maxlength="50"   style="border-radius:4px; padding:4px;"/>
	<div class="frm_reg_lbl">Clave</div>
	<input type="password" id="frm_reg_clave" class="frm_reg" placeholder="Clave" maxlength="6"   style="border-radius:4px; padding:4px; font-family:'Comic Sans MS', cursive;"/>
	<div class="frm_reg_lbl">Repita Clave</div>
	<input type="password" id="frm_reg_rclave" class="frm_reg" placeholder="Repita Clave" maxlength="6"   style="border-radius:4px; padding:4px; font-family:'Comic Sans MS', cursive;"/>
	</div>

	<div align="center" style="margin-top:5px;"><input type="button" onClick="val_form1();" value="Termina de Registrarte!" id="reg_btn" style="border-radius:4px; padding:4px; font-size:16px; font-weight:bolder; font-family: Arial, Helvetica, sans-serif; background:#063; " /></div>
	<div align="center" id="frm_reg_error" style="word-wrap:break-word; min-height:30px; color:#F00;"></div>
</div>



</body>
</html>