﻿
function SearchSend() {
	if (document.frmSearch.search.value.length == 0) {
		alert ('Por favor, introduce lo que quieras buscar');
		document.frmSearch.search.focus();
	}
	else {
	    document.frmSearch.submit();
	}
}

function SubmitContactForm() {
	if (CheckContactForm()) {
        document.getElementById('cmdWait').style.display = '';
        document.getElementById('cmdSend').style.display = 'none';
        
        setTimeout("document.getElementById('frmContact').submit()", 100);
	}
}

function CheckContactForm() {
	if (document.frmContact.txtName.value.length < 4) {
		alert ('Por favor, introduce tu nombre y apellidos');
		return false;
	}
	
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.frmContact.txtEmail.value)) || document.frmContact.txtEmail.value.length < 6) {
		alert ('Por favor, introduce tu email correctamente');
		return false;
	}

	if (document.frmContact.txtMessage.value.length < 25) {
		alert ('Por favor, indicanos mas detalles sobre tu mensaje');
		return false;
	}

	return true;
}


function SubmitProductCheapForm() {
	if (CheckProductCheapForm()) {
        document.getElementById('cmdWait').style.display = '';
        document.getElementById('cmdSend').style.display = 'none';
        
        setTimeout("document.getElementById('frmContact').submit()", 100);
	}
}


function CheckProductCheapForm() {
	if (document.frmContact.txtName.value.length < 4) {
		alert ('Por favor, introduce el nombre de la tienda donde has visto el producto');
		return false;
	}
	
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.frmContact.txtEmail.value)) || document.frmContact.txtEmail.value.length < 6) {
		alert ('Por favor, introduce tu email correctamente');
		return false;
	}

	return true;
}


function ShowBrand(sLink) {
    document.location.href = sLink;
}

function ShowAnswerToProblem(sLink) {
    document.location.href = sLink;
}


function SubmitRequestAProductForm() {
	if (CheckRequestAProductForm()) {
        document.getElementById('cmdRAPWait').style.display = '';
        document.getElementById('cmdRAPSend').style.display = 'none';
        
        setTimeout("document.getElementById('frmRequestProduct').submit()", 100);
	}
}

function CheckRequestAProductForm() {
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.frmRequestProduct.txtRAPEmail.value)) || document.frmRequestProduct.txtRAPEmail.value.length < 6) {
		alert ('Por favor, introduce tu email correctamente');
		return false;
	}

	if (document.frmRequestProduct.txtRAPProduct.value.length < 5) {
		alert ('Por favor, indicanos mas detalles sobre el producto que buscas');
		return false;
	}

	return true;
}

function AddToBasket(iProd, iCat) {
    var iQty = 1;
    if (document.getElementById('cboProdQty_' + iProd)) { iQty = document.getElementById('cboProdQty_' + iProd).options[document.getElementById('cboProdQty_' + iProd).selectedIndex].value; }
    
    document.location.href = '/cesta-compra.aspx?a=1&prod=' + iProd + '&u=' + iQty + '&cat=' + iCat;
}


function BasketLegalCheck(oCheckBox) {
    if (oCheckBox) {
        if (oCheckBox.checked == true) {
            document.getElementById('cmdSend').style.display = '';
        }
        else {
            document.getElementById('cmdSend').style.display = 'none';
            alert ('Si no aceptas nuestras condiciones generales de compra no puedes realizar pedidos en nuestra web');
        }
    }
}


function CheckBasketConfirmFormData() {
	if (document.getElementById('txtCustomerName').value.length < 5) {
		alert ('Por favor, introduce tu nombre y apellidos correctamente');
		return false;
	}

	if (document.getElementById('txtCustomerAddress').value.length < 5) {
		alert ('Por favor, introduce tu direccion correctamente');
		return false;
	}

	if (document.getElementById('txtCustomerPostalCode').value.length < 4) {
		alert ('Por favor, introduce tu codigo postal correctamente');
		return false;
	}

	if (document.getElementById('txtCustomerCity').value.length < 3) {
		alert ('Por favor, introduce tu localidad correctamente');
		return false;
	}
	
	if (document.getElementById('cboProvince').value = 0) {
		alert ('Por favor, selecciona tu provincia correctamente');
		return false;
	}

	if (document.getElementById('txtCustomerTelephone').value.length < 9) {
		alert ('Por favor, introduce tu telefono correctamente');
		return false;
	}

	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('txtCustomerEmail').value)) || document.getElementById('txtCustomerEmail').value.length < 6) {
		alert ('Por favor, introduce tu email correctamente');
		return false;
	}


	return true;
}

function SendBasketConfirmForm() {
    document.getElementById('cmdWait').style.display = '';
    document.getElementById('cmdSend').style.display = 'none';
    
    CheckBasketConfirmForm()
}


function CheckBasketConfirmForm() {
    if (CheckBasketConfirmFormData()) {
        document.getElementById('frmSignin').submit() }
    else {
        document.getElementById('cmdWait').style.display = 'none';
        document.getElementById('cmdSend').style.display = '';
    }
}


function SubmitForumPostForm() {
	if (CheckForumPostForm()) {
        document.getElementById('cmdWait').style.display = '';
        document.getElementById('cmdSend').style.display = 'none';
        
        setTimeout("document.getElementById('frmForumPost').submit()", 100);
	}
}

function CheckForumPostForm() {
	if (document.frmForumPost.txtName.value.length < 3) {
		alert ('Por favor, introduce tu nombre o alias');
		return false;
	}

	if (document.frmForumPost.txtSubject.value.length < 5) {
		alert ('Por favor, amplia el asunto de tu mensaje');
		return false;
	}

	if (document.frmForumPost.txtMessage.value.length < 25) {
		alert ('Por favor, indicanos mas detalles sobre tu mensaje');
		return false;
	}

	return true;
}

function shareInFacebook() {
    u = location.href;
    t = document.title;
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=625,height=435,left='+((screen.width-625)/2)+',top='+((screen.height-435)/2));
    return true;
}
