/**
* gets the browser scroll position
*/
function getScrollPosition() {
var scrollTop = document.body.scrollTop; // works for IE but not firefox
// alert(scrollTop);
if (scrollTop == undefined || scrollTop == 0) {
scrollTop = window.pageYOffset; // works for firefox but not IE
}
//	alert("scrollTop2:" + scrollTop);
return scrollTop;
}
/**
* Sets the browser scroll position
*/
function setScrollPosition(scrollTop) {
//window.scrollTo(0, scrollTop);
}
/**
* String replace without regular expression. This is to circumvent the regular expression
* processing in the String.replace() function. For example trying to replace "$ALERT_INTERVAL$" with "4"
* would not work with String.replace().
* 
* @param s the source string
* @param p1 the pattern to replace
* @param p2 the patter to replace with
* @return the result
*/
function stringReplace(s, p1, p2)
{
if (s == null || p1 == null) return s;
var result = s;
var index = s.indexOf(p1);
if (index > 0) {
if (p2 != null)
result = s.substring(0, index) + p2 + s.substring(index + p1.length);
else
result = s.substring(0, index) + s.substring(index + p1.length);
} 
return result;
}
/**
* Collects the selected checkbox values of a given warName into an array
*/
function getCheckboxArray(varName)
{
var result = new Array();
$.each($("input[name=" + varName + "]:checked"), function() {
result.push($(this).val());
});
return result;
}
function replaceAll(Source,stringToFind,stringToReplace){
var temp = Source;
var index = temp.indexOf(stringToFind);
while(index != -1){
temp = temp.replace(stringToFind,stringToReplace);
index = temp.indexOf(stringToFind);
}
return temp;
}
/**
* Detect whether the data returned by an ajax call is the login page.
* This can happen when session timeout, or illegal access.
* 
* @param data - the data returned by the ajax call.
*/
function isLoginPage(data)
{
return (data.indexOf("__Login Page Marker__") > 0);
}
/**
* Detect whether the data returned by an ajax call is the userHome page.
* This can happen when illegal access to some page.
* 
* @param data - the data returned by the ajax call.
*/
function isUserHomePage(data)
{
return (data.indexOf("__UserHome Page Marker__") > 0);
}
/**
* Hide or show the section of AreaOfExpertise for user profile
*/
function show_section(no) {
$('#content_section'+no).show();
}
function hide_section(no) {
$('#content_section'+no).hide();
}
/**
* Forward to viewOtherUserProfile.jsp
*/
function viewOtherUserProfile(userId) {
window.location ="otherUserProfile.action?userId="+userId;
}
function showSuccessMsgDialog(msg) {
$('#systemMessage div.success').slideDown(300);
$('#systemMessage div.success p').text(msg);
$('#systemMessage').focus();
$('#systemMessage div.success').delay(5000).slideUp(500);
}
function showErrorMsgDialog(msg) {
$('#systemMessage div.error').slideDown(300);
$('#systemMessage div.error p').text(msg);
$('#systemMessage').focus();
}
//Use this if the action is called by ajax
//If using ajax, the message will not show bcoz baseLayout is not reloaded
function getMessageFromCookie() {
if ($.cookie('_message') != null) {
message = replaceAll($.base64Decode($.cookie('_message')),"\"","");
/**
$.alerts.dialogClass = 'message';
jAlert(message, 'Success Message', function() {
$.alerts.dialogClass = null; // reset to default
});*/
$('#systemMessage div.success').slideDown(300);
$('#systemMessage div.success p').text(message);
$('#systemMessage').focus();
$.cookie('_message', null); // clears the cookie
$('#systemMessage div.success').delay(5000).slideUp(500);
}
if ($.cookie('_error_message') != null) {
message = replaceAll($.base64Decode($.cookie('_error_message')),"\"","");
/**
$.alerts.dialogClass = 'error_message';
jAlert(message, 'Error Message', function() {
$.alerts.dialogClass = null; // reset to default
});*/
$('#systemMessage div.error').slideDown(300);
$('#systemMessage div.error p').text(message);
$('#systemMessage').focus();
$.cookie('_error_message', null); // clears the cookie
}
}
function urlEncode (str) {
// URL-encodes string 
// 
// version: 1109.2015
// discuss at: http://phpjs.org/functions/urlencode
// + 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)
// + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + 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
// + reimplemented by: Brett Zamir (http://brett-zamir.me)
// + bugfixed by: Joris
// + reimplemented by: Brett Zamir (http://brett-zamir.me)
// % note 1: This reflects PHP 5.3/6.0+ behavior
// % note 2: Please be aware that this function expects to encode into UTF-8 encoded strings, as found on
// % note 2: pages served as UTF-8
// * example 1: urlencode('Kevin van Zonneveld!');
// * returns 1: 'Kevin+van+Zonneveld%21'
// * example 2: urlencode('http://kevin.vanzonneveld.net/');
// * returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
// * example 3: urlencode('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');
// * returns 3: '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'
str = (str + '').toString();
// Tilde should be allowed unescaped in future versions of PHP (as reflected below), but if you want to reflect current
// PHP behavior, you would need to add ".replace(/~/g, '%7E');" to the following.
return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}
