// JavaScript Document
var divarray 	= new Array();
var divcount 	= 0; 
function waitElement(which,what){
	if(!$('#'+which).is(':visible'))$('#'+which).show();
	var pos		= {
		align: 		$('#'+which).css("float"),
		position: 	$('#'+which).css("position"),
		left:		$('#'+which).css("left"),
		top: 		$('#'+which).css("top"),
		right:		$('#'+which).css("right"),
		bottom:		$('#'+which).css("bottom")
	}
	var style = '';
	if(pos.align!='none' && pos.align!='auto')style += 'float:'+pos.align+';';
	if(pos.position!='none' && pos.position!='auto')style += 'position:'+pos.position+';';
	if(pos.left!='none' && pos.left!='auto')style += 'left:'+pos.left+';';
	if(pos.top!='none' && pos.top!='auto')style += 'top:'+pos.top+';';
	if(pos.right!='none' && pos.right!='auto')style += 'right:'+pos.right+';';
	if(pos.bottom!='none' && pos.bottom!='auto')style += 'bottom:'+pos.bottom+';';
	divarray[which] = new Object();
	divarray[which].element = $('#'+which).clone(true);
	divarray[which].count = divcount++;
	if(!what)what = "wait_element";
	wait = "<div class='"+what+"' id='WAIT_"+divarray[which].count+"' align='absmiddle' style='"+style+"' />";
	$('#'+which).replaceWith(wait);
}
function restoreElement(which) {
	if(divarray[which]){
		$('#WAIT_'+divarray[which].count).replaceWith(divarray[which].element);
		delete divarray[which];
	}
} 
/*
function updateMessage(receiver,updatetype,updateid){
	$.post('index.php?r=email/update',{
		receiver:		receiver,
		updatetype:		updatetype,
		updateid:		updateid
	});
}
*/
function jpop(div,title,message,align,decay){	
	$('#'+div).jpopup({title: title,message: message,align: align,decay:decay});
}
function clearerrors(){
	$('#jpopup_message').hide();	
}
function message(header,msg,delay,theme){
	var opts = {
		header:	header,
		life: delay
	}
	if(theme)opts.theme = theme; else opts.theme = 'msgsuccess';
		
	$.jGrowl(msg, opts);	
}
function clearMsgs(){
	$('.close').click();	
}
function checkNumber(id,msg){
	if(isNaN($.trim($('#'+id).val()))){
		message('Type Error',msg,10000,'msgerror');
		return false;
	}
	return true;
}
function checkInteger(id,msg){
	var v = $.trim($('#'+id).val());
	if(!IsNumeric(v) || v%1 != 0 ){
		message('Type Error',msg,10000,'msgerror');
		return false;
	}
	return true;
}
function checkString(id,msg){
	if($.trim($('#'+id).val())==''){
		message('Required Field',msg,10000,'msgerror');
		return false;
	}
	return true;
}
function checkEqual(id1,id2,msg){
	if($.trim($('#'+id1).val())!=$.trim($('#'+id2).val())){
		message('Input Error',msg,10000,'msgerror');
		return false;
	}
	return true;	
}
function IsNumeric(sText){
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++){ 
		Char = sText.charAt(i); 
		if(ValidChars.indexOf(Char) == -1){
			IsNumber = false;
		}
	}
   	return IsNumber;
}

function uconfirm(title,message,selector,cfunction,param){
	if(typeof(param)=='undefined')param = null;
	$(selector+' #dialog-text').html(message);
	$(selector).dialog({
		resizable: false,
		height: 'auto',
		modal: true,
		title: title,
		closeOnEscape: false,
		buttons: {
			Ok: function() {
				$(this).dialog('destroy');
				cfunction(param);
			},
			Cancel: function() {
				$(this).dialog('destroy');
			}
		}
	});
}
function waitDialog(title,message,selector){
	$(selector+' #dialog-text').text(message);
	$(selector).dialog({
		title:			title,
		resizable:		false,
		height:			100,
		modal:			true,
		closeOnEscape:	false
	});
}
function closeWaitDialog(selector){
	$(selector).dialog('destroy');	
}
function scrollToId(id){
	var offs = $('#'+id).offset();
	var t = offs.top>100 ? offs.top-100 : 0;
	window.scrollTo(0,t);	
}
if(typeof(console)=='undefined'){
	var console = new Object();
	console.log	= function(msg){
		var op = console.recursmsg(msg);
		alert(op);
	}
	console.recursmsg = function(msg){
		var op = '';
		for(var i in msg){
			if(msg.hasOwnProperty(i)){
				if(typeof(msg[i])=='object'){
					op = op + '\n [ '+i+' ] => ';
					op = op + console.recursmsg(msg[i]);
				}else{
					op = op+'\n [ '+i+' ] '+msg[i];		
				}
			}
		}
		return op;
	}
}
function urldecode (str) {
    // Decodes URL-encoded string  
    // 
    // version: 1004.2314
    // discuss at: http://phpjs.org/functions/urldecode    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)    // +      input by: travc
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Lars Fischer
    // +      input by: Ratheous    // +   improved by: Orlando
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // +      bugfixed by: Rob
    // %        note 1: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // %        note 2: Please be aware that this function expects to decode from UTF-8 encoded strings, as found on    // %        note 2: pages served as UTF-8
    // *     example 1: urldecode('Kevin+van+Zonneveld%21');
    // *     returns 1: 'Kevin van Zonneveld!'
    // *     example 2: urldecode('http%3A%2F%2Fkevin.vanzonneveld.net%2F');
    // *     returns 2: 'http://kevin.vanzonneveld.net/'    // *     example 3: urldecode('http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a');
    // *     returns 3: 'http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a'
   
    return decodeURIComponent(str.replace(/\+/g, '%20'));
}
