﻿
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 < 15) {
		alert ('Por favor, indicanos mas detalles sobre el producto que buscas');
		return false;
	}

	return true;
}

function SubmitProdStockEmailAlertForm() {
	if (CheckProdStockEmailAlertForm()) {
        document.getElementById('cmdSEAWait').style.display = '';
        document.getElementById('cmdSEASend').style.display = 'none';
        
        setTimeout("document.getElementById('frmProdStockEmailAlert').submit()", 100);
	}
}

function CheckProdStockEmailAlertForm() {
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.frmProdStockEmailAlert.txtSEAEmail.value)) || document.frmProdStockEmailAlert.txtSEAEmail.value.length < 6) {
		alert ('Por favor, introduce tu email correctamente');
		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; }
    if (document.getElementById('cboProdVariant_' + iProd)) { iProd = document.getElementById('cboProdVariant_' + iProd).options[document.getElementById('cboProdVariant_' + 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;
}

function shareInTwitter() {
    u = location.href;
    t = document.title;
    window.open('http://twitter.com/share?url='+encodeURIComponent(u)+'&text='+encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=625,height=435,left='+((screen.width-625)/2)+',top='+((screen.height-435)/2));
    return true;
}

function likeInFacebook(){
    document.write('<iframe src=')
    document.write(String.fromCharCode(34));
    document.write('http://www.facebook.com/plugins/like.php?href='+encodeURIComponent(location.href)+'&amp;layout=standard&amp;show_faces=false&amp;width=340&amp;action=like&amp;colorscheme=light&amp;height=35');
    document.write(String.fromCharCode(34));
    document.write(' ');
    document.write('scrolling='+String.fromCharCode(34)+'no'+String.fromCharCode(34));
    document.write(' ');
    document.write('frameborder='+String.fromCharCode(34)+'0'+String.fromCharCode(34));
    document.write(' ');
    document.write('style='+String.fromCharCode(34)+'border:none; overflow:hidden; width:250px; height:35px;'+String.fromCharCode(34));
    document.write(' ');
    document.write('allowTransparency='+String.fromCharCode(34)+'true'+String.fromCharCode(34)+'></iframe>');
}


function SubmitCouponForm() {
    if (document.frmCoupon.txtCouponID.value.length < 10) {
        alert('Por favor, introduce el número de cupón correctamente');
    }
    else {
        document.frmCoupon.action = '/cesta-compra.aspx?coupon=' + document.frmCoupon.txtCouponID.value;
        document.frmCoupon.submit();
    }
}

