/************************************************************************************
' Nombre	: submitOfertas()
' Descrip	: hace el submit para el carrito
'
' Depend	: paginArticulo.php
'
' Example	:
'************************************************************************************
' Historia	:OCM	@ 2003-10-27	*	Creacion
'************************************************************************************/
function submitOfertas(strName,artId){
	var theForm	  = eval("document." + strName + "");
	var theObj	  = eval("theForm.cant_" + artId + "");
	var theObjSubCat  = eval("theForm.ofersubcat_" + artId + "");
	canti = 0 ;
        aa = 0 ;
        if ( theObj.value != 0 ) {
		if ( ! isNaN(theObj.value) ) {
			theForm.selProds.value = theForm.selProds.value + artId + ",";
			theForm.selCants.value = theForm.selCants.value + theObj.value + ",";
			canti = 1 ;
		}
		else
		{
			alert("Debe especificar una cantidad valida");
			aa = 1 ;
			
		}
	}

	if (canti == 0) {
		if ( aa == 0) {
			alert("Debe especificar una cantidad del Articulo para Comprar");
			theObj.focus();
		}
	}
	else {
		theForm.selSubCate.value 	= theObjSubCat.value ;
		theForm.action 			= theForm.antes.value;
		theForm.submit();
		return true;
	}
	return false;
}

function validarContacto(strName){
	var theForm	= eval("document." + strName + "");
	var len		= theForm.elements.length;
	var strTmp1	= "Se detectaron errores en la carga de datos.\n\n";
	var strTmp3	= "";


	var iCant 	= 0 ;
	var bnlPase 	= 0 ;
	for(i=0;i<len;i++){
		if(theForm.elements[i].name.charAt(0) == "_") {
			if (theForm.elements[i].type == "text" && theForm.elements[i].value == ""){
		     		iCant ++;
		     		strTmp3 += theForm.elements[i].id + "\n";
		     		bnlPase = 1;
			}
			if (theForm.elements[i].type == "password" && theForm.elements[i].value == ""){
		     		iCant ++;
		     		strTmp3 += theForm.elements[i].id + "\n";
		     		bnlPase = 1;
			}
		}
	}

	var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
	if(!re.test(theForm._txtEmail1.value)&&(iCant==0)){
     		iCant ++;
     		strTmp3 += theForm._txtEmail1.id + "\n";
     		bnlPase = 1;
	}
	
	if(bnlPase==1){
		if(iCant>1){
			strTmp = strTmp1 + "Complete los sig. campos:\n\n" +  strTmp3; 
		}else{
			strTmp = strTmp1 + "Complete el sig. campo\n" +  strTmp3; 
		}
		alert(strTmp);
		return false;
	}else{
		theForm.submit();
		return true;
	}
}

/************************************************************************************
' Nombre	: submitCarritoDetalle()
' Descrip	: hace el submit para el detalle del carrito
'
' Depend	: paginArticulo.php
'
' Example	:
'************************************************************************************
' Historia	:OCM	@ 2003-10-27	*	Creacion
'************************************************************************************/

function submitCarritoDetalle(strName,strArticulo,orden){
	var theCanti	= eval("document." + strName + "." + strArticulo);
	if (theCanti.value == 0){theCanti.value = 1 ;}
	submitCarrito(strName, orden, 1);
}

/************************************************************************************
' Nombre	:checkOptionsJs()
' Descrip	:seleccionar todos o ninguno
'
' Depend	:
'
' Example	:
'************************************************************************************
' Historia	:OCM	@ 2003-09-17	*	Creacion
'************************************************************************************/
function checkOptionsJs(strName,bnlSelected){
	var theForm	= eval("document." + strName + "");
	var len		= theForm.elements.length;

	for(var i = 0 ; i < len ; i++) {
	    if ((theForm.elements[i].type == "checkbox" )) {
	    	theForm.elements[i].checked = bnlSelected ; 
	    }
	}
}

/************************************************************************************
' Nombre	:selectMultipleJs()
' Descrip	:seleccionar todos o ninguno
'
' Depend	:
'
' Example	:
'************************************************************************************
' Historia	:OCM	@ 2003-09-17	*	Creacion
'************************************************************************************/
function selectMultipleJs(strName,selName,bnlSelected) {
	var theForm	= eval("document." + strName + "");
	var len		= theForm.elements.length;

	for(i=0;i<len;i++){
		if ( (theForm.elements[i].type == "select-multiple") && (theForm.elements[i].name == selName) ){
			for(j = 0; j < theForm.elements[i].options.length; j++) {
				theForm.elements[i].options[j].selected = bnlSelected; 
			}
		}
	}
}

/************************************************************************************
' Nombre	: submitBusqueda()
' Descrip	: hace el submit para el submitBusqueda
'
' Depend	: loginbusq.php
'
' Example	:
'************************************************************************************
' Historia	:OCM	@ 2003-10-27	*	Creacion
'************************************************************************************/
function submitBusqueda(intNum,strName){
	var theForm	= eval("document." + strName + "");
	var iTam	= 2 ;
	var len		= theForm.elements.length;
	var strTmp	= "";

	
	if (theForm.buscarElemento.value.length < iTam){
		if (theForm.buscarElemento.value.length == 0){
			alert("\n Debe ingresar alguna palabra.");
		}else{
			alert("\n Debe ingresar una palabra \n(Tamaņo Minimo " + iTam + " caracteres) ");
		}
		theForm.buscarElemento.focus();
	}else{
		theForm.submit();
	}
}
/************************************************************************************
' Nombre	: submitLogin()
' Descrip	: hace el submit para el submitLogin
'
' Depend	: loginbusq.php
'
' Example	:
'************************************************************************************
' Historia	:OCM	@ 2003-10-27	*	Creacion
'************************************************************************************/
function submitLogin(strName){
	var theForm	= eval("document." + strName + "");
	var len = theForm.elements.length;
	
	if (theForm.txtUserName.value.length == 0){
		alert("\n Debe ingresar algun usuario.");
		theForm.txtUserName.focus();
	}else{
		if (theForm.txtPassword.value.length == 0){
			alert("\n Debe ingresar la clave del usuario.");
			theForm.txtPassword.focus();
		}else{
			theForm.submit();
		}
	}


}

/************************************************************************************
' Nombre	: submitCarritoPedido()
' Descrip	: hace el submit para el carrito
'
' Depend	: paginArticulo.php
'
' Example	:
'************************************************************************************
' Historia	:OCM	@ 2003-10-27	*	Creacion
'************************************************************************************/

function submitCarritoPedido(strName){
	var theForm	= eval("document." + strName + "");

	var len		= theForm.elements.length;
	var strTmp	= "";
	var iValorCombo = 0;
	
	vara = 0 ;
	canti = 0 ;
	aa = 0 ;

	for(var i = 0 ; i < len ; i++) {
	    valstr = theForm.elements[i].name ;
	    vallen = theForm.elements[i].name.length ;
	    if ((valstr.indexOf("cant_") == 0 ) && (theForm.elements[i].value != 0 )) {
		if ( ! isNaN(theForm.elements[i].value) ) {
			if(vara == 0){
				theForm.selCate.value = "" ;
				theForm.selSubCate.value = "" ;
				vara = 1 ;
			}
			Producto 		= valstr.substring(5,vallen) ; 
			pos1 				= Producto.indexOf("_") ;
			IdProd			= Producto.substr(0,pos1) ;
			vallen 			= Producto.length ;
			Categoria		= Producto.substring(pos1+1,vallen) ;
			pos1 				= Categoria.indexOf("_") ;
			IdCate			= Categoria.substr(0,pos1) ;
			vallen			= Categoria.length ;
			IdSubCate		= Categoria.substring(pos1+1,vallen) ;
			var theObj	= eval("theForm.ant_" + IdProd + "_" + IdCate + "_" + IdSubCate );
			if ( theForm.elements[i].value != theObj.value ) {

				var theSel1	= eval("theForm.selMedida_" + IdProd + "");
				var theSel2	= eval("theForm.selSabor_" + IdProd + "");	
				
				iValSabor = 0 ;
				if (theSel1 != undefined) iValSabor = theSel1[theSel1.selectedIndex].value;
				if (theSel2 != undefined) iValSabor = theSel2[theSel2.selectedIndex].value;

				theForm.selCate.value = theForm.selCate.value + IdCate + ",";
				theForm.selSubCate.value = theForm.selSubCate.value + IdSubCate + ",";
				theForm.selProds.value = theForm.selProds.value + IdProd + ",";
				theForm.selSabor.value = theForm.selSabor.value + iValSabor + ",";
				theForm.selCants.value = theForm.selCants.value + theForm.elements[i].value + ",";
				canti = canti + 1 ;
			}else{
				aa = 1 ;
			}
		}
		else
		{
			alert("Debe especificar una cantidad valida");
			aa = 1 ;
			
		}
	    }

	}

	if (canti == 0) {
		if ( aa == 0) {
			alert("Debe especificar una cantidad distinta a la actual para Actualizar");
		}
	}
	else {
		theForm.action 		= theForm.actualiza.value;
		theForm.submit();
	}
}

/************************************************************************************
' Nombre	: submitCarrito()
' Descrip	: hace el submit para el carrito
'
' Depend	: paginArticulo.php
'
' Example	:
'************************************************************************************
' Historia	:OCM	@ 2003-10-27	*	Creacion
'************************************************************************************/
function submitCarrito(strName,inicio,prods){
	var theForm			= eval("document." + strName + "");
	var len					= theForm.elements.length;
	var strTmp			= "";
	var iValorCombo = 0;
	vara 		= 0 ;
	canti 	= 0 ;
	aa 			= 0 ;
	if ( inicio != 0 ){len = prods ;}
	for(var i = inicio ; i < inicio+len ; i++) {
	    valstr = theForm.elements[i].name ;
	    vallen = theForm.elements[i].name.length ;
	    if ((valstr.indexOf("cant_") == 0 ) && (theForm.elements[i].value != 0 )) {
				if ( ! isNaN(theForm.elements[i].value) ) {
					if(vara == 0){
						theForm.selCate.value = "" ;
						theForm.selSubCate.value = "" ;
						vara = 1 ;
					}
				  Producto 	= valstr.substring(5,vallen) ; 
				  pos1 			= Producto.indexOf("_") ;
					IdProd		= Producto.substr(0,pos1) ;
			    vallen 		= Producto.length ;
				  Categoria	= Producto.substring(pos1+1,vallen) ;		  	 
				  pos1 			= Categoria.indexOf("_") ;
					IdCate		= Categoria.substr(0,pos1) ;
					vallen		= Categoria.length ;
					IdSubCate	= Categoria.substring(pos1+1,vallen) ;
					var theSel1	= eval("theForm.selMedida_" + IdProd + "");
					var theSel2	= eval("theForm.selSabor_" + IdProd + "");	
					iValSabor = 0 ;
					if (theSel1 != undefined) iValSabor = theSel1[theSel1.selectedIndex].value;
					if (theSel2 != undefined) iValSabor = theSel2[theSel2.selectedIndex].value;
					theForm.selSabor.value = theForm.selSabor.value + iValSabor + ",";
					theForm.selCate.value = theForm.selCate.value + IdCate + ",";
					theForm.selSubCate.value = theForm.selSubCate.value + IdSubCate + ",";
					theForm.selProds.value = theForm.selProds.value + IdProd + ",";
					theForm.selCants.value = theForm.selCants.value + theForm.elements[i].value + ",";
					canti = canti + 1 ;
				}else{
					alert("Debe especificar una cantidad valida");
					aa = 1 ;
				}
	    }
	}//for

	if (canti == 0) {
		if ( aa == 0) {
			alert("Debe especificar una cantidad de los Articulos para Comprar");
		}
	}else{
		//theForm.action 		= theForm.antes.value;
		theForm.submit();
	}
}
/************************************************************************************
' Nombre	: submitDelPedido()
' Descrip	: hace el submit para el borrado de elementos del pedido
'
' Depend	: pedido.php
'
' Example	:
'************************************************************************************
' Historia	:OCM	@ 2003-10-27	*	Creacion
'************************************************************************************/
function submitDelPedido(strName,tipo){
	var theForm	= eval("document." + strName + "");
	var len		= theForm.elements.length;
	vara = 0 ;	
	canti = 0 ;
	
	if (tipo == "ALL") { 
		if (confirm("Confirma Vaciar el Contenido de su Pedido ?") ) {
			theForm.tipoDel.value = "ALL" ;
			theForm.action 		= theForm.antes.value;
			theForm.submit();
		}
	}else{
		for(var i = 0 ; i < len ; i++) {
		    if ((theForm.elements[i].type == "checkbox" ) && (theForm.elements[i].checked)) {
		    	valstr = theForm.elements[i].name ;
		    	vallen = theForm.elements[i].name.length ;
			if(vara == 0){
				theForm.selCate.value = "" ;
				theForm.selSubCate.value = "" ;
				vara = 1 ;
			}
		    	Producto 	= valstr.substring(6,vallen) ; 
		    	pos1 		= Producto.indexOf("_") ;
			IdProd		= Producto.substr(0,pos1) ;
	    		vallen 		= Producto.length ;
			//alert (Producto);alert (pos1);alert (IdProd);
		    	Categoria	= Producto.substring(pos1+1,vallen) ;
		    	 
		    	pos1 		= Categoria.indexOf("_") ;
			IdCate		= Categoria.substr(0,pos1) ;
			vallen		= Categoria.length ;
			IdSubCate	= Categoria.substring(pos1+1,vallen) ;
			//alert ("cate:" + Categoria);alert (pos1);alert (IdCate);alert (IdSubCate);
	
			theForm.selCate.value = theForm.selCate.value + IdCate + ",";
			theForm.selSubCate.value = theForm.selSubCate.value + IdSubCate + ",";
			theForm.selProds.value = theForm.selProds.value + IdProd + ",";
	
			canti = canti + 1 ;
		    }
		}
		if (canti == 0) {
			alert("Debe seleccionar un articulo a Eliminar");
		}
		else {
			if (confirm("Confirma Eliminar los Articulos Seleccionados ?") ) {
				theForm.tipoDel.value = "ONE" ;			
				theForm.action 		= theForm.antes.value;
				theForm.submit();
			}else{
				theForm.selCate.value = "" ;
				theForm.selSubCate.value = "" ;
				theForm.selProds.value = "" ;
			}
		}
	}
}


/************************************************************************************
' Nombre	: categoria()
' Descrip	: hace el submit para la categoria
'
' Depend	: categorias.php
'
' Example	:
'************************************************************************************
' Historia	:OCM	@ 2003-10-27	*	Creacion
'************************************************************************************/
function categoria(intNum,strName){
	var theForm	= eval("document." + strName + "");
	theForm.submit();
}

/************************************************************************************
' Nombre	: subCategoria()
' Descrip	: hace el submit para la subCategoria
'
' Depend	: categorias.php
'
' Example	:
'************************************************************************************
' Historia	:OCM	@ 2003-10-27	*	Creacion
'************************************************************************************/
function subCategoria(intNum,strName){
	var theForm	= eval("document." + strName + "");
	theForm.submit();
}

/************************************************************************************
' Nombre	: submitPage()
' Descrip	: hace el submit para la subCategoria
'
' Depend	: categorias.php
'
' Example	:
'************************************************************************************
' Historia	:OCM	@ 2003-10-27	*	Creacion
'************************************************************************************/
function submitPage(strName){
	var theForm	= eval("document." + strName + "");
	theForm.submit();
}


/*************



***************/
function isOk(intNum){
	if(isValidar(intNum)){
		alert("Submit!!!");	
	}else{
		alert("Error");	
	}
}


function ver(intNum,strName){
	//var theForm	= eval("document." + strName + "");
	//var theForm	= document.forms[intNum];
	
	var theForm	= eval("document." + strName + "");
	var len		= theForm.elements.length;
	var strTmp	= "";
	
	for(i=0;i<len;i++){
	strTmp +="\n Name => " + theForm.elements[i].name + " Type => " + theForm.elements[i].type + " Value => " + theForm.elements[i].value + " Id => " + theForm.elements[i].id + " Nro => " + i;
	}
	alert(strTmp);
}


function submitBusqXMarca(intNum,strName){
	var theForm	= eval("document." + strName + "");
	//var theForm	= document.forms[intNum];

	var iTam	= 2 ;
	var len		= theForm.elements.length;
	var strTmp	= "";

	//alert("\n buscar => " + theForm.buscarElemento.value.length );
	
	if (theForm.busquedaXMarca.value.length < iTam){
		if (theForm.busquedaXMarca.value.length == 0){
			alert("\n Debe ingresar alguna palabra.");
		}else{
			alert("\n Debe ingresar una palabra \n(Tamaņo Minimo " + iTam + " caracteres) ");
		}
		theForm.busquedaXMarca.focus();
	}else{
		//alert("\n submit.");
		theForm.submit();
	}


}
function VerChecks(strName) {
	var varchecks = "";
	
	var theForm	  = eval("document." + strName + "");
	len = theForm.elements.length;
	var theCanti = 0 ;

	for(var i = 0 ; i < len ; i++) {
	    if ((theForm.elements[i].name == "checkListaPrecios") && (theForm.elements[i].checked)) {
				theCanti	= eval("theForm."+theForm.elements[i].value+".value");
				if((theCanti=="")||(theCanti=="0")){
					theCanti = 1 ;
				}
				varchecks += theForm.elements[i].value + ":" + theCanti + ",";
	    }
	}
	return varchecks;
}

function OneChecked(strFormName) {
	var theForm	  = eval("document." + strFormName + "");
	len = theForm.elements.length;
	var a = "" ;
	
	for(var i = 0 ; i < len ; i++) {
		if ((theForm.elements[i].name == "checkListaPrecios") && (theForm.elements[i].checked == true)) {
			return(true);
		}
	}
	return(false);
}

function AlquilarVarios(direccion,strFormName){
	var theForm	  = eval("document." + strFormName + "");
	if(OneChecked(strFormName)==false) {
		alert("Debe seleccionar al menos un registro");
		return (false);
	}else{
		strValor = VerChecks(strFormName);
		if(strValor.length>0)strValor = strValor.substring(0,strValor.length-1);
		//
		theForm.varchecks.value = strValor ;
		theForm.submit();
	}
	return true;
}


