function setStyle() {
	$('input[@type=text]').css({ color: "#000000", background: "#FFFFFF", border: "1px solid #666666" });	
}

function setStyle1() {
	$('input[@type=text]').css({ color: "#000000", background: "#FFFFFF", border: "1px solid #666666", padding: "3px" });	
}

function getApartment() {	
	var divMsg = $('#divApartment');
	var reqURL = "query/apartment.php";
	
	$.ajax({
		   type: "GET",
		   url: reqURL,
		   data: "g_ran=" + Math.random(),	

		   success: function(msg){			   
			   divMsg.html(msg);
		   }
	});
}

function getPrice() {
	var valPriceApartment = parseInt($.trim($('#slcApartment').val()));
	var valDays = parseInt($.trim($('#txtDays').val()));
	
	$('#txtPrice').val('');
	indexSlc = document.getElementById('slcApartment').selectedIndex;
	valPriceApartment = parseInt(document.getElementById('slcApartment').options[indexSlc].title);
	
	if(valDays && valPriceApartment) {
		var valPrice = valPriceApartment*valDays;
		$('#txtPrice').val(valPrice);
	}
}

function sendData() {	
	if(valFecha('txtDate')){
		if(checkMail('txtMail')) {
			if(valFecha('txtEdate')) {
				if($.trim($('#txtCard').val()) != '' && $.trim($('#txtCard').val()).length == 16){
					if(checkForm()) {
						$('#frmApartmento').submit();
						//alert('submit');
					} else {
						alert('Todos los campos son requeridos.');
					}
				} else {
					alert('La tarjeta debe de tener 16 dígitos.');
					setStyleError('txtCard')
				}
			}  else {
				alert('Verifique el formato de la fecha de expiración de su tarjeta.');
				setStyleError('txtEdate')
			}
		} else {
			alert('Verifique el formato del mail.');
			setStyleError('txtMail')
		}
	} else {
		alert('Verifique el formato de la fecha de reserva.');
		setStyleError('txtDate')
	}
	//$('#frmApartmento').submit();
	/*forma = document.getElementById('frmApartmento');
	valor = '';
	for (var i = 0; i < forma.elements.length; i++) {
		valor += forma.elements[i].type + '\n';
		valor += forma.elements[i].name + '\n';;
		valor += forma.elements[i].value + '\n\n';;
	}
	alert(valor);*/
}

function checkForm() {
	entryForm = document.getElementById('frmApartmento');
	
	if($('#txtType').val() == 'R') {
		$('#txtPrice').val('100');
		$('#txtDays').val('1');
	}
	
	for (var i = 0; i < entryForm.elements.length; i++) {
    if (entryForm.elements[i].type == "text") {
        if($.trim(entryForm.elements[i].value) == "") {
					return false;
				}
    }
	}
		
	return true;
}

$(document).ready(function(e) {
	if (typeof $pagApart == "undefined") {
		setStyle();
		getApartment();
	} else {
		setStyle1();
	}
});