
////////////////////////////////////////
var ajaxObjects = new Array();
////////////////////////////////////////
////////////////////////////////////////
function login(form){
	var ajaxIndex = ajaxObjects.length;
	ajaxObjects[ajaxIndex] = new sack();
	ajaxObjects[ajaxIndex].reset();
	ajaxObjects[ajaxIndex].setVar("id", form.id.value);
	ajaxObjects[ajaxIndex].setVar("pwd", form.pwd.value);
	ajaxObjects[ajaxIndex].requestFile = "ajax/login.php";
	ajaxObjects[ajaxIndex].method = 'POST';
	//ajaxObjects[ajaxIndex].element = 'loginResultDiv';
	//ajaxObjects[ajaxIndex].onLoading = function () { whenLoading('loginResultDiv') };
	//ajax.onLoaded = whenLoaded;
	ajaxObjects[ajaxIndex].onCompletion = function() { whenCompleted(ajaxIndex,form.xfer.value); };
	ajaxObjects[ajaxIndex].runAJAX();
}


function whenLoading(objd){
	var e = document.getElementById(objd);
	e.innerHTML = "<img src='images/loaders/ajax-loader_2.gif'>";
}

function whenCompleted(ajaxIndex, xfer) {
	//alert(ajaxObjects[ajaxIndex].response);
	
	if (ajaxObjects[ajaxIndex].response == "DISABLED") {
		alert("Üyeliğiniz geçici süreli durdurulmuştur");
		return false;
	}
	
	if (ajaxObjects[ajaxIndex].response == "FAIL") {
		alert('hatalı giriş');
	} else {
		if ( xfer != "" )
			 dynConObj.loadContent('bodyPannel','ajax/register.php?tour_id=' + xfer);
		else successLogin(ajaxObjects[ajaxIndex].response);
	}
	
}


function successLogin(status) {	
	if (status == "admin") {
		dynConObj.loadContent('menubar','includes/admin.menu.php');	
		dynConObj.loadContent('bodyPannel','ajax/admin.tours.php');
	} else {
		dynConObj.loadContent('menubar','includes/member.menu.php');	
		dynConObj.loadContent('bodyPannel','ajax/member.tours.php');
	}	
}


////////////////////////////////////////////////////////////

function checkMember(form){
	var ajaxIndex = ajaxObjects.length;
	ajaxObjects[ajaxIndex] = new sack();
	ajaxObjects[ajaxIndex].reset();
	ajaxObjects[ajaxIndex].setVar('id', form.id.value);
	ajaxObjects[ajaxIndex].setVar('pwd', form.pwd.value);
	ajaxObjects[ajaxIndex].setVar('tour_id', form.tour_id.value);
	ajaxObjects[ajaxIndex].setVar('from', 'check_member');
	
	ajaxObjects[ajaxIndex].requestFile = "ajax/checkPasswd.php";
	ajaxObjects[ajaxIndex].method = 'POST';
	//ajaxObjects[ajaxIndex].element = 'loginResultDiv';
	//ajaxObjects[ajaxIndex].onLoading = function () { whenLoading('loginResultDiv') };
	//ajax.onLoaded = whenLoaded;
	ajaxObjects[ajaxIndex].onCompletion = function() { whenCheckCompleted(ajaxIndex); };
	ajaxObjects[ajaxIndex].runAJAX();
}

function whenCheckCompleted(ajaxIndex) {
	//alert(ajaxObjects[ajaxIndex].response);
	var arr = ajaxObjects[ajaxIndex].response.split('|');
	//alert(arr[0]);
	if (arr[0] == "FAIL") {
		alert('Hatalı üyelik giriş kodları');
		document.getElementById('status').selectedIndex = 0;
		return false;	
	} 
	
	if (arr[0] == "NOMEMBER") {
		alert('Üye indiriminden yararlanmak için kulübe üye olmanız gerekmektedir');
		document.getElementById('status').selectedIndex = 0;
		return false;	
	} 
	
	if (arr[0] == "REREGISTER") {
		alert('Bu gezi için girilen üye koduyla daha önce kayıt yapılmış. Her üye kodu bir gezi için tek sefer kullanılabilir.');
		document.getElementById('status').selectedIndex = 0;
		return false;	
	} 
	
	
	// formu üye bilgilerinden otomatik doldur
	var mem = arr[1].split(';');
	document.regForm.part_member_id.value = mem[0];
	
	document.regForm.part_name.value = mem[1];
	document.regForm.mobile.value = mem[2];
	document.regForm.part_name.phone = mem[3];
	document.regForm.email.value = mem[4];
	// kuruları read only yap
	document.regForm.part_name.readOnly = true;
	document.regForm.mobile.readOnly = true;
	document.regForm.phone.readOnly = true;
	document.regForm.email.readOnly = true;
	//		
		
	if ( document.getElementById('extra')) {
		if ( document.getElementById('extra').checked )
	 		 document.getElementById('total').value = parseFloat(member_road_price) + parseFloat(member_extra_price) + parseFloat(member_hostel_price);
		else document.getElementById('total').value = parseFloat(member_road_price) + parseFloat(member_hostel_price);		
	} else {
		document.getElementById('total').value = parseFloat(member_road_price) + + parseFloat(member_hostel_price);
	}
	
	closeMessage();	
}
