/* Ajax post request */
function scriptDoLoadPost(scriptUrl, scriptForm, scriptPos, scriptArgs, noLoading) {
	if(!scriptArgs){ var scriptArgs = ''; }
	scriptArgs = $(scriptForm).serialize() + scriptArgs;
	myAjax = new Ajax.Updater(scriptPos, scriptUrl, {
		method : 'post',
		parameters : scriptArgs,
		evalScripts : true,
		onLoading: function(request){ showLoadingIcon(scriptPos, noLoading); },
		insertion : Insertion.Append
	});
}

/* Ajax get request */
function scriptDoLoad(scriptUrl, scriptPos, scriptArgs, noLoading) {
	myAjax = new Ajax.Updater(scriptPos, scriptUrl, {
		method : 'get',
		parameters : scriptArgs,
		evalScripts : true,
		onLoading : function(request){ showLoadingIcon(scriptPos, noLoading); },
		insertion : Insertion.Append
	});
}

/* basic ajax get request */
function scriptRequest(scriptUrl, scriptPos){
	
	myAjax = new Ajax.Request(scriptUrl, {
		method: 'get',
		onSuccess: function(transport) {
			document.getElementById(scriptPos).innerHTML = transport.responseText;			
		}
	});

}

/* Onloading image icon function */
function showLoadingIcon(scriptPos,noLoading){
	loading = 0;
  	contentDiv = "";
	switch (scriptPos){		
		
		case "content":
			contentDiv = '<div id="loading_content"></div>';
			loading = 1;
			break;
	}
	
	if((loading == 1) && (noLoading != 1)){
		document.getElementById(scriptPos).innerHTML = contentDiv;
	}
}

function confirmLoad(scriptUrl, scriptPos, scriptArgs) {

	var agree = confirm("Do you really want to proceed? ");
	if (agree)
		return scriptDoLoad(scriptUrl, scriptPos, scriptArgs);
	else
		return false;
}

function confirmSubmit(scriptUrl, scriptForm, scriptPos) {

	var agree = confirm("Do you really want to proceed? ");
	if (agree)
		return scriptDoLoadPost(scriptUrl, scriptForm, scriptPos);
	else
		return false;
}


function doSubmit(fname){
	document.forms[fname].submit();
}

function showStar(id, val, myrate){
	for(var i=1; i<=id; i++){
		if(i > myrate){
			var but = document.getElementById('star'+i).src;		
			if(val == 'on'){
				but = but.replace(/_off/,"_on");
			}else{
				but = but.replace(/_on/,"_off");
			}
	        document.getElementById('star'+i).src = but;
		}
	}
	
	var txt = '';
	if(val == 'on'){
		if(id==1){
			txt = "Poor!";
		}else if(id==2){
			txt = "Works!";
		}else if(id==3){
			txt = "Good!";
		}else if(id==4){
			txt = "Great!";
		}else if(id==5){
			txt = "Fantastic!";
		}
	}
	
	document.getElementById('rating_txt').innerHTML = txt;
}

function confirmRequest(url){
	var agree = confirm("Do you really want to proceed? ");
	if (agree)
		return window.location=url;
	else
		return false;
}
