var SiteGlobalPath			= "http://www.socialnetgate.com/";
var SiteAbsolutePath		= "/home/socialne/public_html/";
var SiteRootPath			= "/";
var SiteDefaultThemePath	= "default";
var SiteAdminGlobalPath		= "http://www.socialnetgate.com/siteadmin/";
var SiteAdminAbsolutePath	= "/home/socialne/public_html/siteadmin/";
var SiteAdminRootPath		= "/siteadmin/";
var SiteAjaxPath			= "/webapp/views/default/ajax/";
var SiteScriptPath			= "/webapp/views/default/javascript/";
var SiteStylePath			= "/webapp/views/default/styles/";
var SiteImagePath			= "/images/";
var SiteTitle				= "SocialNetGate";

function parseJSON(json){
    try{
        if(/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(json)){
            var j = eval('(' + json + ')');
            return j;
		}
	}catch(e){
    }
    throw new SyntaxError("parseJSON");
}

function redirect(redirect_url){
	window.location = redirect_url;
}

function autolink(s){
	var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gi;
	return s.replace(exp,"<a href='$1' target='_blank'>$1</a>");
	/*var hlink = /\s(ht|f)tp:\/\/([^ \,\;\:\!\)\(\"\'\<\>\f\n\r\t\v])+/g;
	return (s.replace (hlink, function ($0,$1,$2){
		s = $0.substring(1,$0.length);
		return " <a href='"+s+"' target='_blank'>"+s+"</a>";
	}));*/
}
function stripHTML(oldString) {
	var newString = "";
	var inTag = false;
	for(var i = 0; i < oldString.length; i++) {
		if(oldString.charAt(i) == '<') inTag = true;
		if(oldString.charAt(i) == '>') {
			if(oldString.charAt(i+1)=="<"){
				//dont do anything
			}else{
				inTag = false;
				i++;
			}
		}
		if(!inTag) newString += oldString.charAt(i);
	}
	return newString;
}

function br2nl(oldString){
	return oldString.replace(/<br>/gi, "");
}

function disableAnchor(obj, disable){
	if(disable){
		var href = obj.getAttribute("href");
		if(href && href != "" && href != null){
			obj.setAttribute('href_bak', href);
		}
		obj.removeAttribute('href');
		obj.style.color="gray";
	}else{
		obj.setAttribute('href', obj.attributes['href_bak'].nodeValue);
		obj.style.color="blue";
	}
}

function createlink(s){
  var sel = s;
  if (sel == null) return;

  // replace the text selection
  var szText = sel.text;
  szText = "<a href=\"PLACEHOLDER\" target=_blank title=\"Open in a new window\">" + 
           szText + "[^]</a>";
  sel.text = szText;

  // replace anchor placeholder with clipboard content
  var r = document.all["body"].createTextRange();
  r.findText("PLACEHOLDER");
  r.select();
  r.execCommand("Paste"); // Internet Explorer only
}

function urlencode(string) {
	return escape(_utf8_encode(string));
}

function urldecode(string) {
	return _utf8_decode(unescape(string));
}

function _utf8_encode(string) {
	string = string.replace(/\r\n/g,"\n");
	var utftext = "";

	for (var n = 0; n < string.length; n++) {

		var c = string.charCodeAt(n);

		if (c < 128) {
			utftext += String.fromCharCode(c);
		}
		else if((c > 127) && (c < 2048)) {
			utftext += String.fromCharCode((c >> 6) | 192);
			utftext += String.fromCharCode((c & 63) | 128);
		}
		else {
			utftext += String.fromCharCode((c >> 12) | 224);
			utftext += String.fromCharCode(((c >> 6) & 63) | 128);
			utftext += String.fromCharCode((c & 63) | 128);
		}

	}

	return utftext;
}

function _utf8_decode(utftext) {
	var string = "";
	var i = 0;
	var c = c1 = c2 = 0;

	while ( i < utftext.length ) {

		c = utftext.charCodeAt(i);

		if (c < 128) {
			string += String.fromCharCode(c);
			i++;
		}
		else if((c > 191) && (c < 224)) {
			c2 = utftext.charCodeAt(i+1);
			string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
			i += 2;
		}
		else {
			c2 = utftext.charCodeAt(i+1);
			c3 = utftext.charCodeAt(i+2);
			string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
			i += 3;
		}

	}

	return string;
}