/**
*  Good-to-have function when debugging ajax callbacks
*/
function alertFromPhp (phpString) {
	alert(phpString);
	return true;
}
/**
* Silencer function used for ajaxcallbacks
*/
function silence (param) {
	return true;
}
/**
* Forwarding function used for ajaxcallbacks
*/
function forwardFromPhp (p_sUrl) {
	document.location = p_sUrl;
	return true;
}
/**
* Reload function used for ajaxcallbacks
*/
function ajaxReload () {
	window.location.reload();
	return true;
}
/**
* General phpdata handling function used for ajaxcallbacks
*/
function generalPhpHandler (phpData) {
	var aResult = phpData.split("||");
	var aStatus = aResult[0].split("|");
	if (aStatus[1] == "1") {
		window.location.reload();
	} else {
		var aNewHtml = aResult[1].split("|");
		document.getElementById(aNewHtml[0]).style.display = 'block';
		document.getElementById(aNewHtml[0]).innerHTML = aNewHtml[1];
	}
	return true;
}
/**
* Function invoked when clicking on a show/hide gallery icon, does in turn make an ajaxcall
*/
function showHideGallery (p_iTargetNo) {
	var funcName = 'showHideGalleries_' + p_iTargetNo;
	window[funcName]();
}
/**
* Function invoked when clicking on a show/hide image icon, does in turn make an ajaxcall
*/
function showHideImage (p_iTargetNo) {
	var funcName = 'showHideImages_' + p_iTargetNo;
	window[funcName]();
}
/**
* Function invoked when clicking on a show/hide image icon, does in turn make an ajaxcall
*/
function showHideNews (p_iTargetNo) {
	var funcName = 'showHideNews_' + p_iTargetNo;
	window[funcName]();
}
/**
* Function to return updated text from php via ajaxcallbacks
*/
function returnFromPhp (p_sData) {
	var mValue = p_sData;
	if (0 == mValue) {
		alert('There was an error when updating');
	} else {
		aResult = mValue.split("|");
		document.getElementById(trim(aResult[0], ' ')).innerHTML = aResult[1];
	}
	return true;
}
/**
* Function for icon/value toggling
*/
function toggleSelect(obj, obj2, p_aTitles) {
	var sel = document.getElementById(obj);
	var btn = document.getElementById(obj2);
	var aTitle = p_aTitles.split(',');
	if ( sel.innerHTML != 1 ) {
		sel.innerHTML = 1;
		btn.className ="icon_show_yes";
		btn.title = aTitle[1];
	} else {
		sel.innerHTML = 0;
		btn.className ="icon_show_no";
		btn.title = aTitle[0];
	}
	return true;
};

function hideLink() {

}


function openAd() {
	$("#popup").draggable({
		handle: "#popup_drag_handle"
	});
	document.getElementById("popup").style.display="block";
	document.getElementById("popup").style.top="25%";
	document.getElementById("popup").style.left="45%";
}
function closeAd() {
	document.getElementById("popup").style.display="none";
	document.getElementById("popup").style.top="-1000";
	document.getElementById("popup").style.left="-1000";
}
/**
*  Sets the visibility to "hidden" for the given DOM element
*/
function makeInVisibleJs (elemToVisible) {
	document.getElementById(elemToVisible).style.visibility = "hidden";

	return true;
}

/**
* Some great utility functions that are taken from the php to js project - http://kevin.vanzonneveld.net
*/
function str_replace(search, replace, subject) {
	var f = search, r = replace, s = subject;
	var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;

	while (j = 0, i--) {
		if (s[i]) {
			while (s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
		}
	};

	return sa ? s : s[0];
}

function strpos( haystack, needle, offset){
	var i = (haystack+'').indexOf( needle, offset );
	return i===-1 ? false : i;
}
function trim (str, charlist) {
	var whitespace, l = 0, i = 0;
	str += '';

	if (!charlist) {
		// default list
		whitespace = " \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000";
	} else {
		// preg_quote custom list
		charlist += '';
		whitespace = charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
	}

	l = str.length;
	for (i = 0; i < l; i++) {
		if (whitespace.indexOf(str.charAt(i)) === -1) {
			str = str.substring(i);
			break;
		}
	}

	l = str.length;
	for (i = l - 1; i >= 0; i--) {
		if (whitespace.indexOf(str.charAt(i)) === -1) {
			str = str.substring(0, i + 1);
			break;
		}
	}

	return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}
