// ajax call to load the cities options into an item
function loadCities(provId,target) {
	 $.post("_ajax.php",{action: 'loadCities', provId: provId},function(res) {
		 $(target).html(res);
	 }); 
}

function showModal(target,page) {
	$(target).load(page);
	$(target).dialog("open");
}
function closeModal(target) {
	$(target).html('');
	$(target).dialog("close");
}

// form validation script
// USAGE : <form ACTION METHOD onsubmit="return validateThis(this);" id="formId">
// MUST HAVE AN ID

function validateThis(formItem) {
	var returnVal = true;
	formId = formItem.id;
	$("#"+formId+" .required").each(function() {
	$(this).removeClass('isValid');
	$(this).removeClass('notValid');

	if ($(this)[0].tagName == 'INPUT' || $(this)[0].tagName == 'TEXTAREA') {
			var req = $(this).attr('req');
			var rVal = $(this).val();
			var len = $(this).val().length;
			if (req == 'email') {
				// email checking
				var emailOk = true;
				if (!rVal.match("@")) { emailOk = false;  }
				if (!rVal.match(/[.]/)) { emailOk = false;  }
				if (len < 6) { emailOk = false;  }
				if (emailOk == true) { $(this).addClass('isValid'); } else { $(this).addClass('notValid'); returnVal = false; }
			} else {
				// standard length checking
				if (len >= req) { $(this).addClass('isValid'); } else { $(this).addClass('notValid'); returnVal = false; }
			}
		}
		
		if ($(this)[0].tagName == 'SELECT') {
			var thisVal = $(this).val();
			if (thisVal != '' && thisVal != 'N/A' && thisVal != 'NA' && thisVal != ' ' && thisVal != 'null' && thisVal != null) { $(this).addClass('isValid'); } else { $(this).addClass('notValid'); returnVal = false; }
		}
		
	});
		return returnVal;
}


function changePass(formItem) {

	var pw1 = $("#pw1").val();
	var pw2 = $("#pw2").val();
	
	if (pw1.length >= 4 && pw2.length >= 4 && pw1 == pw2) {
		$("#pw1").removeClass("notValid");
		$("#pw2").removeClass("notValid");
		$("#pw1").addClass("isValid");
		$("#pw2").addClass("isValid");
		return true;
	} else {
		$("#pw1").removeClass("isValid");
		$("#pw2").removeClass("isValid");
		$("#pw1").addClass("notValid");
		$("#pw2").addClass("notValid");
		return false;	
	}
}



// function to check if the signup username is valid and not currently in the system.
function checkUserOK() {
	var u = $("#username").val();
	var ret = true;
	$.post("_ajax.php",{action: 'checkUser', un: u},function(res) {
		
		switch (res) {
			case '1':
				$("#userOK").val("");
				$("#userOKimage").css('display','inline');
				$("#userOKimage").attr("src","http://cdn.urbytus.net/_icons/exclamation.png");
			break;
			
			case '0':
				$("#userOK").val("Y");
				$("#userOKimage").css('display','inline');
				$("#userOKimage").attr("src","http://cdn.urbytus.net/_icons/tick.png");
			break;
		}
		
		
	});
}



// Changing images in front page

var image1=new Image()
image1.src="./images/step_1.jpg"
var image2=new Image()
image2.src="./images/step_1.1.jpg"
var image3=new Image()
image3.src="./images/step_1.2.jpg"



// task functions
function readItem(link,thisItem) {
	$(".listPaneActive").removeClass('listPaneActive');
	$("#" + thisItem).addClass("listPaneActive");
	$("#readPane").html('<center style="color: #999;font-size: 10px;padding: 50px 0;"><img src="http://cdn.urbytus.net/images/jsonLoader.gif" /></center>');
	$("#readPane").load(link);
}
		
function tasksSelTab(tabId) {
	$("#tasks_tabs").tabs("select",tabId);
}
function ua_taskMsgOrig(msgId) {
	$("#modal1").html('');
	$("#modal1").load("_ajax_task_showOrig.php?msgId=" + msgId);
	$("#modal1").dialog('open');
}
function ua_task_viewList(msgId) {
	$("#modal1").html('');
	$("#modal1").load("_ajax_task_viewList.php?msgId=" + msgId);
	$("#modal1").dialog('open');
}
function ua_task_toggleMsgBox(taskId) {
	$("#modalTskMsg").html('');
	$("#modalTskMsg").load("_ajax_task_newMsg.php?taskId=" + taskId);
	$("#modalTskMsg").dialog('open');
}



