/*Implementation of some common javascript functions*/

$(document).ready(function(){
	$("div#closeErrorsPanel").click(function(){
		$("div#topupFormErrors").hide("slow");
	});
	$("div#topupScheduler").hide("fast");
});

/*Checktext field for constraints*/
	function SmsMessageCheck(ceiling,el){
		CSM=$('textarea.'+el);
		cv=CSM.val();
		cl=cv.length;
		if(cl){
			//check constraints
			if(cl>ceiling){
				pushstring=cv.substr(0,ceiling);
				CSM.val(pushstring);
			}
		}
	
		//reinitialize counters
		cv=CSM.val();
		cl=cv.length;
		
		//display remaining characters
		rc=ceiling-cl;
		$('span#remainingCharacters').html(rc);
	}
	
	function validateAirtimeForm(thisForm){
		return false;
	}
	
	function confirmTopupRemoval(confirmMessage){
		if (confirm(confirmMessage)){
			return true;
		}else{
			return false;
		}
	}
	
	function showMessagePopup(el,message){
		alert(message);
	}
	
	function filterPrefixes(el){
		sOpt=$("option[@value="+el.value+"]",el).html();		
		fMkp=$("select[@name='topupPrefixHolder']");
		fStr=sOpt.substring(0,sOpt.indexOf("-"));
		$("optgroup",fMkp).each(function(){
			if(this.label.search(fStr)>=0){
				ftMkp=$(this).html();
				ftMkp=ftMkp+"<option value='' selected='selected'>-select-</option>";
				prOpt=$("select[@name='topupPrefix']");
				$(prOpt).html(ftMkp);
			}
		});
	}
	
	
	function showScheduler(){
		$("div.topupScheduler").show("slow");
	}
	
	function  hideScheduler(){
		$("div.topupScheduler").hide("slow");
	}
	
	function loadAirTips(fStr,context){
		$(context).html("Fetching...");
		$.post('/shop/airtime/index.cfm/loadtips',{fStr:fStr},function(rObject){
			$("div#airSenseWrapper").html(rObject);
		});
		return false;
	}
