function _mtt_loader(step) {
	$().ready(function() { 
//		_mtt_Loading();
		$('#prevBtnDiv').html('<div style="display:block;background:#fff;height:30px;width:120px;border:solid 1px #999;"><div style="width:25px;float:left;padding-left:3px;padding-top:5px;"><img src="../Img/loader-min.gif" alt="" /></div><div style="float:left;width:60px;font:italic 14px/16px Tahoma;padding-top:3px;margin-top:3px;">Loading</div></div>');
/*
	$("#message_container").html("");
	$("#summary").html("");
	$("#messageDiv").hide();
					    $("#showHideMsg").attr({ 
					          src: $("#showHideMsg").attr("src") == "../Img/icon_hide.gif" ? "../Img/icon_show.gif" : "../Img/icon_hide.gif",
					          alt: $("#showHideMsg").attr("src") == "../Img/icon_hide.gif" ? "Show Message(s)" : "Hide Message(s)",
					          title: $("#showHideMsg").attr("src") == "../Img/icon_hide.gif" ? "Show Message(s)" : "Hide Message(s)"
				        });

*/
		$("#myApplDiv").load(step + ".php"); 
		$("#myApplDiv").show(); 
	});
}
function _mtt_Loading() {
	$('#myApplDiv').html('<div style="height:200px;text-align:center;font:bold 16px/16px Tahoma;"><img src="/Img/loadingAnimation.gif" alt="" border="0" /><br />Please Wait. Loading Application ...</div>');
}

function goodchars(e, goods) {
	var key, keychar;
	key = getkey(e);
	if (key == null) return true;
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	goods = goods.toLowerCase();
	if (goods.indexOf(keychar) != -1)
		return true;
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		return true;
	return false;
}
function getkey(e) {
	if (window.event)
		return window.event.keyCode;
	else if (e)
		return e.which;
	else
		return null;
}
function getBrowser() {
    brs=navigator.userAgent.toLowerCase();
    var retval;
    if (brs.search(/msie\s(\d+(\.?\d)*)/)!=-1) {
        retval='msie';
    } else if (brs.search(/netscape[\/\s](\d+([\.-]\d)*)/)!=-1) {
        retval='netscape';
    } else if (brs.search(/firefox[\/\s](\d+([\.-]\d)*)/)!=-1) {
        retval='firefox';
    } else if (brs.search(/safari[\/\s](\d+([\.-]\d)*)/)!=-1) {
        retval='safari';
    } else {
        retval='unknown';
    }
    return retval;
}
function checkKeyPress(ev, obj, allowDot) {
    var keyCode = null;
    if ( getBrowser()=='msie' ) {
        keyCode = window.event.keyCode;
    } else if ( getBrowser()=='netscape' || getBrowser()=='firefox' ) {
        keyCode = ev.which;
    }
    var keyAllowed = true;
    if (keyCode==8||keyCode==9) {
        retval = true;
    } else {
		if (allowDot)
			keyAllowed =  ((keyCode >= 48) && (keyCode <= 57) || keyCode == 46)
		else
			keyAllowed = (keyCode >= 48) && (keyCode <= 57)

	    if (!keyAllowed) {
    	    if ( getBrowser()=='msie' ) {
        	    window.event.keyCode=0;
	        } else if ( getBrowser()=='netscape' || getBrowser()=='firefox' ) {
    	        ev.preventDefault();
        	    ev.stopPropagation();
            	ev.returnValue=false;
	        }
    	}
		   return false;
	}
}

function validate_email(input) {
	s= input.value
	if(s.search) {
		return (s.search(new RegExp("^([-!#$%&'*+./0-9=?A-Z^_`a-z{|}~])+@([-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,4}$","gi"))>=0)
	}
	if(s.indexOf) {
		at_character=s.indexOf('@')
		if(at_character<=0 || at_character+4>s.length)
			return false
	}
	if(s.length<6)
		return false
	else
		return true
}
function getCookieVal (offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
		endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
			return getCookieVal (j);    
			i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}
function SetCookie (name, value) {  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = GetCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
function paypalSubmit(u) {
	document.pp.custom.value = u;
	document.pp.submit();
}
function popStatement() {
	var WinW = screen.availWidth; 
	var WinH = screen.availHeight;
	var w = 500; 
	var h = 250;
	var posX = (WinW-w)/2;
	var posY = (WinH-h)/2;
	var params = "screenX="+posX+",screenY="+posY+",width="+w+",height="+h;
	newWin = window.open("/app_upload_statement.php", "Dummy", params)
	newWin.focus();
}

function _mtt_check_appl() {
	$.ajax({
			type: "GET",
			url: "check.php",
			async: false,
			success: function(responseText) {
				eval(responseText);
			},
			error:function (xhr, ajaxOptions, thrownError){
				alert(xhr.responseText);

			}   

	});
}
function saveAppl(s) {
//	location.href = '/app_save_box.php';
	if ( confirm("If you proceed now, you will save all the information filled out in the previous steps except the current one. If you wish to save also the current step, please fill out all the required fields and then click on the 'Next' button.") ) 
		openModalWin('/app_save_box.php?s='+s, 750, 500, retFunc);
}


// model win starts
var modalWin = new Object( );
	function openModalWin(url, width, height, returnFunc, args) {
        name = (new Date( )).getSeconds( ).toString( );
		if(window.showModalDialog) { // IE
			modalWin.returnFunc = returnFunc;
			window.showModalDialog(url, name,'dialogWidth:'+width+'px; dialogHeight:'+height+'px; Help:0; Scroll:1; Status:1;'+args);
		}else {
			if (!modalWin.win || (modalWin.win && modalWin.win.closed)) {
				if(window.screenX) { // probably FF
			        modalWin.url = url;
			        modalWin.width = width;
			        modalWin.height = height;
			        modalWin.returnFunc = returnFunc;
		    	    modalWin.args = args;
		        	modalWin.returnedValue = "";
					modalWin.left = window.screenX + ((window.outerWidth - modalWin.width) / 2);
					modalWin.top = window.screenY + ((window.outerHeight - modalWin.height) / 2);
					var param = "modal=yes,screenX=" + modalWin.left + ",screenY=" + modalWin.top + ",scrollbars=yes,resizable=no,width=" + modalWin.width + ",height=" + modalWin.height;
	       	 	} else { // maybe others
	    	        modalWin.left = (screen.width - modalWin.width) / 2;
		            modalWin.top = (screen.height - modalWin.height) / 2;
    		        var param = "modal=yes,left=" + modalWin.left + ",top=" + modalWin.top + ",scrollbars=yes,resizable=no,width=" + modalWin.width + ",height=" + modalWin.height;
		        }
				modalWin.win = window.open(modalWin.url, name, param);
				modalWin.win.focus();
	    	} else {
       			modalWin.win.focus();
		    }
		}
	}
	function blockGeckoEvents() {
		if(!window.showModalDialog) {
			$('#geckoHiddenLayer').show();
			window.onfocus = checkOpenedModal;
	    	document.onclick = checkOpenedModal;
		}
	}
	function unblockGeckoEvents( ) {
		if(!window.showModalDialog) {
			$('#geckoHiddenLayer').hide();
		}
	}
	function checkOpenedModal( ) {
    	if (!window.showModalDialog && modalWin.win && !modalWin.win.closed) {
	        modalWin.win.focus( );
	    }
	}
   
function retFunc( ) {
//	alert('ok');
}
// modal win ends
function doChange() {
	var id 		= arguments[0];
	var which	= arguments[1];
	var campus	= arguments[2];
	var programme	= arguments[3];
	switch (which) {
		case 1 : // manage specialisation combobox using selected campus id
			if($('#fifthCampus').val()) { // a valid option selected
				for (var q=document.getElementById('fifthSpecialization').options.length;q>=0;q--)
					document.getElementById('fifthSpecialization').options[q] = null;	 // null all of them
				for (var q=document.getElementById('fifthStartingDate').options.length;q>=0;q--)
					document.getElementById('fifthStartingDate').options[q] = null; // null all of them


				document.getElementById('fifthSpecialization').options[document.getElementById('fifthSpecialization').options.length] = new Option('Please wait...', ''); // create first option (Please wait...)	
				document.getElementById('fifthStartingDate').options[document.getElementById('fifthStartingDate').options.length] = new Option('Select Programme First', ''); // create first option (Please wait...)

				$("#divSpecialisation").load('/_getFormData.php?ACT=DO&CAMPUS='+id+'&WHICH=5&PROGRAMME='+programme); // fetch data from 


			}else{  // empty option selected (first item)

				for (var q=document.getElementById('fifthSpecialization').options.length;q>=0;q--) // loop options
					document.getElementById('fifthSpecialization').options[q] = null;	 // null all of them
				for (var q=document.getElementById('fifthStartingDate').options.length;q>=0;q--) // loop options
					document.getElementById('fifthStartingDate').options[q] = null;		 // null all of them	
				document.getElementById('fifthSpecialization').options[document.getElementById('fifthSpecialization').options.length] = new Option('Select ESE Centre First', ''); // create first option (Select campus first)	
				document.getElementById('fifthStartingDate').options[document.getElementById('fifthStartingDate').options.length] = new Option('Select ESE Centre First', ''); // create first option (Select campus first)
				document.getElementById('fifthCampus').focus();
			}
		break;

		case 2 :  // manage date combobox using selected specialisation id
			if($('#fifthSpecialization').val()) { // a valid option selected
				for (var q=document.getElementById('fifthStartingDate').options.length;q>=0;q--) // loop options
					document.getElementById('fifthStartingDate').options[q] = null; // null all of them

				document.getElementById('fifthStartingDate').options[document.getElementById('fifthStartingDate').options.length] = new Option('Please wait...', ''); // create first option (Please wait...)	

				$("#divStartingDate").load('/_getFormData.php?ACT=DO&CAMPUS='+campus+'&SPEC='+id+'&WHICH=6'); // fetch data from database

			}else{  // empty option selected (first item)
				for (var q=document.getElementById('fifthStartingDate').options.length;q>=0;q--) // loop options
					document.getElementById('fifthStartingDate').options[q] = null;	 // null all of them		
				document.getElementById('fifthStartingDate').options[document.getElementById('fifthStartingDate').options.length] = new Option('Select Programme First', ''); // create first option (Select specialisation area first)
				document.getElementById('fifthSpecialization').focus();
			}
		break;
	}
}
