function rolloverImg(id,src) {
	doc=document;
  el=doc.getElementById(id);
  if(!el.oldSrc) el.oldSrc=el.src;
  el.src=src;
	el.onmouseout=function() { restoreImg(); }
  doc.currentHover=id;
}
function restoreImg() {
  doc=document;
  id=doc.currentHover;
  el=doc.getElementById(id);
  el.src=el.oldSrc;
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
String.prototype.ucfirst = function() {
   var x = this.split(/\s+/g);
   for(var i = 0; i < x.length; i++)
   {
      var parts = x[i].match(/(\w)(\w*)/);
 
      x[i] = parts[1].toUpperCase() + parts[2].toLowerCase();
   }
   return x.join(' ');
};
function urlencode(str) {
  return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}

function check_email(str) {
  at=str.indexOf('@');
  dot=str.indexOf('.',at);
  last_at=str.lastIndexOf('@');
  last_dot=str.lastIndexOf('.');
  if(at>0 && dot>0 && (dot-at)>1 && str.length-dot>1 && last_at==at && str.length>5) { valid='1' }
  else { valid='0'; }
	
  return valid
}
function pop_up(url,name,width,height) {  
	w = (document.body.clientWidth - width)/2;
  h = (document.body.clientHeight)/2;
	window.open(url,name,'width=' + width + ',height=' + height + ',menubar=no,left='+w+',top=200,screenX='+w+',screenY=200,scrollbars=1');
}
function show_hide(id) {
	if(jQuery("#"+id).css("display")=="none") { jQuery("#"+id).css("display", "block"); }
	else { jQuery("#"+id).css("display", "none"); }
}
function add_emot(id_t,emot) {
	document.getElementById(id_t).value = document.getElementById(id_t).value + emot;
	document.getElementById(id_t).focus();
}
function show(id) {
	document.getElementById(id).style.display='block';
}
function hide(id) {
	document.getElementById(id).style.display='none';
}
function browser_detection() {
	browser_version = parseInt(navigator.appVersion);
	browser_type = navigator.appName;
	if (browser_type == "Microsoft Internet Explorer" && (browser_version >= 4)) {
   var type='ie';
	} 
	else {
   var type='other';
	}
	return type;
}

function preload_images(folder,pics) {
	pics=pics.split(";");
  for(i=0;i<pics.length;i++) {
  	img=new Image();
    img.src=folder+pics[i];
  }
}
function changeValue(id) {
	d=document; el=d.getElementById(id);
	if(!el.oldValue) {
  	el.oldValue=el.value;
  }
  val=el.oldValue;
  if(el.value==el.oldValue) {
    el.focus();
  	el.value='';
    el.onblur=function() { returnValue(id) };
  }
}
function returnValue(id) {
	d=document; el=d.getElementById(id);
  if(el.value=='') el.value=el.oldValue;
}
function changeVal(el, val) {
	if(el.value==val) el.value="";
	$(el).blur(function() {
		if($(this).val()=="") $(this).val(val);
	});
}

function runFile(file) {
	d=document;
  ifr=d.getElementById('hiddenIfr');
  ifr.src=file;
}
function getElementPosition(elemID){
  var offsetTrail = document.getElementById(elemID);
  var offsetLeft = 0;
  var offsetTop = 0;
  while (offsetTrail){
   offsetLeft += offsetTrail.offsetLeft;
   offsetTop += offsetTrail.offsetTop;
   offsetTrail = offsetTrail.offsetParent;
  }
  if (navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.leftMargin != 'undefined'){
   offsetLeft += document.body.leftMargin;
   offsetTop += document.body.topMargin;
  }
  return {left:offsetLeft,top:offsetTop};
}

function getEl(el) {
	return document.getElementById(el);
}

function sapos(str) {
	if (typeof(str) !== "undefined" && str!==null) {
  	str = str.replace("'", "&#39;");
  	str = str.replace('"', '&#34;');
  	return str;
  }
	else return '';
}
function nl2br(str) {
	if (typeof(str) !== "undefined" && str!==null) return (str + '').replace(/([^>]?)\n/g, '$1<br>\n');
}
function nobr(str) {
	if (typeof(str) !== "undefined" && str!==null) return str.replace(/<br>/gi, '').replace(/<br \/>/gi, '');
}

jQuery(document).ready(function() {
  // sprites
	refreshSprites();
	refreshSpritesCh();
});
function refreshSprites() {
	jQuery(".sprite").mouseover(function() {
  	h=jQuery(this).height();
    jQuery(this).css("background-position", "0 -"+h+"px");
  });
	jQuery(".sprite").mousedown(function() {
  	h=jQuery(this).height()*2;
    jQuery(this).css("background-position", "0 -"+h+"px");
    return false;
  });
	jQuery(".sprite").mouseout(function() {
    jQuery(this).css("background-position", "0 0");
  });
	jQuery(".sprite").mouseup(function() {
    jQuery(this).css("background-position", "0 0");
  });
}
function refreshSpritesCh() {
	jQuery(".sprite-choose").mouseover(function() {
  	h=jQuery(this).height();
    if(!jQuery(this).hasClass("sprite-selected")) jQuery(this).css("background-position", "0px -"+h+"px");
  });
	jQuery(".sprite-choose").mousedown(function() {
		elem=jQuery(this);
  	h=elem.height()*2;
		jQuery(".sprite-choose[name="+elem.attr("name")+"]").css("background-position", "0px 0px");
		jQuery(".sprite-choose[name="+elem.attr("name")+"]").removeClass("sprite-selected");
    elem.css("background-position", "0px -"+h+"px");
		elem.addClass("sprite-selected");
    return false;
  });
	jQuery(".sprite-choose").mouseout(function() {
		elem=jQuery(this);
    if(!elem.hasClass("sprite-selected")) elem.css("background-position", "0px 0px");
		else {
	  	h=elem.height()*2;
	    elem.css("background-position", "0px -"+h+"px");
		}
  });
	jQuery(".sprite-choose").mouseup(function() {
		elem=jQuery(this);
    if(!elem.hasClass("sprite-selected")) elem.css("background-position", "0px 0px");
  });
}
function spriteIt(elem) {
	jQuery("#"+elem).mouseover(function() {
  	h=jQuery(this).height();
    jQuery(this).css("background-position", "0px -"+h+"px");
  });
	jQuery("#"+elem).mousedown(function() {
  	h=jQuery(this).height()*2;
    jQuery(this).css("background-position", "0px -"+h+"px");
    return false;
  });
	jQuery("#"+elem).mouseout(function() {
    jQuery(this).css("background-position", "0px 0px");
  });
	jQuery("#"+elem).mouseup(function() {
    jQuery(this).css("background-position", "0px 0px");
  });
}

function overlay(elem, w, clickclose) {
  //msg="<a href='javascript:;' onclick='jQuery.unblockUI()' id='close-blockUI' class='spr-close sprite right'></a>"+jQuery('#'+elem).html();
  if(w=="" || w=="NULL" || w=="undefined" || !w) w=500;
	jQuery.blockUI({ 
  	message: jQuery('#'+elem).html(),
    css: {
      left: (jQuery(window).width() - w) /2 + 'px', 
      width: w+'px',
			background: "none",
			border: "none"
    }
  });
  //spriteIt("close-blockUI");
  if(clickclose!==false) jQuery('.blockOverlay').attr('title','Click to close').click(jQuery.unblockUI); 
}

function confirm2(conftext, confok, callback) {
	if(confok=="" || typeof(confok)=="undefined") confok="Yes";
	w=500;
	theText="<span class='blhd'>Confirm action</span>"
					+"<span class='block t14 grey2' style='padding:5px; margin-bottom:10px;'>"
					+conftext
					+"<br><br>"
					+"<center><input type='button' onclick=\""+callback+"\" value='"+confok+"' class='submit' style='font-size:17px'>&nbsp;&nbsp;<input type='button' class='submit' value='Cancel' onclick='jQuery.unblockUI()' style='font-size:17px'></center>"
					+"</span>";
	jQuery.blockUI({
		message: theText,
		css: {
      left: (jQuery(window).width() - w) /2 + 'px', 
      width: w+'px' 
		},
		overlayCSS: {
			backgroundColor: '#000',
      opacity:          0,
      cursor:          'default'
		}
	});
	jQuery('.blockOverlay').attr('title','Click to close').click(jQuery.unblockUI); 
	return false;
}

function block_loading() {
	htm="<span class='blhd'>Loading..</span><br><br><center><font class='t17 grey'>Please wait..</font><br><br><img src='/images/loaders/medium.gif'><br><br>";
	jQuery.blockUI({
    message: htm,
    css: {
      top: "10px",
      width: '350px'
    }
  });
}


function varDump(variable, maxDeep)
{
	var deep = 0;
	var maxDeep = maxDeep || 5;

	function fetch(object, parent)
	{
		var buffer = '';
		deep++;

		for (var i in object) {
			if (parent) {
				objectPath = parent + '.' + i;
			} else {
				objectPath = i;
			}

			buffer += objectPath + ' (' + typeof object[i] + ')';

			if (typeof object[i] == 'object') {
				buffer += "\n";
				if (deep < maxDeep) {
					buffer += fetch(object[i], objectPath);
				}
			} else if (typeof object[i] == 'function') {
				buffer += "\n";
			} else if (typeof object[i] == 'string') {
				buffer += ': "' + object[i] + "\"\n";
			} else {
				buffer += ': ' + object[i] + "\n";
			}
		}

		deep--;
		return buffer;
	}

	if (typeof variable == 'object') {
		return fetch(variable);
	}

	return '(' + typeof variable + '): ' + variable + "\n";
}
function stripslashes (str) {
    return (str+'').replace(/\\(.?)/g, function (s, n1) {
        switch (n1) {
            case '\\':
                return '\\';
            case '0':
                return '\0';
            case '':
                return '';
            default:
                return n1;
        }
    });
}

function ucfirst (str) {
    str += '';
    var f = str.charAt(0).toUpperCase();
    return f + str.substr(1);
}

Array.prototype.remove = function(from, to) {
  var rest = this.slice((to || from) + 1 || this.length);
  this.length = from < 0 ? this.length + from : from;
  return this.push.apply(this, rest);
};
Array.prototype.interchange = function(from, to){
  data=this[from];
  this[from]=this[to];
  this[to]=data;
  return this;
}

function array_search (needle, haystack, argStrict) {
    var strict = !!argStrict;
    var key = '';
    for (key in haystack) {
        if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
            return key;
        }
    }
    return false;
}

Array.prototype.pushelem = function(elem){
  this.length++;
	this[this.length]=elem;
  return this;
}

function alert_msg(alert_title, alert_msg) {
  msg="<span class='alert_block'>"
    +"<span class='alert_hd'>"+alert_title+"</span>"
    +"<p>"+alert_msg+"</p>"
    +"<center>&nbsp;<a href='javascript:;' onclick='$.unblockUI()' class='sprite spr-ok'></a></center>"
    +"</span>";
  
  $.blockUI({
    message: msg,
    css: {
      border: "none",
      backgroundColor: "transparent"
    },
    overlayCSS: {
      backgroundColor: "#fff",
      opacity: 0.5,
      cursor: "default"
    }
  });
  refreshSprites();
  //$.sound.play("/inc/sounds/beep.WAV");
}

$(document).ready(function() {
	$.reject({
			imagePath: "/images/browsers/"
	});
	
	//loadStickyFooter("/inc/stickyFooter/index.php");
});

preload_images("/images/loaders/","1.gif;large.gif;small.gif;medium.gif");
preload_images("/images/sprites/", "ok.gif")

