function openSearchSimple(sKeyName,sShow,sSearchFamilia,sFilter,sPage) {
	var sSearchString;
	var sLocationHref;

	sSearchString = getObj(sKeyName).value;
	sLocationHref = 'busquedasimple.php?show='+sShow+'&searchfamilia='+sSearchFamilia+'&searchstring='+sSearchString+'&searchprod=N/A&filter='+sFilter+'&desde='+sPage
	window.location = sLocationHref;
	return true;
}

function openSearchSimple2(sKeyName,sShow,sSearchFamilia,sFilter,sPage) {
	var sSearchString;
	var sLocationHref;

	sSearchString = getObj(sKeyName).value;
	sLocationHref = 'busquedasimple2.php?show='+sShow+'&searchfamilia='+sSearchFamilia+'&searchstring=N/A&searchprod='+sSearchString+'&filter='+sFilter+'&desde='+sPage
	window.location = sLocationHref;
	return true;
}

function openSearchComplex() {
	window.location = 'busquedacomplex.php?desde=-1';
	return true;
}

function countProducts() {
	var pCant = 0;
	var data = "";

	//Load Exist Data From Cookie
	var oRow , oCell;
	var sValue , vValue , tValue;
	vValue =getCookie("XPMetadoc")
	data = "";
	//Count
	if ( vValue != undefined ) {
		tValue = vValue.split(";");
		sValue = tValue[0].split("|");

		for ( var i=0 ; i<sValue.length-1 ; i++ ) {
			data = data + sValue[i] + "|";
			i++
			data = data + sValue[i] + "|";
			i++
			data = data + sValue[i] + "|";
			i++
			data = data + sValue[i] + "|";
			i++
			data = data + sValue[i] + "|";
			pCant++
		}
	}
	//Add Products
	var cells = tCesta.cells;
	for ( var i=0 ; i<cells.length ; i++ ) {
		if ( cells[i].id == "lblProductos" ) {
			cells[i].innerHTML = pCant + " Productos";
		}
	}
}

function getCookie(special) {
	var cookieName = (special + "=");
	var i = 0;
	while (i < document.cookie.length) {
		var j = i + cookieName.length;
        	if (document.cookie.substring(i,j) == cookieName) return getCookieValue(j);
	        i = document.cookie.indexOf(" ", i) + 1;
	        if (i == 0) break;
	}
}

function getCookieValue(offset) {
	var endString = document.cookie.indexOf (";", offset);
	if (endString) endString = document.cookie.length;
	return unescape(document.cookie.substring(offset, endString));
}

function payOrder() {
	getObj('payform').submit();
}

function Delete(idReg) {
	getObj('emode').value = 'delete';
	getObj('idReg').value = idReg;
	getObj('editform').submit();
}

function Recalculate() {
	var x=0;
	getObj('bprice').value = getObj('cboarticulo').options[getObj('cboarticulo').selectedIndex].label;
	getObj('btotal').value = getObj('bprice').value * getObj('bqty').value;
	getObj('bdescripcion').value = getObj('cboarticulo').options[getObj('cboarticulo').selectedIndex].text;
}

function validForm(msgOK,msgFAIL) {
	if (getObj('cboarticulo').options[getObj('cboarticulo').selectedIndex].value == '0') {
		alert(msgFAIL);
		return;
	} else {
		alert(msgOK);
		getObj('buyform').submit();
		return;
	}
	getObj('buyform').submit();
}

function printForm() {
	window.open('print.php?ReportId='+item+'&Tipo=','','toolbar=0,location=0,directories=0,status=-1,menubar=0,scrollbars=Auto');
	return true;
}

function openPedidos(iPedidoId) {
	window.location = 'pedidosdetalles.php?PedidoId='+iPedidoId;
	return true;
}

function openItem(itemId,vistaId) {
	if (vistaId == 0) {
		window.open('pop_articulo.php?ItemId='+itemId,'','width=500,height=355,status=no,resizable=yes,scrollbars=yes');
	} else {
		window.location = 'articulo.php?ItemId='+itemId;
	}
}

