function selectOption(ele,num) {
	var selObj = document.getElementById(ele);
	selObj.selectedIndex = num;
}	

function submitAjaxForm(theform,divx) {
  var status = AjaxRequest.submit(
    theform
    ,{
      'onSuccess':function(req){ document.getElementById(divx).innerHTML = req.responseText; }
    }
  );
  return status;
}

function clearDefault(el) {
	if (el.defaultValue==el.value) el.value = ""
}

//confirm action before redirect
function confirmAction(myURL,myMES){
	var res = confirm(myMES);
	if(res){
		location.href=myURL;
	}
}

function sendMyPass() {
	var email = document.getElementById('myemail').value;
	function SimpleAJAXCallback(in_text){
		document.getElementById('forgotpass').innerHTML = in_text;
	}
	if (email) {
		document.getElementById('forgotpass').innerHTML = 'Sending your password please wait ...';
		SimpleAJAXCall('ajax.call.php?ajax=sendpass&email='+encodeURI(email),SimpleAJAXCallback,'POST');
	} else {
		alert("Please enter your email address to have your password sent to you.");
	}
}

function sendMyAct() {
	var email = document.getElementById('myemail').value;
	function SimpleAJAXCallback(in_text){
		document.getElementById('forgotpass').innerHTML = in_text;
	}
	if (email) {
		document.getElementById('forgotpass').innerHTML = 'Sending your activation email please wait ...';
		SimpleAJAXCall('ajax.call.php?ajax=sendactivation&email='+encodeURI(email),SimpleAJAXCallback,'POST');
	} else {
		alert("Please enter your email address to have your activation email sent to you.");
	}
}

function showIName() {
	var v = document.getElementById('etype').value;
	function SimpleAJAXCallback(in_text){
		document.getElementById('enamediv').innerHTML = in_text;
	}	
	SimpleAJAXCall('ajax.call.php?ajax=iname&ilabel='+encodeURI(v),SimpleAJAXCallback,'POST');
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

function stopRKey(evt) {
	var evt = (evt) ? evt : ((event) ? event : null);
	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
	if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}

function ajaxValidSubmit(theform,divx) {
	if (validateFields(document.getElementById('tripsummary'), rules)) {
		submitAjaxForm(theform,divx);
	}
}

function submitThisForm(theform) {
	 if (validateFields(document.getElementById('eform'), rules)) {
		 var status = AjaxRequest.submit(
			theform
			,{
				'onSuccess':function(req){ document.getElementById('smessage').innerHTML = req.responseText; theform.reset(); refreshmoMindList();}
				}
			);
	}
}
					
function listMoMind(di,tt) {
	function SimpleAJAXCallback(in_text){
		document.getElementById(di).innerHTML = in_text;
	}	
	SimpleAJAXCall('ajax.call.php?ajax=listmyevent&tt='+encodeURI(tt),SimpleAJAXCallback,'POST');
}

function refreshmoMindList() {
	if (document.getElementById('dowhat').value == 'update') {
		listMoMind('linetable','');
	}
	if (document.getElementById('dowhat').value == 'dashboard') {
		listMoMind('linetable_last','latest');
		listMoMind('linetable_month','thismonth');
	}
}

function removeMoMind(e) {
	function SimpleAJAXCallback(in_text){
		refreshmoMindList();
	}	
	var res = confirm("Are you sure you want to remove this entry?");	
	if(res){
		SimpleAJAXCall('ajax.call.php?ajax=removemomind&ee='+encodeURI(e),SimpleAJAXCallback,'POST');	
	}
}

