/*
 *
 * Tab In Process JavaScript
 * v1.0 abdul.othman@i-to-i.com
 * 2008-03-05
 *
 */

	// Prototype.js is required: Web
	function loadPage(url,elemtoshow) {
		var resultarea = $(elemtoshow);

		new Ajax.Updater(resultarea,url, {
			method: 'post',
			asynchronous: true,
			evalScripts: true,
			onLoading: function() {
				Element.show('loading');
			},
		    onComplete: function(result) {
		        resultarea.innerHTML=result.responseText;
		        Effect.Fade('loading', {delay:0.4});
		    }
		} );
		return false;
	}

	// process inside the tab content
	function loadPageExtra(url,params,elemtoshow) {
		var resultarea = $(elemtoshow);

		if (elemtoshow == 'gal-comments') {
			requiredFields = new Array("comment_author","comment_text");
			friendlyNames = new Array("name","comment");

			for(i=0;i<requiredFields.length;i++){
				if ( ($(requiredFields[i]).value == "") || ($(requiredFields[i]).value == "Your nickname") ){
					alert("Please type your "+friendlyNames[i]+".");
					$(requiredFields[i]).focus();
					$(requiredFields[i]).style.backgroundColor = "#fcc";
					return false;
				}
			}

			autcomment = $('comment_author').value;
			txtcomment = $('comment_text').value;
			ratecomment = $('comment_rating').value;
			params += "&pic_comment_author="+autcomment+"&pic_comment="+txtcomment+"&pic_comment_rating="+ratecomment;
		}

		new Ajax.Updater(resultarea,url, {
			method: 'post',
			parameters: params,
			asynchronous: true,
			evalScripts: true,
			onLoading: function() {
				Element.show('loading');
			},
		    onComplete: function(result) {
		        resultarea.innerHTML=result.responseText;
		        if (elemtoshow == 'gal-comments') { Element.hide('img-comment');}
		        Effect.Fade('loading', {delay:0.4});
		    }
		} );
		return false;
	}

	// limit text area entry
	function limitText(limitField, limitNum) {
		if (limitField.value.length > limitNum) {
			limitField.value = limitField.value.substring(0, limitNum);
		}
	}

	// JQuery is required: CMS Only
	// A H O 20080228
	function jqloadPage(url,params,elemtoshow) {
		$.ajax({
			type: 'POST',
			url: url,
   			data: params,
   			beforeSend: function(){
				$('#loading_area').show();
			},
			success: function(html){
				//$('#loading_area').hide();
				$("#loading_area").fadeOut("slow");
				$('#'+elemtoshow).html(html);
			}
		});
	}
