// jquery function miscellaneous
//  
// Copyright Vllad 2010. All Rights reserved.
// 
// This software may be used, modified and distributed freely
// providing this copyright notice remains intact at the head 
// of the file.
//
// This software is freeware. The author accepts no liability for
// any loss or damages whatsoever incurred directly or indirectly 
// from the use of this script. The author of this software makes 
// no claims as to its fitness for any purpose whatsoever. If you 
// wish to use this software you should first satisfy yourself that 
// it meets your requirements.
//
// URL:   
// Email: oscar@ranchostudios.com
 
 
function getAjax(ttype,miData,beforeSend,onSuccess,onError){
 
	if (!ttype)ttype="POST";
	var pasa_json;	
 
	$.ajax({
	   	type: ttype,
	   	url: _HOME+"/ajax.php",
	   	data: miData,
	   	beforeSend: function(){
			if(beforeSend)beforeSend.call(this);
		},
	   	success: function(json){
			pasa_json = json;
		},
		error: function(data, status, e){
			if(onError)onError.call(this,data,status,e);
		},
		complete: function(XMLHttpRequest, textStatus) {
			if( XMLHttpRequest.status==200){
				if(onSuccess)onSuccess.call(this,pasa_json);
			}else{
				//alert('Check your internet connection.');
			}
		}
 
	});
} 

function print_r(theArray,level){
	 var salida = "";
	 var profundo = "";
	 if (typeof level == 'undefined' ) {profundo = '';level=0;}
	 else{for (i=0;i<level;i++){profundo+="\t";}}
	 for(var prop in theArray){ 
		 if (typeof(theArray[prop])=='object'){
			 salida += profundo+"["+prop+"] = \n "+print_r(theArray[prop],level+1)+"\n";
		 }else{
			 salida += profundo+"["+prop+"] = "+theArray[prop]+"\n";
		 }
	 } 
	return salida;    
}

function getJson(json){
	return eval('(' + json + ')');
}
 
function msgTo(selector,msg){
	if(selector=='#code-msg'){
		$('#code-msg-cont').fadeIn();
		setTimeout("hideMsgTo('#code-msg-cont')",5000); 
	}
	$(selector).empty();
	$(selector).append(msg);
}

function hideMsgTo(selector){
	$(selector).fadeOut();
}
/*function alerts(string,type){
	$('.alerts-'+type).empty();
	$(".alerts-"+type).append(string);
	$('.alerts-'+type).fadeIn();
	setTimeout("hideMsgTo('.alerts-"+type+"')",5000);
}*/
function alerts(msg,type){
	if (type=='error')
		msg='<div  id="modalalert"><div class="ui-widget"><div class="ui-state-error ui-corner-all" style="padding: 0 .7em;"><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>'+msg+'</div></div></div>';
	else if(type=='info') 
		msg='<div  id="modalalert"><div class="ui-widget"><div class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;"><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>'+msg+'</div></div></div>';
	else
		msg='<div  id="modalalert">'+msg+'</div>';
	modalWindow(msg,400,66,"");
}

function modalWindow(html,w,h,r){
	
if(r==''){	
	$.modal(
			html,
			{
				minHeight:h,
				minWidth: w,
				width: w,
				height:h,
			overlayClose:true,
			onOpen: function (dialog) {dialog.overlay.fadeIn('slow', function () {dialog.data.hide();dialog.container.fadeIn('slow', function () {dialog.data.slideDown('slow');});})},
			onClose: function (dialog) {
						$('.modalCloseImg').fadeOut();
						dialog.data.fadeOut('slow', function () {
								dialog.container.hide('slow', function () {
									dialog.overlay.slideUp('slow', function () {
										$.modal.close();
									});
								});
							});
			}});
	}
else{
	$.modal(
			html,
			{
				minHeight:h,
				minWidth: w,
				width: w,
				height:h,
			overlayClose:true,
			onOpen: function (dialog) {dialog.overlay.fadeIn('slow', function () {dialog.data.hide();dialog.container.fadeIn('slow', function () {dialog.data.slideDown('slow');});})},
			onClose: function (dialog) {
						$('.modalCloseImg').fadeOut();
						dialog.data.fadeOut('slow', function () {
								dialog.container.hide('slow', function () {
									dialog.overlay.slideUp('slow', function () {
										$.modal.close();
										window.location=r;
									});
								});
							});
			}});
	
}
}


function modalWindowScroll(html,w,h,r){
	
	if(r==''){	
		$.modal(
				html,
				{
					minHeight:h,
					minWidth: w,
					width: w,
					height:h,
				overlayClose:true,
				onOpen: function (dialog) {dialog.overlay.fadeIn('slow', function () {dialog.data.hide();dialog.container.fadeIn('slow', function () {dialog.data.slideDown('slow');$('.scroll-pane').jScrollPane();$("#simplemodal-container a.modalCloseImg").css({'right':'-10px','top':'-6px'});});})},
				onClose: function (dialog) {
							$('.modalCloseImg').fadeOut();
							dialog.data.fadeOut('slow', function () {
									dialog.container.hide('slow', function () {
										dialog.overlay.slideUp('slow', function () {
											$.modal.close();
										});
									});
								});
				}});
		}
	else{
		$.modal(
				html,
				{
					minHeight:h,
					minWidth: w,
					width: w,
					height:h,
				overlayClose:true,
				onOpen: function (dialog) {dialog.overlay.fadeIn('slow', function () {dialog.data.hide();dialog.container.fadeIn('slow', function () {dialog.data.slideDown('slow');$('.scroll-pane').jScrollPane();});})},
				onClose: function (dialog) {
							$('.modalCloseImg').fadeOut();
							dialog.data.fadeOut('slow', function () {
									dialog.container.hide('slow', function () {
										dialog.overlay.slideUp('slow', function () {
											$.modal.close();
											window.location=r;
										});
									});
								});
				}});
		
	}
	}


function getPage(url){
	window.location=url;
}
