function setPaymentInfo(isChecked)
{
	with (window.document.frmCheckout) {
		if (isChecked) {
			txtShippingFirstName.value  = txtPaymentFirstName.value;
			txtShippingLastName.value   = txtPaymentLastName.value;			
			txtShippingAddress1.value   = txtPaymentAddress1.value;
			txtShippingAddress2.value   = txtPaymentAddress2.value;
			txtShippingPhone.value      = txtPaymentPhone.value;
			txtShippingState.value      = txtPaymentState.value;			
			txtShippingCity.value       = txtPaymentCity.value;
			txtShippingPostalCode.value = txtPaymentPostalCode.value;
			
			txtShippingFirstName.readOnly  = true;
			txtShippingLastName.readOnly   = true;
			txtShippingAddress1.readOnly   = true;
			txtShippingAddress2.readOnly   = true;
			txtShippingPhone.readOnly      = true;
			txtShippingState.readOnly      = true;			
			txtShippingCity.readOnly       = true;
			txtShippingPostalCode.readOnly = true;			
		} else {
			txtShippingFirstName.readOnly  = false;
			txtShippingLastName.readOnly   = false;
			txtShippingAddress1.readOnly   = false;
			txtShippingAddress2.readOnly   = false;
			txtShippingPhone.readOnly      = false;
			txtShippingState.readOnly      = false;			
			txtShippingCity.readOnly       = false;
			txtShippingPostalCode.readOnly = false;			
		}
	}
}

function confirmar()
{
	with (window.document.frmCheckout) {
		if (acepto.checked == false) {
    		alert("Confirmar Condiciones");
			return;
		} else if (txtShippingFirstName.value == '') {
			alert('Introducir Nombre');
			return;
		} else if (txtShippingLastName.value == '') {
			alert('Introducir Apellido');
			return;
		} else if (txtShippingAddress1.value == '') {
			alert('Introducir dirección');
			return;
		} else if (txtShippingPhone.value == '') {
			alert('Introducir número de teléfono');
			return;
		} else if (txtShippingState.value == '') {
			alert('Introducir provincia');
			return;
		} else if (txtShippingCity.value == '') {
			alert('Introducir ciudad');
			return;
		} else if (txtShippingPostalCode.value == '') {
			alert('Introducir código postal');
			return;
		} else {
			if (chkFac.checked == true) {
    			var chkFact = 'si';
			}else{
				var chkFact = 'no';
			}
			if (optCod.checked == true) {
    			var pay = optCod.value;
			}else if(optCrb.checked == true) {
    			var pay = optCrb.value;
			}else if(optPaypal.checked == true){
				var pay = optPaypal.value;
			}else{
				var pay = optTpv.value;
			}
			SWFAddress.setValue('/confirmar/?pay='+pay+'&txtShippingFirstName='+txtShippingFirstName.value+'&txtShippingLastName='+txtShippingLastName.value+'&txtShippingPhone='+txtShippingPhone.value+'&txtShippingState='+txtShippingState.value+'&txtShippingCity='+txtShippingCity.value+'&txtShippingPostalCode='+txtShippingPostalCode.value+'&txtShippingAddress1='+txtShippingAddress1.value+'&txtShippingAddress2='+txtShippingAddress2.value+'&obser='+obser.value+'&chkFac='+chkFact);
		}
	}
}

function checkFormCambios()
{
	with (window.document.frmCheckout) {
		if (txtShippingFirstName.value == '') {
			alert('Introducir Nombre');
			return;
		} else if (txtShippingLastName.value == '') {
			alert('Introducir Apellido');
			return;
		} else if (txtShippingNif.value == '') {
			alert('Introducir DNI / NIF');
			return;
		} else if (txtShippingAddress1.value == '') {
			alert('Introducir dirección');
			return;
		} else if (txtShippingPhone.value == '') {
			alert('Introducir número de teléfono');
			return;
		} else if (txtShippingState.value == '') {
			alert('Introducir provincia');
			return;
		} else if (txtShippingCity.value == '') {
			alert('Introducir ciudad');
			return;
		} else if (txtShippingPostalCode.value == '') {
			alert('Introducir código postal');
			return;
		} else {
			cambio(txtShippingFirstName.value,txtShippingLastName.value,txtShippingNif.value,txtShippingPhone.value,txtShippingState.value,txtShippingCity.value,txtShippingPostalCode.value,txtShippingAddress1.value,txtShippingAddress2.value,txtShippingQuestion.value);
		}
	}
}

function cambio(txtShippingFirstName,txtShippingLastName,txtShippingNif,txtShippingPhone,txtShippingState,txtShippingCity,txtShippingPostalCode,txtShippingAddress1,txtShippingAddress2,txtShippingQuestion) {


    var xhr = getTransport_cuenta();
    xhr.onreadystatechange = function() {
        updateChange_cuenta(xhr);
    }

	xhr.open('post', 'datasource/cambio.php', true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    xhr.send('txtShippingFirstName='+txtShippingFirstName+'&txtShippingLastName='+txtShippingLastName+'&txtShippingNif='+txtShippingNif+'&txtShippingPhone='+txtShippingPhone+'&txtShippingState='+txtShippingState+'&txtShippingCity='+txtShippingCity+'&txtShippingPostalCode='+txtShippingPostalCode+'&txtShippingAddress1='+txtShippingAddress1+'&txtShippingAddress2='+txtShippingAddress2+'&txtShippingQuestion='+txtShippingQuestion);
 
}


function checkFormCuenta()
{
	with (window.document.frmCheckout) {
		if (txtShippingEmail.value == '') {
			alert('Introducir Email');
			return;
		} else if (txtPassword.value == '') {
			alert('Escriba la contraseña');
			return;
		} else if (txtRePassword.value == '') {
			alert('Reescriba la contraseña');
			return;
		} else if (txtShippingFirstName.value == '') {
			alert('Introducir Nombre');
			return;
		} else if (txtShippingLastName.value == '') {
			alert('Introducir Apellido');
			return;
		} else if (txtShippingNif.value == '') {
			alert('Introducir DNI / NIF');
			return;
		} else if (txtShippingAddress1.value == '') {
			alert('Introducir dirección');
			return;
		} else if (txtShippingPhone.value == '') {
			alert('Introducir número de teléfono');
			return;
		} else if (txtShippingState.value == '') {
			alert('Introducir provincia');
			return;
		} else if (txtShippingCity.value == '') {
			alert('Introducir ciudad');
			return;
		} else if (txtShippingPostalCode.value == '') {
			alert('Introducir código postal');
			return;
		} else if (txtShippingQuestion.value == '') {
			alert('Responder la pregunta. Donde nos ha conocido?');
			return;
		} else if (txtRePassword.value != txtPassword.value) {
			alert("Asegurese de que reescribio correctamente la contraseña");
			return;
		} else if (acepto.checked == false) {
    		alert("Confirmar Condiciones");
			return;
		} else {
			cuenta(txtShippingFirstName.value,txtShippingLastName.value,txtShippingNif.value,txtShippingPhone.value,txtShippingEmail.value,txtShippingState.value,txtShippingCity.value,txtShippingPostalCode.value,txtPassword.value,txtShippingAddress1.value,txtShippingAddress2.value,txtShippingQuestion.value);
		}
	}
}

function cuenta(txtShippingFirstName,txtShippingLastName,txtShippingNif,txtShippingPhone,txtShippingEmail,txtShippingState,txtShippingCity,txtShippingPostalCode,txtPassword,txtShippingAddress1,txtShippingAddress2,txtShippingQuestion) {


    var xhr = getTransport_cuenta();
    xhr.onreadystatechange = function() {
        updateChange_cuenta(xhr);
    }

	xhr.open('post', 'datasource/micuenta.php', true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    xhr.send('txtShippingFirstName='+txtShippingFirstName+'&txtShippingLastName='+txtShippingLastName+'&txtShippingNif='+txtShippingNif+'&txtShippingPhone='+txtShippingPhone+'&txtShippingEmail='+txtShippingEmail+'&txtShippingState='+txtShippingState+'&txtShippingCity='+txtShippingCity+'&txtShippingPostalCode='+txtShippingPostalCode+'&txtPassword='+txtPassword+'&txtShippingAddress1='+txtShippingAddress1+'&txtShippingAddress2='+txtShippingAddress2+'&txtShippingQuestion='+txtShippingQuestion);
 
}
             
function getTransport_cuenta() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        try {
        	return new ActiveXObject('Msxml2.XMLHTTP');
            } catch(e) {
            return new ActiveXObject('Microsoft.XMLHTTP');
    	}
    }
}

function updateContent_cuenta(html) {
                var content = document.getElementById('content');
                content.innerHTML = html;
                
                while (html.match(/(<script[^>]+javascript[^>]+>\s*(\/\/*<!\[CDATA\[)?(<!--)?\s*)/i)) {
                    html = html.substr(html.indexOf(RegExp.$1) + RegExp.$1.length);
                    if (!html.match(/((\/\/ *\]\]>)?(-->)?\s*<\/script>)/)) break;
                    block = html.substr(0, html.indexOf(RegExp.$1));
                    html = html.substring(block.length + RegExp.$1.length);
                    eval(block);
                }
}
            
function updateChange_cuenta(xhr) {	
    if (xhr.readyState != 4) {
		document.getElementById('content').innerHTML='<div align="center"><img src="imagenes/ajax-loader.gif" width="220" height="19" /></div>';
	}else{
        if (xhr.status == 200) {
            updateContent_cuenta(xhr.responseText);           
        } else {
            //alert('Error: ' + xhr.status + '!');
        }
    }
}