/*******************************************************************************
 * Dynamic Ajax Content- � Dynamic Drive DHTML code library
 * (www.dynamicdrive.com) This notice MUST stay intact for legal use Visit
 * Dynamic Drive at http://www.dynamicdrive.com/ for full source code
 ******************************************************************************/

var bustcachevar = 0 // bust potential caching of external pages after
// initial
// request? (1=yes, 0=no)
var loadedobjects = "";
var rootdomain = window.location.protocol + window.location.hostname;
var bustcacheparameter = "";
var pageanchor = "";
var callDomainCollapse = true;
// function ajaxpage(url, containerid, synchronous, user, password) {
// // alert('1 ' + 'url ' + url + ' containerid ' + containerid );
// AjaxRequest.get({
// 'url' : url,
// 'async' : true,
// 'username' : user,
// 'password' : password,
// 'onLoading' : function(req) {
// alert('onLoading ' + containerid);
// },
// 'onLoaded' : function(req) {
// alert('onLoaded ' + containerid);
// },
// 'onInteractive' : function(req) {
// alert('onInteractive ' + containerid);
// },
// 'onSuccess' : function(req) {
// // alert('2 ' + 'url ' + url + ' containerid ' + containerid );
// // var selector = "#" + containerid;
// // var s = req.responseText;
// // alert($(selector));
// // $(selector).html(s);
// // toInsert.push(req.responseText);
// // if (toInsert.length == 1) {
// // document.getElementById(containerid).innerHTML =
// // req.responseText;
// // toInsert.pop();
// // }
// // return;
// document.getElementById(containerid).innerHTML = req.responseText;
// if (req.responseText.indexOf("registar.css")) {
// lregcss = true;
// }
// document.getElementById(containerid).scrollTop = 0;
// loadImages(url, containerid);
// changeLinks(url, containerid);
// setCurrentDocUrl(url, containerid);
// if (prepareAnchor(containerid)) {
// anchorPage();
// }
// if (url.indexOf("/cover.htm") != -1) {
// dc.setRequestParameters(url.split('cover.htm')[0], synchronous,
// user, password);
// // evaluate script
// var script = document.getElementById("scripteval");
// if (script != null) {
// eval(script.text);
// }
// }
// alert('outsucces ' + containerid);
// },
// 'onError' : function(req) {
// alert('Error!\nStatusText=' + req.statusText + '\nContents='
// + req.responseText);
// },
// 'onTimeout' : function(req) {
// alert('Timed Out!');
// }
// });
// alert('out' + containerid);
// }

function ajaxpage(url, containerid, synchronous, user, password) {
	var page_request = false
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject) { // if IE
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} catch (e) {
			try {
				page_request = new ActiveXObject("Microsoft.XMLHTTP")
			} catch (e) {
			}
		}
	} else
		return false
	page_request.onreadystatechange = function() {
		loadpage(page_request, containerid, url, synchronous, user, password);
	}
	if (bustcachevar) // if bust caching of external page
		bustcacheparameter = (url.indexOf("?") != -1) ? "&"
				+ new Date().getTime() : "?" + new Date().getTime()
		/** DEMO * */
		/*
		 * DEMO commented var auth = make_base_auth(user, password);
		 */
	var auth = make_base_auth('removeme', 'removeme');
	/** * */
	if (synchronous == "false")
		page_request.open('GET', url + bustcacheparameter, false);
	else
		page_request.open('GET', url + bustcacheparameter, true);
	page_request.setRequestHeader("Authorization", auth);
	// page_request.setRequestHeader("ContentType", "text/xml");
	// page_request.setRequestHeader("Accept",
	// "text/xml,text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
	page_request.send(null);
}

function loadpage(page_request, containerid, url, synchronous, user, password) {
//	 alert('url ' + url);
	// alert('page_request.readyState ' + page_request.readyState);
	if (page_request.readyState == 4
			&& (page_request.status == 200 || window.location.href
					.indexOf("http") == -1)) {
		document.getElementById(containerid).innerHTML = page_request.responseText;
		// alert('containerid ' + containerid + "CONTENT " +
		// document.getElementById(containerid).innerHTML);
		// alert('Test poruka : IE10 related > ucitao stranicu ' +
		// page_request.responseText + ' u innerHTML');
		// TODO use responseXML. responseText is used because the ContentType is
		// text/html.
		// In order to use responseXML ContentType needs to be text/xml for
		// server response.
		// setTimeout(function() {
		if (page_request.responseText.indexOf("registar.css")) {
			lregcss = true;
		}
		document.getElementById(containerid).scrollTop = 0;
		loadImages(url, containerid);
		changeLinks(url, containerid);
		setCurrentDocUrl(url, containerid);

		if (url.indexOf("/cover.htm") != -1) {
			// alert('Cover.htm');
			// TODO hack hack hack, remove to wca
			$( ".clickme" ).click(function() {
				  $(this).next(".lista").slideToggle(500);
			});
			var elmts = document.getElementsByName('favs1');
			if (elmts && elmts[0]) {
				elmts[0].onchange = function() {
					jQuery.cookie('nwUrl', url.substring(0, url
							.lastIndexOf('/') + 1)
							+ this.options[this.selectedIndex].value);
					window.open('newWindow.jsf', '', '');
					return false;
				};
			}
			/** DEMO * */
			/*
			 * DEMO commented dc.setRequestParameters(url.split('cover.htm')[0],
			 * synchronous, user, password);
			 */
			dc.setRequestParameters(url.split('cover.htm')[0], synchronous,
					'removeme', 'removeme');
			/** * */
//			// evaluate script
//			var script = document.getElementById("scripteval");
//			if (script != null) {
//				eval(script.text);
//			}
//			return;
		} else {
			if (prepareAnchor(containerid)) {
				anchorPage();
			}
		}

		// execute "scripteval" id-ed script code that is inserted as DOM text.
		var script = document.getElementById("scripteval");
		if (script != null) {
			eval(script.text);
		}

		// execute "scripteval" class-ed script code that is inserted as DOM text.
		$('.scripteval').each(function(){
//			alert('scripteval');
			eval($(this).text());
		});
	}
}

function loadobjs() {
	if (!document.getElementById) {
		return;
	}

	for (i = 0; i < arguments.length; i++) {
		var file = arguments[i]
		var fileSplit = file.split('/');
		var fileref = "";
		if (loadedobjects.indexOf(fileSplit[fileSplit.length - 1]) == -1) { // Check
			// to
			// see
			// if
			// this
			// object
			// has
			// not
			// already been added to page before
			// proceeding
			if (file.indexOf(".js") != -1) { // If object is a js file
				fileref = document.createElement('script')
				fileref.setAttribute("type", "text/javascript");
				fileref.setAttribute("src", file);
			} else if (file.indexOf(".css") != -1) { // If object is a css
				// file
				fileref = document.createElement("link");
				fileref.setAttribute("id", fileSplit[fileSplit.length - 1]);
				fileref.setAttribute("rel", "stylesheet");
				fileref.setAttribute("type", "text/css");
				fileref.setAttribute("href", file);
			}
		}
		if (fileref != "") {
			document.getElementsByTagName("head").item(0).appendChild(fileref)
			loadedobjects += fileSplit[fileSplit.length - 1] + " " // Remember
			// this
			// object as
			// being
			// already
			// added to
			// page
		}
	}
}

function deleteCssObj(id) {
	var elementToDelete = document.getElementById(id);
	if (elementToDelete != null) {
		elementToDelete.parentNode.removeChild(elementToDelete);
		var loadedobjectsSplit = loadedobjects.split(' ');
		var temp = "";
		for (l = 0; l < loadedobjectsSplit.length; ++l) {
			if (loadedobjectsSplit[l] != id) {
				temp += " " + loadedobjectsSplit[l];
			}
		}
		loadedobjects = temp;
	}
}

function setcook(user, password) {
	var toSet = user + ";";
	var toSet = toSet + password;
	jQuery.cookie('wpfRepSec', toSet);
}

function getcook() {
	return jQuery.cookie('wpfRepSec');
}

var lregcss = null;

function loadajaxpage(url, containerid, synchronous, user, password) {
	setcook(user, password);
	var selectorMain = "#" + containerid;
	removeClonedContent();
	if (jQuery(selectorMain).length > 0) {
		if (url.indexOf("/cover.htm") != -1) {
			deleteCssObj('paragraf.css');
			deleteCssObj('registar.css');
//			loadobjs('/documents/editorial/style/webstyle.css');
//			loadobjs('/documents/editorial/style/colour.css');
			loadobjs('/demo/documents/editorial/style/web_templatemo_style.css');
			loadobjs('/demo/documents/editorial/style/tabcontent.css');
			loadobjs('/demo/documents/editorial/style/flexslider.css');
		} else {
			loadobjs('../demo/documents/Old/paragraf.css');
			if (lregcss == true) {
				loadobjs('../demo/documents/Old/registar.css');
				lregcss = false;
			}
		}

		ajaxpage(url, containerid, synchronous, user, password);
	}

	bindToCaptureSelectAll(containerid);
}

function loadajaxpageForTabAbout(url, containerid, synchronous, user, password) {
	setcook(user, password);
	var selectorMain = "#" + containerid;
	if (jQuery(selectorMain).length > 0) {
		removeClonedContent();
		ajaxpage(url, containerid, synchronous, user, password);
		loadobjs('../demo/documents/Old/paragraf.css');
		if (lregcss == true) {
			loadobjs('../demo/documents/Old/registar.css');
			lregcss = false;
		}
	}
	/*
	 * sendEventForSelectionRestoreInsideTheSameFrame();
	 * sendEventForSelectionRestore();
	 */
	bindToCaptureSelectAll(containerid);
}

function loadPageExtension(url, containerid) {
	var tSetStr = getcook();
	var tSet = tSetStr.split(";");
	ajaxpage(url, containerid, true, tSet[0], tSet[1]);
	loadobjs('../demo/documents/Old/paragraf.css');
	if (lregcss == true) {
		loadobjs('../demo/documents/Old/registar.css');
		lregcss = false;
	}
}

function loadHtmlPage(url, containerid, synchronous, user, password) {
	setcook(user, password);
	var selectorMain = "#" + containerid;

	if (jQuery(selectorMain).length > 0) {
		if (url.indexOf("/cover.htm") != -1) { // pages other then home page
			// MUST NOT have cover in their
			// url path
			deleteCssObj('paragraf.css');
			deleteCssObj('registar.css');
//			loadobjs('/documents/editorial/style/webstyle.css');
//			loadobjs('/documents/editorial/style/colour.css');
			loadobjs('/demo/documents/editorial/style/web_templatemo_style.css');
			loadobjs('/demo/documents/editorial/style/tabcontent.css');
			loadobjs('/demo/documents/editorial/style/flexslider.css');
		} else {
			loadobjs('../demo/documents/Old/paragraf.css');
			if (lregcss == true) {
				loadobjs('../demo/documents/Old/registar.css');
				lregcss = false;
			}
		}

		if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) // test for
		// Firefox/x.x
		// or
		// Firefox
		// x.x
		// (ignoring
		// remaining
		// digits);
		{
			var ffversion = new Number(RegExp.$1); // capture x.x portion and
			// store as a number
			if (ffversion >= 2) {
				ajaxpage(url, containerid, true, user, password);
			}
		} else {
			ajaxpage(url, containerid, synchronous, user, password);
		}
	}

	bindToCaptureSelectAll(containerid);
}

function loadpagefromsubtitle(url, containerid, synchronous) {
	var tSetStr = getcook();
	var tSet = tSetStr.split(";");
	var selectorMain = "#" + containerid;
	if (jQuery(selectorMain).length > 0) {
		if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) // test for
		// Firefox/x.x
		// or
		// Firefox
		// x.x
		// (ignoring
		// remaining
		// digits);
		{
			var ffversion = new Number(RegExp.$1); // capture x.x portion and
			// store as a number
			if (ffversion >= 2) {
				ajaxpage(url, containerid, true, tSet[0], tSet[1]);
			}
		} else {
			ajaxpage(url, containerid, synchronous, tSet[0], tSet[1]);
		}
		loadobjs('../demo/documents/Old/paragraf.css');
		if (lregcss == true) {
			loadobjs('../demo/documents/Old/registar.css');
			lregcss = false;
		}
	}
	/*
	 * sendEventForSelectionRestoreInsideTheSameFrame();
	 * sendEventForSelectionRestore();
	 */
	bindToCaptureSelectAll(containerid);
}

function loadajaxpageFodDocAboutInfoPrint(url, containerid, synchronous, user,
		password) {
	/* if (jQuery('#aboutDocumentContent').is(':empty')) { */
	removeClonedContent();
	ajaxpage(url, containerid, synchronous, user, password);
	loadobjs('../demo/documents/Old/paragraf.css');
	if (lregcss == true) {
		loadobjs('../demo/documents/Old/registar.css');
		lregcss = false;
	}
	bindToCaptureSelectAll(containerid);

	/*
	 * ajaxpage(url, containerid); loadobjs('../../documents/Old/paragraf.css');
	 *
	 * ajaxpage(url, containerid); loadobjs('../../documents/Old/paragraf.css');
	 *
	 * ajaxpage(url, containerid); loadobjs('../../documents/Old/paragraf.css');
	 *
	 * ajaxpage(url, containerid); loadobjs('../../documents/Old/paragraf.css'); }
	 * sendEventForSelectionRestoreInsideTheSameFrame();
	 * sendEventForSelectionRestore();
	 */
}

function loadajaxpageForPrint(url, containerid, synchronous) {
	var tSetStr = getcook();
	var tSet = tSetStr.split(";");
	removeClonedContent();
	ajaxpage(url, containerid, synchronous, tSet[0], tSet[1]);
	loadobjs('../demo/documents/Old/paragraf.css');
	if (lregcss == true) {
		loadobjs('../demo/documents/Old/registar.css');
		lregcss = false;
	}
	bindToCaptureSelectAll();
}

function loadajaxpageForPrintExtended(url, containerid, synchronous) {
	var tSetStr = getcook();
	var tSet = tSetStr.split(";");
	ajaxpage(url, containerid, synchronous, tSet[0], tSet[1]);
	loadobjs('../demo/documents/Old/paragraf.css');
	if (lregcss == true) {
		loadobjs('../demo/documents/Old/registar.css');
		lregcss = false;
	}
}

/*
 * function loadajaxpageForTabAbout(url, containerid){ if
 * (jQuery(containerid).is(':empty')) { ajaxpage(url, containerid);
 * loadobjs('../../documents/Old/paragraf.css'); }
 * sendEventForSelectionRestoreInsideTheSameFrame();
 * sendEventForSelectionRestore(); }
 */

function loadajaxpageForNewWindow() {
	var url = jQuery.cookie('nwUrl');
	var tSetStr = getcook();
	var tSet = tSetStr.split(";");
	// alert('tset[0]' + tSet[0]);
	// alert('tset[1]' + tSet[1]);
	// alert('urlfornewwindow' + url);
	if (url== 'http://demo.paragraf.rs/demo/combined_cyr/editorial/cover.htm'){
		alert('Početna stranica nije predviđena za preslovljavanje!');
		window.close();
	}
	ajaxpage(url, "newContent", "true", tSet[0], tSet[1]);

	loadobjs('../demo/documents/Old/paragraf.css');
	if (lregcss == true) {
		loadobjs('../demo/documents/Old/registar.css');
		lregcss = false;
	}
}

function loadImages(url, containerId) {
	// var urlSplit = url.split('/');
	var baseurl = url.substring(0, url.lastIndexOf('/'));
	var imgs = document.getElementById(containerId).getElementsByTagName('img');
	for ( var i = 0; i < imgs.length; i++) {
		var oldSrc = imgs[i].src;
		var context = window.location.pathname.split('/')[1];
		if (oldSrc.indexOf(context) != -1) {// most probably only for editorial
			// pages
			imgs[i].src = baseurl + oldSrc.split(context)[1];
		}
		// var oldSrcSplit = oldSrc.split('/');
		// var target = urlSplit[0];
		// build url from server domain (protocol, host, port) and partial
		// document path
		// if (urlSplit[urlSplit.length - 3] == "modeli") {
		// for ( var j = 1; j < urlSplit.length - 2; j++)
		// target = target + "/" + urlSplit[j];
		// } else {
		// for ( var j = 1; j < urlSplit.length - 1; j++)
		// target = target + "/" + urlSplit[j];
		// }
		// build img src url
		// get img document relative path
		// var context = window.location.pathname.split('/')[1];
		// if (oldSrc.indexOf(context) != -1) {// most probably only for
		// editorial pages
		// target += oldSrc.split(context)[1];
		// }
		// else{ // for all other documents
		// alert(target);
		// alert("Obavestite razvojni tim o ovoj poruci");
		// target = target + "/" + oldSrcSplit[oldSrcSplit.length - 1];
		// }
	}
}

function changeLinksForAuthorization(element, url, link) {
	var newurl = url.substring(0, url.lastIndexOf('/') + 1) + link;
	element.href = "javascript:;";
	element.title = newurl;
	element.className = "rcdis";
	element.onclick = function() {
		jQuery.cookie('nwUrl', newurl);
		window.open('newWindow.jsf', '', '');
		return false;
	};
}

function openInNewWindow(newurl) {
	jQuery.cookie('nwUrl', newurl);
	window.open('newWindow.jsf', '_blank');
	window.focus();
	return false;
}

function changeLinks(url, containerId) {
	//alert('url ' + url);
	var links = document.getElementById(containerId).getElementsByTagName('a');
	for ( var i = 0; i < links.length; i++) {
		var str = links[i].innerHTML;
		var element = links[i];
		var wpfTrget = jQuery(element).attr('target');
		var wpfHref = jQuery(element).attr('href');
		// if (str.indexOf("Napomena") != -1 || str.indexOf("Nazad") != -1) {
		// // if (str.indexOf("Slede") != -1 || str.indexOf("Prethodni") != -1
		// // || str.indexOf("Napomena") != -1 || str.indexOf("Nazad") != -1) {
		// var oldHref = element.href;
		// var urlSplit = url.split("/");
		// var oldHrefSplit = oldHref.split("/");
		// var target = urlSplit[0];
		// for ( var j = 1; j < urlSplit.length - 1; j++)
		// target = target + "/" + urlSplit[j];
		// target = target + "/" + oldHrefSplit[oldHrefSplit.length - 1];
		// element.href = target;
		// var extension = oldHrefSplit[oldHrefSplit.length - 1];
		// var pattern = /e[0-9]*/;
		// var match = pattern.exec(extension);
		//
		// if (str.indexOf("Slede") != -1)
		// element.id = "sledeci" + match;
		// if (str.indexOf("Prethodni") != -1)
		// element.id = "prethodni" + match;
		// element.onclick = function() {
		// loadajaxpageForPrint(this.href, containerId, "true");
		// return false;
		// };
		// }
		// only relative links
		if (wpfHref && wpfHref.substring(0, 1) !== '#'
				&& wpfHref.indexOf('http:') == -1
				&& wpfHref.indexOf('https:') == -1
				&& wpfTrget
				&& wpfTrget.indexOf("_blank") != -1) {
			changeLinksForAuthorization(element, url, wpfHref);
		}

		if (str.indexOf("Menjanje komentara korisnika") != -1) {
			document.getElementById(containerId).getElementsByTagName("a")[i].onclick = clickHiddenLink;
			document.getElementById(containerId).getElementsByTagName("a")[i].className = 'userEditClass';
			updUsrCommnt();
		}
	}
	
	var options = document.getElementById(containerId).getElementsByTagName('option');
	
	for ( var i = 0; i < options.length; i++) {
		var option = options[i];
		var value = jQuery(option).attr('value');
		// only relative links
		if (value && value.substring(0, 1) !== '#'
				&& value.indexOf('http:') == -1
				&& value.indexOf('https:') == -1) {
			changeLinksForAuthorization(option, url, value);
		}
	}
	
//	var selects = document.getElementById(containerId).getElementsByTagName('select');
//	//HACK FOR COVER
//	for ( var i = 0; i < selects.length; i++) {
//		selects[i].onchange= function() {
//			var optValue = this.options[this.selectedIndex].value;
//			if (optValue &&
//					(optValue.indexOf('http:') != -1 ||
//							optValue.indexOf('https:') != -1)) {
//				window.open(optValue);
//			} else
//				return;
//		};
//	}
	
    var selects = document.getElementById(containerId).getElementsByTagName(
    'select');
    // HACK FOR COVER
    for (var i = 0; i < selects.length; i++) {
    	if (selects[i].className === 'sadrzaj') {// select on archive pages just for anchoring
    		break;
    	}

    	selects[i].onchange = function() {
    		var optValue = this.options[this.selectedIndex].value;

    		if (optValue && optValue.substring(0, 1) !== '#'
    			&& optValue.indexOf('http:') == -1
    			&& optValue.indexOf('https:') == -1) {
    			var newurl = url.substring(0, url.lastIndexOf('/') + 1)
    			+ optValue;
    			jQuery.cookie('nwUrl', newurl);
    			window.open('newWindow.jsf', '', '');
    		} else {
    			window.open(optValue);
    		}
    	};
    }
}

function loadpart() {
	loadajaxpageForPrint(this.href, mainDocContainer(), "true");
	return false;
}

function initTabs() {
	WPFTSR.initialize(new YAHOO.widget.TabView('mainForm:tabs'));
}

function setCurrentDocUrl(url, containerId) {
	// 2in1
	// if (containerId == "staticContent" || containerId ==
	// "dCurrentDocContent")
	// document.getElementById('mainForm:hidCurrentDocUrl').innerHtml = url;
	if (containerId == "wpfCurrentDocument"
			|| document.getElementById(containerId).parentNode.id == "wpfCurrentDocument")
		document.getElementById('mainForm:hidCurrentDocUrl').innerHtml = url;
	//
}

function setPageAnchor(anc) {
	if (jQuery.browser.msie) {
		pageanchor = anc.replace(/[\[]/g, "%5B");
		pageanchor = pageanchor.replace(/[\]]/g, "%5D");
	} else
		pageanchor = anc;
}

function anchorPage() {
	if (pageanchor != "") {
		window.location.hash = pageanchor;
		pageanchor = "";
	}
}
function prepareAnchor(contid) {
	// 2in1
	// if (contid == "staticContent" || contid == "dCurrentDocContent") {
	if (contid == "wpfCurrentDocument"
			|| document.getElementById(contid).parentNode.id == "wpfCurrentDocument") {
		if (pageanchor.indexOf("str_", 0) != -1) {
			return true;
		}
		// 2in1
		// if ((pageanchor.indexOf("clan_", 0) != -1)
		// && !(jQuery("#dRelatedDocContent").length > 0)) {
		// return true;
		// }
		if ((pageanchor.indexOf("clan_", 0) != -1)
				&& !(jQuery("#wpfRelatedDocument").length > 0)) {
			return true;
		}
		//

	}
	// 2in1
	// if (contid == "dRelatedDocContent") {
	if (contid == "wpfRelatedDocument") {
		if (pageanchor.indexOf("clan_", 0) != -1) {
			if (replaceAnchor(pageanchor, "par" + pageanchor)) {
				pageanchor = "par" + pageanchor;
				return true;
			}
		}
	}
	return false;
}

jQuery(document).bind('loadData', function() {
	var url = document.getElementById("newWindowForm:hiddenURL").value;
	var containerid = "newContent";
	/* if(jQuery.browser.msie){ */
	loadajaxpageForPrintExtended(url, containerid, "true");
	/*
	 * } else{ jQuery('#newContent').load(url); }
	 */
});

function someclicku() {
	var event = new jQuery.Event('loadData');
	jQuery(document).trigger('loadData');
}

function make_base_auth(user, password) {
	var tok = user + ':' + password;
	var hash = Base64.encode(tok);
	return "Basic " + hash;
}

function changeLinksForIFrame() {

	var tSetStr = getcook();
	var tSet = tSetStr.split(";");

	var responseText = jQuery.ajax({
		url : "/demo/documents/editorial/cover.htm",
		context : document.body,
		username : tSet[0],
		password : tSet[1],
		async : false,
		statusCode : {
			404 : function() {
				alert('page not found');
			}
		}
	});
	if (responseText.status == 404) {
		parent.location.reload();
		return false;
	}
}

/**
 * Self executing function for adding tooltips
 */
var WPFTOOLTIP = (function(window, $) {
	var STATIC_TIPS = {// should be short
		tip1 : 'This tooltip contains plain text',
		tip2 : 'This tooltip has some <b>bold</b> and <i>italic</i> <b><i>text</b></i>',
		tip3 : 'This tooltip has <br> text in new line',
		tip4 : 'This tooltip provides <a href="https://www.paragraf.rs">a link to paragraf web site</a>',
		tip5 : 'This tooltip has image <br> <img src="/demo/documents/editorial/kutak/images/ico2.png"/>',
		tip6 : '<p style="background:#FFFFFF">This tooltip has white background</p>',
		tip7 : '<div style="overflow:auto; width: 70px; height:100px">'
			+ '<p>This tooltip is so long that it must be scrolled in order to be read.'
			+ 'I do not like long tooltips. And I do not like scrolling.</p></div>',
		tip8 : 'I can even play some flash <br>'
			+ '<object width="400" height="40"	classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"'
			+ ' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">'
			+ '	<param name="SRC" value="bookmark.swf">'
			+ '	<embed src="/banner/Car-speakers-590x90.swf" width="400" height="40"></embed>'
			+ '	</object> '
	};
	// Add tooltips
	$(document).ready(function() {
		//addtips();
	});
	
	var addtips = function() {
		//alert('1');
		addStaticTooltip($("#mainForm\\:tbLContentLbl"), '<a href="http://demo.paragraf.rs/demo/documents/editorial/tooltip/t_sadrzaj.html" target="_blank" class="naslov1"><img src="http://demo.paragraf.rs/demo/documents/editorial/tooltip/questionMark.png" alt="Pomo&#x0107; za tab SADR&#x017d;AJ" width="16" height="16" /> Pomo&#x0107; za tab SADR&#x017d;AJ</a>');
		addStaticTooltip($("#mainForm\\:tbLPublisherLbl"), '<a href="http://demo.paragraf.rs/demo/documents/editorial/tooltip/t_glasila.html" target="_blank" class="naslov1"><img src="http://demo.paragraf.rs/demo/documents/editorial/tooltip/questionMark.png" alt="Pomo&#x0107; za tab SADR&#x017d;AJ" width="16" height="16" /> Pomo&#x0107; za tab GLASILA</a>');
		addStaticTooltip($("#mainForm\\:tbLBiltenLbl"), '<a href="http://demo.paragraf.rs/demo/documents/editorial/tooltip/t_bilteni.html" target="_blank" class="naslov1"><img src="http://demo.paragraf.rs/demo/documents/editorial/tooltip/questionMark.png" alt="Pomo&#x0107; za tab SADR&#x017d;AJ" width="16" height="16" /> Pomo&#x0107; za tab BILTENI</a>');
		addStaticTooltip($("#mainForm\\:tbLEPressLbl"), '<a href="http://demo.paragraf.rs/demo/documents/editorial/tooltip/t_casopisi.html" target="_blank" class="naslov1"><img src="http://demo.paragraf.rs/demo/documents/editorial/tooltip/questionMark.png" alt="Pomo&#x0107; za tab SADR&#x017d;AJ" width="16" height="16" /> Pomo&#x0107; za tab &#x010c;ASOPISI</a>');
		addStaticTooltip($("#mainForm\\:tbLFavoritesLbl"), '<a href="http://demo.paragraf.rs/demo/documents/editorial/tooltip/t_favoriti.html" target="_blank" class="naslov1"><img src="http://demo.paragraf.rs/demo/documents/editorial/tooltip/questionMark.png" alt="Pomo&#x0107; za tab SADR&#x017d;AJ" width="16" height="16" /> Pomo&#x0107; za tab FAVORITI</a>');
		addStaticTooltip($("#mainForm\\:tbLSearchLbl"), '<a href="http://demo.paragraf.rs/demo/documents/editorial/tooltip/t_pretraga.html" target="_blank" class="naslov1"><img src="http://demo.paragraf.rs/demo/documents/editorial/tooltip/questionMark.png" alt="Pomo&#x0107; za tab SADR&#x017d;AJ" width="16" height="16" /> Pomo&#x0107; za tab PRETRAGA</a>');
		addStaticTooltip($("#mainForm\\:tbLRelationsLbl"), '<a href="http://demo.paragraf.rs/demo/documents/editorial/tooltip/t_relacije.html" target="_blank" class="naslov1"><img src="http://demo.paragraf.rs/demo/documents/editorial/tooltip/questionMark.png" alt="Pomo&#x0107; za tab SADR&#x017d;AJ" width="16" height="16" /> Pomo&#x0107; za tab RELACIJE</a>');
		addStaticTooltip($("#toggleButton"), '<a href="http://demo.paragraf.rs/demo/documents/editorial/tooltip/detaljna.html" target="_blank" class="naslov1"><img src="http://demo.paragraf.rs/demo/documents/editorial/tooltip/questionMark.png" alt="Pomo&#x0107; za tab SADR&#x017d;AJ" width="16" height="16" /> Pomo&#x0107; za DETALJNE KRITERIJUME PRETRAGE</a>');
		addStaticTooltip($("#toggleButtonD"), '<a href="http://demo.paragraf.rs/demo/documents/editorial/tooltip/detaljna.html" target="_blank" class="naslov1"><img src="http://demo.paragraf.rs/demo/documents/editorial/tooltip/questionMark.png" alt="Pomo&#x0107; za tab SADR&#x017d;AJ" width="16" height="16" /> Pomo&#x0107; za DETALJNE KRITERIJUME PRETRAGE</a>');
		addLowerStaticTooltip($("#mainForm\\:tbRDevelopLbl"), '<a href="http://demo.paragraf.rs/demo/documents/editorial/tooltip/t_nastanak.html" target="_blank" class="naslov1"><img src="http://demo.paragraf.rs/demo/documents/editorial/tooltip/questionMark.png" alt="Pomo&#x0107; za tab SADR&#x017d;AJ" width="16" height="16" /> Pomo&#x0107; za tab NASTANAK</a>');
		addLowerStaticTooltip($("#mainForm\\:tbRAboutLbl"), '<a href="http://demo.paragraf.rs/demo/documents/editorial/tooltip/t_o_dokumentu.html" target="_blank" class="naslov1"><img src="http://demo.paragraf.rs/demo/documents/editorial/tooltip/questionMark.png" alt="Pomo&#x0107; za tab SADR&#x017d;AJ" width="16" height="16" /> Pomo&#x0107; za tab O DOKUMENTU</a>');
		addLowerStaticTooltip($("#mainForm\\:tbRAboutActLbl"),  '<a href="http://demo.paragraf.rs/demo/documents/editorial/tooltip/t_sadrzaj.html" target="_blank" class="naslov1"><img src="http://demo.paragraf.rs/demo/documents/editorial/tooltip/questionMark.png" alt="Pomo&#x0107; za tab SADR&#x017d;AJ" width="16" height="16" /> Pomo&#x0107; za tab O PROPISU</a>');
		addStaticTooltip($("#mainForm\\:SlctCompTyp1"), '<a href="http://demo.paragraf.rs/demo/documents/editorial/tooltip/osnovna.html" target="_blank" class="naslov1"><img src="http://demo.paragraf.rs/demo/documents/editorial/tooltip/questionMark.png" alt="Pomo&#x0107; za tab SADR&#x017d;AJ" width="16" height="16" /> Pomo&#x0107; za OSNOVNE KRITERIJUME PRETRAGE</a>');
		addStaticTooltip($("#mainForm\\:SlctCompTyp2"), '<a href="http://demo.paragraf.rs/demo/documents/editorial/tooltip/osnovna.html" target="_blank" class="naslov1"><img src="http://demo.paragraf.rs/demo/documents/editorial/tooltip/questionMark.png" alt="Pomo&#x0107; za tab SADR&#x017d;AJ" width="16" height="16" /> Pomo&#x0107; za OSNOVNE KRITERIJUME PRETRAGE</a>');
		//alert('2');
//		addDynamicTooltip($("#btnRel"), STATIC_TIPS.tip5);
	};


	function addLowerStaticTooltip(element, tooltip) {
		element.qtip({
			content : {
				text : tooltip
			},
			show: {
		        effect: function(offset) {
		              $(this).slideUp(150); // 
				$(this).fadeIn();
		        }
		    },
			hide : {
				 effect: function(offset) {
		              $(this).slideDown(150); // 
		        },
				fixed : true,
				delay : 300
			},
			position: {
		        my: 'bottom left',  // Position my top left...
		        at: 'top right', // at the bottom right of...
		        target: element // my target
		    }
		});
	}

	
	function addStaticTooltip(element, tooltip) {
		element.qtip({
			content : {
				text : tooltip
			},
			show: {
		        effect: function(offset) {
		              $(this).slideDown(150); // 
				$(this).fadeIn();
		        }
		    },
			hide : {
				 effect: function(offset) {
		              $(this).slideUp(150); // 
		        },
				fixed : true,
				delay : 300
			},
			position: {
		        viewport: $(window)
		    }
//			position: {
//		        my: 'top left',  // Position my top left...
//		        at: 'bottom left', // at the bottom right of...
//		        target: element // my target
//		    }
		});
	}

	function addDynamicTooltip(element, url) {
		element.qtip({
			content : {
				text : 'U&#x010d;itavanje...', // The text to use whilst the AJAX
//				text: url
				// request is loading
				ajax : {
					url : url, // URL to the local file
					type : 'GET', // POST or GET
					data : {}, // Data to pass along with your request
					once : false
				}
			},
			show: {
		        effect: function(offset) {
		              $(this).slideDown(150); // 
				$(this).fadeIn();
		        }
		    },
			hide : {
				 effect: function(offset) {
		              $(this).slideUp(150); // 
		        },
				fixed : true,
				delay : 300
			},
			position: {
			        viewport: $(window)
			    }
//			position: {
//		        my: 'bottom left',  // Position my top left...
//		        at: 'bottom left', // at the bottom right of...
//		        target: element // my target
//		    }
		});
	}
	
	return {
		addTooltips : function() {
			this.addTips();
		}
	};
})(window, jQuery);

/**
 * The AjaxRequest class is a wrapper for the XMLHttpRequest objects which are
 * available in most modern browsers. It simplifies the interfaces for making
 * Ajax requests, adds commonly-used convenience methods, and makes the process
 * of handling state changes more intuitive. An object may be instantiated and
 * used, or the Class methods may be used which internally create an AjaxRequest
 * object.
 */
function AjaxRequest() {
	var req = new Object();

	// -------------------
	// Instance properties
	// -------------------

	/**
	 * Timeout period (in ms) until an async request will be aborted, and the
	 * onTimeout function will be called
	 */
	req.timeout = null;

	/**
	 * Since some browsers cache GET requests via XMLHttpRequest, an additional
	 * parameter called AjaxRequestUniqueId will be added to the request URI
	 * with a unique numeric value appended so that the requested URL will not
	 * be cached.
	 */
	req.generateUniqueUrl = false;

	/**
	 * The url that the request will be made to, which defaults to the current
	 * url of the window
	 */
	req.url = window.location.href;

	/**
	 * The method of the request, either GET (default), POST, or HEAD
	 */
	req.method = "GET";

	/**
	 * Whether or not the request will be asynchronous. In general, synchronous
	 * requests should not be used so this should rarely be changed from true
	 */
	req.async = true;

	/**
	 * The username used to access the URL
	 */
	req.username = null;

	/**
	 * The password used to access the URL
	 */
	req.password = null;

	/**
	 * The parameters is an object holding name/value pairs which will be added
	 * to the url for a GET request or the request content for a POST request
	 */
	req.parameters = new Object();

	/**
	 * The sequential index number of this request, updated internally
	 */
	req.requestIndex = AjaxRequest.numAjaxRequests++;

	/**
	 * Indicates whether a response has been received yet from the server
	 */
	req.responseReceived = false;

	/**
	 * The name of the group that this request belongs to, for activity
	 * monitoring purposes
	 */
	req.groupName = null;

	/**
	 * The query string to be added to the end of a GET request, in proper
	 * URIEncoded format
	 */
	req.queryString = "";

	/**
	 * After a response has been received, this will hold the text contents of
	 * the response - even in case of error
	 */
	req.responseText = null;

	/**
	 * After a response has been received, this will hold the XML content
	 */
	req.responseXML = null;

	/**
	 * After a response has been received, this will hold the status code of the
	 * response as returned by the server.
	 */
	req.status = null;

	/**
	 * After a response has been received, this will hold the text description
	 * of the response code
	 */
	req.statusText = null;

	/**
	 * An internal flag to indicate whether the request has been aborted
	 */
	req.aborted = false;

	/**
	 * The XMLHttpRequest object used internally
	 */
	req.xmlHttpRequest = null;

	// --------------
	// Event handlers
	// --------------

	/**
	 * If a timeout period is set, and it is reached before a response is
	 * received, a function reference assigned to onTimeout will be called
	 */
	req.onTimeout = null;

	/**
	 * A function reference assigned will be called when readyState=1
	 */
	req.onLoading = null;

	/**
	 * A function reference assigned will be called when readyState=2
	 */
	req.onLoaded = null;

	/**
	 * A function reference assigned will be called when readyState=3
	 */
	req.onInteractive = null;

	/**
	 * A function reference assigned will be called when readyState=4
	 */
	req.onComplete = null;

	/**
	 * A function reference assigned will be called after onComplete, if the
	 * statusCode=200
	 */
	req.onSuccess = null;

	/**
	 * A function reference assigned will be called after onComplete, if the
	 * statusCode != 200
	 */
	req.onError = null;

	/**
	 * If this request has a group name, this function reference will be called
	 * and passed the group name if this is the first request in the group to
	 * become active
	 */
	req.onGroupBegin = null;

	/**
	 * If this request has a group name, and this request is the last request in
	 * the group to complete, this function reference will be called
	 */
	req.onGroupEnd = null;

	// Get the XMLHttpRequest object itself
	req.xmlHttpRequest = AjaxRequest.getXmlHttpRequest();

	if (req.xmlHttpRequest == null) {
		return null;
	}

	// -------------------------------------------------------
	// Attach the event handlers for the XMLHttpRequest object
	// -------------------------------------------------------
	req.xmlHttpRequest.onreadystatechange = function() {
		if (req == null || req.xmlHttpRequest == null) {
			return;
		}
		if (req.xmlHttpRequest.readyState == 1) {
			req.onLoadingInternal(req);
		}
		if (req.xmlHttpRequest.readyState == 2) {
			req.onLoadedInternal(req);
		}
		if (req.xmlHttpRequest.readyState == 3) {
			req.onInteractiveInternal(req);
		}
		if (req.xmlHttpRequest.readyState == 4) {
			req.onCompleteInternal(req);
		}
	};

	// ---------------------------------------------------------------------------
	// Internal event handlers that fire, and in turn fire the user event
	// handlers
	// ---------------------------------------------------------------------------
	// Flags to keep track if each event has been handled, in case of
	// multiple calls (some browsers may call the onreadystatechange
	// multiple times for the same state)
	req.onLoadingInternalHandled = false;
	req.onLoadedInternalHandled = false;
	req.onInteractiveInternalHandled = false;
	req.onCompleteInternalHandled = false;

	req.onLoadingInternal = function() {
		if (req.onLoadingInternalHandled) {
			return;
		}
		AjaxRequest.numActiveAjaxRequests++;
		if (AjaxRequest.numActiveAjaxRequests == 1
				&& typeof (window['AjaxRequestBegin']) == "function") {
			AjaxRequestBegin();
		}
		if (req.groupName != null) {
			if (typeof (AjaxRequest.numActiveAjaxGroupRequests[req.groupName]) == "undefined") {
				AjaxRequest.numActiveAjaxGroupRequests[req.groupName] = 0;
			}
			AjaxRequest.numActiveAjaxGroupRequests[req.groupName]++;
			if (AjaxRequest.numActiveAjaxGroupRequests[req.groupName] == 1
					&& typeof (req.onGroupBegin) == "function") {
				req.onGroupBegin(req.groupName);
			}
		}
		if (typeof (req.onLoading) == "function") {
			req.onLoading(req);
		}
		req.onLoadingInternalHandled = true;
	};

	req.onLoadedInternal = function() {
		if (req.onLoadedInternalHandled) {
			return;
		}
		if (typeof (req.onLoaded) == "function") {
			req.onLoaded(req);
		}
		req.onLoadedInternalHandled = true;
	};

	req.onInteractiveInternal = function() {
		if (req.onInteractiveInternalHandled) {
			return;
		}
		if (typeof (req.onInteractive) == "function") {
			req.onInteractive(req);
		}
		req.onInteractiveInternalHandled = true;
	};

	req.onCompleteInternal = function() {
		if (req.onCompleteInternalHandled || req.aborted) {
			return;
		}
		req.onCompleteInternalHandled = true;
		AjaxRequest.numActiveAjaxRequests--;
		if (AjaxRequest.numActiveAjaxRequests == 0
				&& typeof (window['AjaxRequestEnd']) == "function") {
			AjaxRequestEnd(req.groupName);
		}
		if (req.groupName != null) {
			AjaxRequest.numActiveAjaxGroupRequests[req.groupName]--;
			if (AjaxRequest.numActiveAjaxGroupRequests[req.groupName] == 0
					&& typeof (req.onGroupEnd) == "function") {
				req.onGroupEnd(req.groupName);
			}
		}
		req.responseReceived = true;
		req.status = req.xmlHttpRequest.status;
		req.statusText = req.xmlHttpRequest.statusText;
		req.responseText = req.xmlHttpRequest.responseText;
		req.responseXML = req.xmlHttpRequest.responseXML;
		if (typeof (req.onComplete) == "function") {
			req.onComplete(req);
		}
		if (req.xmlHttpRequest.status == 200
				&& typeof (req.onSuccess) == "function") {
			req.onSuccess(req);
		} else if (typeof (req.onError) == "function") {
			req.onError(req);
		}
		// Clean up so IE doesn't leak memory
		delete req.xmlHttpRequest['onreadystatechange'];
		req.xmlHttpRequest = null;
	};

	req.onTimeoutInternal = function() {
		if (req != null && req.xmlHttpRequest != null
				&& !req.onCompleteInternalHandled) {
			req.aborted = true;
			req.xmlHttpRequest.abort();
			AjaxRequest.numActiveAjaxRequests--;
			if (AjaxRequest.numActiveAjaxRequests == 0
					&& typeof (window['AjaxRequestEnd']) == "function") {
				AjaxRequestEnd(req.groupName);
			}
			if (req.groupName != null) {
				AjaxRequest.numActiveAjaxGroupRequests[req.groupName]--;
				if (AjaxRequest.numActiveAjaxGroupRequests[req.groupName] == 0
						&& typeof (req.onGroupEnd) == "function") {
					req.onGroupEnd(req.groupName);
				}
			}
			if (typeof (req.onTimeout) == "function") {
				req.onTimeout(req);
			}

			// Opera won't fire onreadystatechange after abort, but other
			// browsers do.
			// So we can't rely on the onreadystate function getting called.
			// Clean up here!
			delete req.xmlHttpRequest['onreadystatechange'];
			req.xmlHttpRequest = null;
		}
	};

	// ----------------
	// Instance methods
	// ----------------

	/**
	 * The process method is called to actually make the request. It builds the
	 * querystring for GET requests (the content for POST requests), sets the
	 * appropriate headers if necessary, and calls the XMLHttpRequest.send()
	 * method
	 */
	req.process = function() {
		if (req.xmlHttpRequest != null) {
			// Some logic to get the real request URL
			if (req.generateUniqueUrl && req.method == "GET") {
				req.parameters["AjaxRequestUniqueId"] = new Date().getTime()
						+ "" + req.requestIndex;
			}
			var content = null; // For POST requests, to hold query string

			for ( var i in req.parameters) {
				if (req.queryString.length > 0) {
					req.queryString += "&";
				}
				req.queryString += encodeURIComponent(i) + "="
						+ encodeURIComponent(req.parameters[i]);
			}
			if (req.method == "GET") {
				if (req.queryString.length > 0) {
					req.url += ((req.url.indexOf("?") > -1) ? "&" : "?")
							+ req.queryString;
				}
			}
			req.xmlHttpRequest.open(req.method, req.url, req.async,
					req.username, req.password);
			if (req.method == "POST") {
				if (typeof (req.xmlHttpRequest.setRequestHeader) != "undefined") {
					req.xmlHttpRequest.setRequestHeader('Content-type',
							'application/x-www-form-urlencoded');
				}
				content = req.queryString;
			}
			if (req.timeout > 0) {
				setTimeout(req.onTimeoutInternal, req.timeout);
			}
			req.xmlHttpRequest.send(content);
		}
	};

	/**
	 * An internal function to handle an Object argument, which may contain
	 * either AjaxRequest field values or parameter name/values
	 */
	req.handleArguments = function(args) {
		for ( var i in args) {
			// If the AjaxRequest object doesn't have a property which was
			// passed, treat it as a url parameter
			if (typeof (req[i]) == "undefined") {
				req.parameters[i] = args[i];
			} else {
				req[i] = args[i];
			}
		}
	};

	/**
	 * Returns the results of XMLHttpRequest.getAllResponseHeaders(). Only
	 * available after a response has been returned
	 */
	req.getAllResponseHeaders = function() {
		if (req.xmlHttpRequest != null) {
			if (req.responseReceived) {
				return req.xmlHttpRequest.getAllResponseHeaders();
			}
			alert("Cannot getAllResponseHeaders because a response has not yet been received");
		}
	};

	/**
	 * Returns the the value of a response header as returned by
	 * XMLHttpRequest,getResponseHeader(). Only available after a response has
	 * been returned
	 */
	req.getResponseHeader = function(headerName) {
		if (req.xmlHttpRequest != null) {
			if (req.responseReceived) {
				return req.xmlHttpRequest.getResponseHeader(headerName);
			}
			alert("Cannot getResponseHeader because a response has not yet been received");
		}
	};
	return req;
}

// ---------------------------------------
// Static methods of the AjaxRequest class
// ---------------------------------------

/**
 * Returns an XMLHttpRequest object, either as a core object or an ActiveX
 * implementation. If an object cannot be instantiated, it will return null;
 */
AjaxRequest.getXmlHttpRequest = function() {
	if (window.XMLHttpRequest
			&& !(BrowserDetect.browser == "Explorer" && BrowserDetect.version < 9)) {// code
		// for
		// IE9+,
		// Firefox,
		// Chrome,
		// Opera,
		// Safari
		return new XMLHttpRequest();// Microsoft failed to properly implement
		// the XMLHttpRequest in IE7 and IE8 (can't
		// request local files)
	} else if (window.ActiveXObject) {// code for IE8, IE7, IE6, IE5
		try {
			return new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		}
		try {
			return new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
		}
	}
	// throw new Error("Can not create XMLHttpRequest");
	return null;
};

/**
 * See if any request is active in the background
 */
AjaxRequest.isActive = function() {
	return (AjaxRequest.numActiveAjaxRequests > 0);
};

/**
 * Make a GET request. Pass an object containing parameters and arguments as the
 * second argument. These areguments may be either AjaxRequest properties to set
 * on the request object or name/values to set in the request querystring.
 */
AjaxRequest.get = function(args) {
	AjaxRequest.doRequest("GET", args);
};

/**
 * Make a POST request. Pass an object containing parameters and arguments as
 * the second argument. These areguments may be either AjaxRequest properties to
 * set on the request object or name/values to set in the request querystring.
 */
AjaxRequest.post = function(args) {
	AjaxRequest.doRequest("POST", args);
};

/**
 * The internal method used by the .get() and .post() methods
 */
AjaxRequest.doRequest = function(method, args) {
	if (typeof (args) != "undefined" && args != null) {
		var myRequest = new AjaxRequest();
		myRequest.method = method;
		myRequest.handleArguments(args);
		myRequest.process();
	}
};

/**
 * Submit a form. The requested URL will be the form's ACTION, and the request
 * method will be the form's METHOD. Returns true if the submittal was handled
 * successfully, else false so it can easily be used with an onSubmit event for
 * a form, and fallback to submitting the form normally.
 */
AjaxRequest.submit = function(theform, args) {
	var myRequest = new AjaxRequest();
	if (myRequest == null) {
		return false;
	}
	var serializedForm = AjaxRequest.serializeForm(theform);
	myRequest.method = theform.method.toUpperCase();
	myRequest.url = theform.action;
	myRequest.handleArguments(args);
	myRequest.queryString = serializedForm;
	myRequest.process();
	return true;
};

/**
 * Serialize a form into a format which can be sent as a GET string or a POST
 * content.It correctly ignores disabled fields, maintains order of the fields
 * as in the elements[] array. The 'file' input type is not supported, as its
 * content is not available to javascript. This method is used internally by the
 * submit class method.
 */
AjaxRequest.serializeForm = function(theform) {
	var els = theform.elements;
	var len = els.length;
	var queryString = "";
	this.addField = function(name, value) {
		if (queryString.length > 0) {
			queryString += "&";
		}
		queryString += encodeURIComponent(name) + "="
				+ encodeURIComponent(value);
	};
	for ( var i = 0; i < len; i++) {
		var el = els[i];
		if (!el.disabled) {
			switch (el.type) {
			case 'text':
			case 'password':
			case 'hidden':
			case 'textarea':
				this.addField(el.name, el.value);
				break;
			case 'select-one':
				if (el.selectedIndex >= 0) {
					this.addField(el.name, el.options[el.selectedIndex].value);
				}
				break;
			case 'select-multiple':
				for ( var j = 0; j < el.options.length; j++) {
					if (el.options[j].selected) {
						this.addField(el.name, el.options[j].value);
					}
				}
				break;
			case 'checkbox':
			case 'radio':
				if (el.checked) {
					this.addField(el.name, el.value);
				}
				break;
			}
		}
	}
	return queryString;
};

// -----------------------
// Static Class variables
// -----------------------

/**
 * The number of total AjaxRequest objects currently active and running
 */
AjaxRequest.numActiveAjaxRequests = 0;

/**
 * An object holding the number of active requests for each group
 */
AjaxRequest.numActiveAjaxGroupRequests = new Object();

/**
 * The total number of AjaxRequest objects instantiated
 */
AjaxRequest.numAjaxRequests = 0;