function AJX() {}


/**
 * Tries to get an XMLHttpRequest object, returns false if the browser does not support AJAX.
 * 
 * @deprecated You should not need to use this function directly, use {@link aV.AJAX.makeRequest} to make AJAX calls.
 * @return {XMLHttpRequestObject | false} A new XMLHttpRequest object or false
 */
AJX.prototype.createRequestObject=function()
{
	var requestObject = false;
	if(window.XMLHttpRequest && !(window.ActiveXObject))
	{
		try
		{
			requestObject = new XMLHttpRequest();
		}
		catch(error)
		{
			requestObject = false;
		}
	}
	else if(window.ActiveXObject)
	{
		try
		{
			requestObject = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(error)
		{
			try
			{
				requestObject = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(error)
			{
				requestObject = false;
			}
		}
	}
	return requestObject;
};

/**
 * Destroys the given XMLHttpRequest object safely.
 * Aborts the request if it is active.
 *
 * @param {XMLHttpRequestObject} requestObject The requestObject which will be destroyed
 */
AJX.prototype.destroyRequestObject=function(requestObject)
{
	if (requestObject)
	{
		if ((requestObject.readyState!=4) && (requestObject.readyState!=0))
			requestObject.abort();
		requestObject=undefined;
	}
};

AJX.prototype.createCrossDomainRequestObject=function()
{
	var requestObject={};
	var callBackUrl=window.location.protocol + '//' + window.location.host + '/blank.html';
	requestObject.$$guid=this._crossDomainRequestLastGuid++;
	requestObject._container=document.createElement("span");
	requestObject._container.innerHTML='<iframe style="display:none" id="aVAJAXFrame' + requestObject.$$guid + '" name="aVAJAXFrame' + requestObject.$$guid + '" onload="this.loaded()"></iframe>';
	requestObject._container.iframe=requestObject._container.firstChild;
	requestObject._container.iframe.loaded=function()
	{
		if (!requestObject.status)
		{
			requestObject.status=200;
			this.contentWindow.location = callBackUrl;
			return;
		}
		requestObject.responseText=this.contentWindow.name;
		try
		{
			if (window.DOMParser)
				requestObject.responseXML=(new DOMParser()).parseFromString(requestObject.responseText, "application/xml");
			else if (window.ActiveXObject)
			{
				requestObject.responseXML=new ActiveXObject("Microsoft.XMLDOM");
				requestObject.responseXML.async=false;
				requestObject.responseXML.loadXML(requestObject.responseText);
			}
			else
				throw new Error("Cannot find an XML parser!");
		}
		catch(error)
		{
			requestObject.responseXML=null;
		}
		requestObject.readyState=4;
		requestObject._doReadyStateChange();

		setTimeout(function(){document.body.removeChild(requestObject._container); delete requestObject._container;}, 0);
	};
	
	requestObject.readyState=1;
	requestObject.status=0;
	
	requestObject._doReadyStateChange=function()
	{
		if (requestObject.onreadystatechange)
			requestObject.onreadystatechange({type: "readystatechange", target: requestObject});
	};

	requestObject.open=function(method, address)
	{
		if (this._container.form)
			this._container.removeChild(this._container.form);

		this._container.form=this._container.appendChild(document.createElement("form"));
		this._container.form.style.display='none';
		this._container.form.target=requestObject._container.iframe.name;
		this._container.form.method=method;
		this._container.form.action=address;
		requestObject.readyState=2;
		requestObject._doReadyStateChange();
	};
	
	requestObject.setRequestHeader=function(header, value)
	{
		header=header.toLowerCase();
		header=this.headerTranslations[header];
		if (!(this._container.form && (header in this._container.form)))
			return false;
		this._container.form[header]=value;
		return true;
	};
	
	requestObject.send=function(parameters)
	{
		parameters=(parameters)?parameters.split('&'):[];
		var matcher=/^([^&=]+)=([^&]+)$/;
		var pair, parameterObj;
		for (var i = 0; i < parameters.length; i++) 
		{
			pair = parameters[i].match(matcher);
			if (!(pair && pair[1]))
				continue;
			parameterObj = document.createElement("input");
			parameterObj.type = "hidden";
			parameterObj.name = pair[1];
			parameterObj.value = decodeURIComponent(pair[2]);
			this._container.form.appendChild(parameterObj);
		}
		requestObject.readyState=3;
		requestObject._doReadyStateChange();
		this._container.form.submit();
	};
	
	document.body.appendChild(requestObject._container);	
	
	return requestObject;
};

/**
 * This function is assigned to the page's onbeforeunload event for pageLeaveWarning feature.
 * See {@link aV.AJAX}.config.pageLeaveWarning
 *
 * @deprecated Should not be called directly, it is for the page's onbeforeunload event.
 * @return {String | null} pageLeaveWarning config variable or null
 */
AJX.prototype.checkActiveRequests=function()
{
	if (this.activeRequestCount>0)
		return 'warning dont leave';
};

/**
 * Creates a new XMLHttpRequest object which connects to the address, which includes the URI encoded and merged GET parameters.
 * Assignes changeFunction to the newly created XMLHttpRequest object's onreadystatechange event.
 * Frees the XMLHttpRequest object automatically after completing the call.
 *
 * @deprecated Generally used internally from other high-level functions. Not very suitable for end-developers.
 * @return {XMLHttpRequestObject}
 * @param {String} address The address of the page which will be connected. Should include the URI encoded GET parameters.
 * @param {Function(XMLHttpRequestObject)} [changeFunction] The function which will be assigned to the newly created XMLHttpRequest object's onreadystatechange event.
 */
AJX.prototype.makeGetRequest=function(address, changeFunction, crossDomain)
{
	var requestObject = (crossDomain)?this.createCrossDomainRequestObject():this.createRequestObject(); //try to create an XMLHttpRequest object
	if (requestObject) //if the XMLHttpRequest object is valid
	{
		requestObject.open("GET", address, true); //set the address and HTTP method to GET
		requestObject.onreadystatechange = function()
		{
			try
			{
				if (changeFunction) //if there is an assigned changeFunction, assign it to the onreadystatechange event specially, that it recieves the XMLHttpRequest object as its parameter		
					changeFunction(requestObject);
			}
			catch(error)
			{
				if (window.onerror)
					window.onerror(error.message, error.fileName, error.lineNumber);
			}
			finally
			{
				if (requestObject.readyState==4)
				{
					this.activeRequestCount--;
					requestObject=undefined;
				}
			}
		};
		requestObject.send((crossDomain)?'&windowname=true':null); //start the request
		this.activeRequestCount++;
	}
	else  //if cannot create a valid XMLHttpRequest object, inform user.
		alert('browser not support ajax');
	return requestObject; //return the created XMLHttpRequest object for any further use
};

/**
 * Creates a new XMLHttpRequest object which posts the given URI query string to the given address.
 * Assignes changeFunction to the newly created XMLHttpRequest object's onreadystatechange event.
 * Frees the XMLHttpRequest object automatically after completing the call.
 *
 * @deprecated Generally used internally from other high-level functions. Not very suitable for end-developers.
 * @return {XMLHttpRequestObject}
 * @param {String} address The address of the page which will be connected. Should  NOT include any parameters.
 * @param {String} parameters The URI encoded and merged POST parameters for the HTTP request.
 * @param {Function(XMLHttpRequestObject)} [changeFunction] The function which will be assigned to the newly created XMLHttpRequest object's onreadystatechange event.
 */
AJX.prototype.makePostRequest=function(address, parameters, changeFunction, crossDomain)
{
	var requestObject = (crossDomain)?this.createCrossDomainRequestObject():this.createRequestObject(); //try to create a XMLHttpRequest object
	if (requestObject) //if XMLHttpRequest object is valid
	{
		requestObject.open("POST", address, true); //set the address and HTTP method to GET
		requestObject.onreadystatechange = function()
		{
			try
			{
				if (changeFunction) //if there is an assigned changeFunction, assign it to the onreadystatechange event specially, that it recieves the XMLHttpRequest object as its parameter		
					changeFunction(requestObject);
			}
			catch(error)
			{
				if (window.onerror)
					window.onerror(error.message, error.fileName, error.lineNumber);
			}
			finally
			{
				if (requestObject.readyState==4)
				{
					this.activeRequestCount--;
					requestObject=undefined;
				}
			}
		};
		if (!parameters)
			parameters='';
		requestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    requestObject.setRequestHeader("Content-length", parameters.length);
    requestObject.setRequestHeader("Connection", "close");
		//set some headers for POST method
		if (crossDomain)
			parameters+='&windowname=true';
		requestObject.send(parameters); //send the request with parameters attached
		this.activeRequestCount++;
	}
	else  //if cannot create a valid XMLHttpRequest object, inform user.
		alert('browser no support ajax');
	return requestObject; //return the created XMLHttpRequest object for any further use
};

AJX.prototype.isCrossDomain=function(url)
{
	var matchResult=url.match(/^\w+:\/\/([^\/@ ]+)/i);
	var domain=(matchResult)?matchResult[1]:null;
	return (domain && (domain!=document.domain));
};

/**
 * Takes "GET" or "POST" as method parameter and then according to this, creates a SELF-MANAGED
 * XMLHttpRequest object using internal makeGetRequest or makePostRequest according to the method parameter.
 * Developers are strongly recommended to use THIS function instead of the above POST and GET specific functions.
 *
 * @return {XMLHttpRequestObject} The newly created XMLHttpRequest object for this specific AJAX call.
 * @param {String} method Should be either POST or GET according to the type of the HTTP request.
 * @param {String} address The address of the page which will be connected. Should  NOT include any parameters.
 * @param {String | Object} parameters The parameters which are either URI encoded and merged or given in the JSON format
 * @param {Function(XMLHttpRequestObject)} [completedFunction] The function which will be called when the HTTP call is completed. (readyState==4)
 * @param {Function(XMLHttpRequestObject)} [loadingFunction] The function which will be called EVERYTIME when an onreadystatechange event is occured with a readyState different than 4. Might be called several times before the call is completed.
 */
AJX.prototype.makeRequest=function(method, address, parameters, completedFunction, compFunctionParams, loadingFunction)
{
	var crossDomain=this.isCrossDomain(address);
	var triggerFunction=function (requestObject) //define the custom changeFunction as triggerFunction
	{
		if (requestObject.readyState == 4 && completedFunction) //if the request is finished and there is a  completedFunction assigned
			completedFunction(requestObject, compFunctionParams); //call the completedFunction sending the requestObject as its parameter
		else if (loadingFunction) //if request is in progress and there is an assigned loadingFunction
			loadingFunction(requestObject); //call the loadingFunction passing the requestObject as its parameter
	}; //finished defining the custom changeFunction
	//checking parameters
	if (!parameters)
		parameters='';
	if (parameters.constructor==Object)
		parameters=parameters.toQueryString();
	
	if (method.toUpperCase()=="GET") //if requested method is GET, then call the aV.AJAX.makeGetRequest function
		return this.makeGetRequest(address + ((parameters)?'?' + parameters:''), triggerFunction, crossDomain);
	else if (method.toUpperCase()=="POST") //else if requested method is POST, then call the aV.AJAX.makePostRequest function
		return this.makePostRequest(address, parameters, triggerFunction, crossDomain);
	else //if requested method is invalid, return false
		return false;
};

AJX.prototype.isResponseOK=function(requestObject, responseType)
{
	if (!responseType)
		responseType='Text';
	return (requestObject.status==200 && requestObject["response" + responseType]);
};

AJX.prototype.formatResponse = function(reqObject, format, gridCssName, itemCssName)  {
	format = format.toLowerCase();
	switch (format) {
		case "xml": 
			return reqObject.responseXML;
		    break;
		case "text": 
			return reqObject.responseText;
		    break;
		case "json": 
			return eval("(" + reqObject.responseText + ")");
		    break;
		case "table": 
			return this.getHTMLTable(eval("(" + reqObject.responseText + ")"), gridCssName, itemCssName);
		    break;
		default: 'invalid format'; 
	}	
};

AJX.prototype.getHTMLTable = function(jsonObj, gridCssName, itemCssName) {
			alert(jsonObj);
	var s = '';
	var gridCssClass = 
		(typeof gridCssName == "string" && gridCssName != '') ? 
			' class="'+gridCssName+'"' : '';
	var itemCssClass = 
		(typeof itemCssName == "string" && itemCssName != '') ? 
			' class="'+itemCssName+'"' : '';
	if (typeof jsonObj == "object") {
		s = '<table border="0" cellspacing="0" cellpadding="0" width="100%"'+gridCssName+'>';
		for (var item in jsonObj) {
			// if again this is an array (no recursion)
			if (typeof jsonObj[item] == "object") {
				s += '<tr>';
				for (var innerItem in jsonObj[item]) {
					s += '<td valign="top" align="left"'+itemCssClass+'>' + jsonObj[item][innerItem] + '</td>';
				}						
				s += '</tr>';
				continue;
			}
			else {
				s += '<tr>' + 
						'<td valign="top" align="left"'+itemCssClass+'>' + jsonObj[item] + '</td>' + 
						'</tr>';
			}
		}
		s += '</table>';
	}
	else {
		s = '<div'+gridCssClass+'><div'+itemCssClass+'>' + jsonObj + '</div></div>';
	}
	return s;
};

/**
 * @param loaderDivId
 * @param loaderDivCtnt
 * @param loaderDivTitle
 * @param divsToClear
 *	
 */ 
AJX.prototype.prepareDivs = function(loaderDivId, loaderDivCtnt, loaderDivTitle, divsToClear) {
	var s = '';
	var loaderDivCtnt = (loaderDivCtnt == undefined || loaderDivCtnt == '') ? 'js/ajaxwait.gif' : loaderDivCtnt;
	if (typeof loaderDivCtnt == "string" && loaderDivCtnt != '') {
		// we must show an image
		if (loaderDivCtnt.indexOf(".")>-1) {
			var loaderDivTitle = 
				(typeof loaderDivTitle == "string" && loaderDivTitle != '') ? loaderDivTitle : ' ... ';
			s = '<img src="'+loaderDivCtnt+'" border="0" title="'+loaderDivTitle+'" alt="'+loaderDivTitle+'" vspace="0" hspace="0"'+loaderDivTitle+' />';
		}
		else {
			s = loaderDivCtnt;
		}
	}
	if (typeof divsToClear == "array" && divsToClear.length > 0 ) {
		for (var item in divsToClear ) {
			$(divsToClear[item]).innerHTML = '';
		}
	}
	try {
		$(loaderDivId).innerHTML = s;
	} catch (e) {
		try {
			loaderDivId.innerHTML = s;
		}
		catch ( ex ) {}
	}
};

AJX.prototype.setResult = function(result, resultDivId, divsToClear) {
	if (typeof divsToClear == "object") {
		for (var item in divsToClear ) {
			$(divsToClear[item]).innerHTML = '';
		}
	}
	$(resultDivId).innerHTML = result;
};


AJX.prototype.showDivFrameDialog =	function(divid, iframeUri, title, bcolor, fcolor, wdth, hght, xpos, ypos) {
	fcolor = (fcolor==null || fcolor=='') ? '#000' : fcolor;
	bcolor = (bcolor==null || bcolor=='') ? '#fff' : bcolor;
	wdth = (wdth==null || wdth=='') ? 520 : wdth;
	hght = (hght==null || hght=='') ? 400 : hght;
	xpos = (xpos==null || xpos=='') ? ((screen.width/2) - (wdth/2)) : xpos;
	ypos = (ypos==null || ypos=='') ? ((screen.height/2) + document.viewport.getScrollOffsets().top) : ypos;
	this.createAjaxDiv(divid, '', '', bcolor, title, fcolor, wdth, hght);
	$(divid+'Ctnt').style.overflow = 'hidden';
	$(divid+'Ctnt').innerHTML = '<iframe src="'+iframeUri+'" width="'+wdth+'" ' +
								 'height="'+hght+'" style="overflow-x:hidden;overflow-y:auto;* width:'+(wdth-10)+'px;" scrolling="no" frameborder="0" marginheight="0" marginwidth="0" name="extajxframe" id="extajxframe"></iframe>';
	$(divid+'Root').style.zIndex = 0;								 
}

/**
 * creates a floating div besides the anchor element to display ajax responses.
 *
 * @param divid id of the floating div
 * @param anchor anchor element (if this is empty create the div window in the parent window)
 * @param backimg background image for the div
 * @param bgcolor background color for the div
 * @param wdth width of the div
 * @param hght height of the div
 * @param posX x coord if anchor is set to null
 * @param posY y coord if anchor is set to null
 */
AJX.prototype.createAjaxDiv = function (divid, anchor, backimg, bgcolor, title, foreground, wdth, hght, posX, posY, openerName) {
	var useParentWindow = false;
	var doc = window.document;
	var docloc = doc.location + ""; 
	docloc = docloc.substring(0, docloc.indexOf('cms-plugins'));
	title = (title==null || title=='') ? 'Details' : title;
	foreground = (foreground==null) ? '#000000' : foreground;
	wdth = (wdth!=null && wdth!='') ? wdth : 540;
	hght = (hght!=null && hght!='') ? hght : 380;
	var posObj = (anchor != null && anchor != '') ? getPosition(anchor) : null;
	if (posObj!=null) {
		posX = posObj.x;
		posY = posObj.y-(hght/2);
	}
	else if ( posX != null && posX != '' && posY!=null && posY !='') {
		// do nothing just take the given values
	}
	else {
		doc = window.parent.document;
		posX = window.center().x-(wdth/2);
		posY = window.center().y-(hght/2);
		//useParentWindow = true;
	}
	if ( (posX + wdth) >= (screen.width-10) ) {
		posX = 10;
	}
	if ( $(divid + 'Root') != null ) {		
		$(divid + 'Ctnt').innerHTML = '<img src="'+docloc+'cms-plugins/js/ajaxwait.gif" border="0" vspace="0" hspace="0" title=" ...." alt=" ...." />';
	}
	if ( $(divid + 'Root') == null ) {		
		var obody = doc.getElementsByTagName('body')[0];
		var frag  = doc.createDocumentFragment();
		
		var outerWin  = doc.createElement('div');
		outerWin.setAttribute('id', divid + 'Root');
		outerWin.style.background = bgcolor;
		outerWin.style.position = 'absolute';
		outerWin.style.width = '0px';
		outerWin.style.height = '0px';
		outerWin.style.border = '1px solid #cccccc';
		
		var handle = doc.createElement('div');
		handle.setAttribute('id', divid + 'Handle');
		handle.style.borderBottom = '1px solid #ccc';
		var htmlStr = '<div class="handleCtnr" style="display:inline;margin:1px;padding-top:0px;padding-bottom:2px;padding-left:3px;padding-right:1px;font-size:11px;line-height:15px;" ' + 
							'onmouseover="this.style.cursor=\'pointer\';" onmouseout="this.style.cursor=\'default\';">';
        if (wdth > 250) {										
				htmlStr += '<div class="handleClose" style="float:left;display:inline;width:13px;background: url('+docloc+'js/closewin.png) 1px 2px no-repeat;" ' +
						   'onclick="this.parentNode.parentNode.parentNode.style.display=\'none\';toggleObjects(\'inline\', \'<>\');">&nbsp;</div>';
		}
		htmlStr += '<div class="handleTitle" id="handleTitle" style="float:left;display:inline;padding-left:10px;">'+title+'</div>' +
					'<div class="handleClose" style="float:right;width:12px;padding-right:1px;background: url('+docloc+'js/closewin.png) 0px 2px no-repeat;" ' +
					'onclick="this.parentNode.parentNode.parentNode.style.display=\'none\';toggleObjects(\'inline\', \'<>\');">&nbsp;</div>' + 
					'</div>';
		handle.innerHTML = htmlStr;			
		outerWin.appendChild(handle);
		
		var ajxHeight = (hght-40);
		var ajxCtnt = doc.createElement('div');
		ajxCtnt.setAttribute('id', divid + 'Ctnt');
		ajxCtnt.style.margin = '1px';
		ajxCtnt.style.padding = '2px';
		ajxCtnt.style.height = ajxHeight + 'px';
		ajxCtnt.style.overflow = 'auto';
		ajxCtnt.innerHTML = '<img src="'+docloc+'cms-plugins/js/ajaxwait.gif" border="0" vspace="0" hspace="0" title=" ...." alt=" ...." />';
		outerWin.appendChild(ajxCtnt);	

		frag.appendChild(outerWin);
		obody.insertBefore(frag, obody.firstChild);
	} else {
		$(divid + 'Ctnt').innerHTML = '<img src="'+docloc+'cms-plugins/js/ajaxwait.gif" border="0" vspace="0" hspace="0" title=" ...." alt=" ...." />';
		var outerWin  = $(divid + 'Root');
	}
	bgcolor = (bgcolor==null) ? '#ffffff' : bgcolor;
	if (backimg != null && backimg != '') {
		outerWin.style.background = 'url('+backimg+') right no-repeat ' + bgcolor;
	} else {
		outerWin.style.background = bgcolor;
	}
	outerWin.style.color = foreground;
	$('handleTitle').innerHTML = title;
	outerWin.style.width = wdth + 'px';
	outerWin.style.height = hght + 'px';
	outerWin.style.top = posY + 'px';
	outerWin.style.left = posX + 'px';
	var theHandle = doc.getElementById(divid + 'Handle');
	var str2Update = theHandle.innerHTML;
	var myregexp = /('<>')/;
	str2Update = str2Update.replace(myregexp, '\''+openerName+'\'');
	theHandle.innerHTML = str2Update;
	outerWin.style.display = 'block';
	if (useParentWindow == true) {
		window.parent.Drag.init(theHandle, outerWin);
	}
	else {
		Drag.init(theHandle, outerWin);
	}
};


/**
 * Loads content to the given container element using an asynchronous HTTP GET call.
 * If the config.loadingText is defined, target container element's innerHTML is filled with its valye while the content is loading.
 *
 * @result {XMLHttpRequestObject}
 * @param {String} address The URL of the content which will be loaded dynamically into the given container.
 * @param {String|Object} element The container element itself or its id, which the dynamic content will be loaded into.
 * @param {Function(Object, String)} [completedFunction] The function which will be called when the loading of the content is finished. It is called with the target container element and the URL as parameters.
 * @param {Function(Object, String)} [loadingFunction] The function which will be called EVERYTIME when an onreadystatechange event is occured with a readyState different than 4 while loading the dynamic content. It is called with the target container element and the URL as parameters.
 */
AJX.prototype.loadContent=function(address, element, completedFunction, loadingFunction)
{
	var crossDomain=this.isCrossDomain(address);
	if (typeof(element)=='string') //if id of the object is given instead of the object itself
		element=document.getElementById(element); //assign the element the object corresponding to the given id
	var triggerFunction = function(requestObject) //define the custom changeFunction
	{
		if (requestObject.readyState == 4) //if the request is finished
		{
			element.innerHTML=requestObject.responseText; //fill the element's innerHTML with the returning data
			if (completedFunction) //if a callback function assigned to *callbackFunc*
				completedFunction(element, address); //call it with the element object and the given URL as its parameters
		}
		else
		{
			if (loadingFunction) //if a custom loadingFunction is assigned
				loadingFunction(element, address); //call it with the element object and the given URL as its parameters
			else 
				element.innerHTML='loading data ...'; //set the given element's innerHTML the loading text to inform the user
		}
	};
	return this.makeGetRequest(address, triggerFunction, crossDomain); //make the GET request and return the used XMLHttpRequest object
};

/**
 * Loads an external style-sheet or Javascript file on-demand.
 * Removes the old node if a resourceId is given.
 * 
 * @return {HTMLElementObject} The newly added script or link DOM node.
 * @param {String} address The address of the resource-to-be-loaded.
 * @param {String} [type="js"] The type of the resource.
 * Should be either js or css.
 * @param {String} [resourceId]	The id which will be assigned to newly created DOM node.
 * If not given, no id is assigned to the created node.
 * @param {Boolean} [forceRefresh] Addes a "?time" value at the end of the file URL to force the browser reload the file and not to use cache.
 */
AJX.prototype.loadResource=function(address, type, resourceId, forceRefresh)
{
	if (!type)
		type="js";
	if (forceRefresh)
		address+="?" + Date.parse(new Date());
	var attr, newNode;
	var head=document.getElementsByTagName("head")[0];
	if (type=="js")
	{
		newNode=document.createElement("script");
		newNode.type="text/javascript";
		attr="src";
	}
	else if (type=="css")
	{
		newNode=document.createElement("link");
		newNode.type="text/css";
		newNode.rel="stylesheet";
		attr="href";
	}
	if (resourceId)
	{
		old=document.getElementById(resourceId);
		if (old) old.parentNode.removeChild(old);
		delete old;
		newNode.id=resourceId;
	}
	newNode[attr]=address;
	return head.appendChild(newNode);
};

/**
 * @ignore
 * @param {Object} address
 * @param {Object} parameters
 * @param {Object} element
 * @param {Object} incremental
 * @param {Object} completedFunction
 * @param {Object} loadingFunction
 */
AJX.prototype.loadSelectOptions=function(address, parameters, element, incremental, completedFunction, loadingFunction)
{
	
};

/**
 * Sends the form data using AJAX when the form's onSubmit event is triggered.
 * @return {Boolean} Returns always false to prevent "real" submission.
 * @param {Object} event
 */
AJX.prototype.sendForm=function(event)
{
	var form=event.target;
/*
	if (checkRequiredFormElements)
		if (!checkRequiredFormElements(form))
		return false;
*/	
	var params={};
	for (var i = 0; i < form.elements.length; i++) 
	{
		if (form.elements[i].type=='submit' || form.elements[i].value=='' || ((form.elements[i].type=='checkbox' || form.elements[i].type=='radio') && form.elements[i].checked==false))
			continue;
		params[form.elements[i].name] = form.elements[i].value;
		form.elements[i].oldDisabled=form.elements[i].disabled;
		form.elements[i].disabled=true;
	}
	
	var completedFunction=function(requestObject)
	{
		for (var i = 0; i < form.elements.length; i++) 
			form.elements[i].disabled=form.elements[i].oldDisabled;
		if (form.callback)
			form.callback(requestObject);
	};
	
	this.makeRequest(form.method, form.action, params, completedFunction);
	return false;
};

/**
 * The current active requests number.
 * Changing this value is highly discouraged.
 *
 * @type integer
 */
AJX.prototype.activeRequestCount=0;

AJX.prototype._crossDomainRequestLastGuid=1;

AJX.prototype.headerTranslations=
{
	'content-type': 'enctype',
	'accept-charset': 'acceptCharset',
	'accept-language': 'lang'
};

/**
 * Introduces some useful functions for XML parsing, which are returned by the XMLHttpRequest objects's responseXML property.
 * @namespace
 */
AJX.prototype.XML = {};
/**
 * Tries to extract the node value whose name is given with nodeName and is contained by mainItem node. Returns the defaultVal if any error occurs.
 *
 * @return {String} The value of the node whose name is given with nodeName and which is contained by mainItem node.
 * @param {Object} mainItem The main node item which holds the sub nodes and their values.
 * @param {String} nodeName Name of the sub node whose value will be extracted from the mainItem.
 * @param {String} [defaultVal] The default value which will be returned if the sub node whose name is given in nodeName is not found.
 */
AJX.prototype.XML.getValue=function(mainItem, nodeName, defaultVal)
{
	defaultVal=(defaultVal) ? defaultVal : "";
	var val;
	try
	{
		val=mainItem.getElementsByTagName(nodeName)[0].firstChild.nodeValue;
		val=(val!=undefined) ? val : defaultVal;
	}
	catch(error)
	{
		val=defaultVal;
	}
	finally
	{
		return val;
	}
};

AJX.prototype.XML.getValues=function(mainItem, nodeName)
{
	var val = [];
	var res = mainItem.getElementsByTagName(nodeName);
	if (res != undefined) {
		for (i=0; i<res.length; i++) {
			if (typeof res[i].childNodes[0].nodeValue == "string") {
				val.push(res[i].childNodes[0].nodeValue);
			}
		}
	}
	return val;
};

/**
 * Tries to set the node value whose name is given with nodeName and is contained by mainItem node. Returns false if any error occurs.
 *
 * @return {String} The value set by the function is returned. If an error occures, the function returns false.
 * @param {Object} mainItem The main node item which holds the sub nodes and their values.
 * @param {String} nodeName Name of the sub node whose value will be set.
 * @param {String} val The new value of the sub node whose name is given in nodeName.
 */
AJX.prototype.XML.setValue=function(mainItem, nodeName, val)
{
	try
	{
		mainItem.getElementsByTagName(nodeName)[0].firstChild.nodeValue=val;
		return val;
	}
	catch(error)
	{
		return false;
	}
};

/**
 * Converts an element/node collection, which acts as an array usually, to an actual array and returns it, which allows developers to use array-spesific functions.
 *
 * @return {HTMLElementObject[]} The array version of the given collection.
 * @param {HTMLCollectionObject} collection The collection which will be converted to array.
 */
AJX.prototype.XML.toArray=function(collection)
{
	var result = new Array();
	for (i = 0; i < collection.length; i++)
		result.push(collection[i]);
	return result;
};

AJX.prototype.XML.toObject=function(source, includeRoot)
{
	var result={};
	if (source.nodeType==9)
		source=source.firstChild;
	if (!includeRoot)
		source=source.firstChild;
	
	while (source) 
	{
		if (source.childNodes.length) 
		{
			if (source.tagName in result) 
			{
				if (result[source.tagName].constructor != Array)
					result[source.tagName] = [result[source.tagName]];
				result[source.tagName].push(this.XML.toObject(source));
			}
			else
				result[source.tagName] = this.XML.toObject(source);
		}
		else 
			result = source.nodeValue;
		source=source.nextSibling;
	}

	return result;
};

function showDescTxtInDiv(anchorElem, calid, uripre, wdth, hght, title, fgcolor, bgcolor, targetWinForToggle) {
	var aj = new AJX;
	aj.createAjaxDiv('descres', anchorElem, '', bgcolor, title, fgcolor, 300, 250, null, null, targetWinForToggle);
	var ret = aj.makeRequest('get', uripre + 'agent.ajx.php', 'exec=desc&cid='+calid, showIcon, new Array('descresCtnt', wdth, hght, 'descres', 'text'));
	$('descresRoot').style.zIndex = 1;
}
function showIconInDiv(anchorElem, calid, uripre, wdth, hght, title, fgcolor, bgcolor, isolang, targetWinForToggle) {
	var aj = new AJX;
	isolang = (isolang==null || isolang=='') ? '' : 'isolang=' + isolang + '&';
	aj.createAjaxDiv('iconres', anchorElem, '', bgcolor, title, fgcolor, wdth, hght, null, null, targetWinForToggle);
	var ret = aj.makeRequest('get', uripre + 'agent.ajx.php', isolang+'exec=icon&cid='+calid, showIcon, new Array('iconresCtnt', wdth, hght, 'iconres', 'image'));
	$('iconresRoot').style.zIndex = 1;
}
function showIcon(obj, params) {
	var aj = new AJX;
	$(params[0]).innerHTML = obj.responseText;
	nwdth = params[1] + 5;
	nhght = params[2] + 10;
	$(params[3] + 'Root').style.width = (nwdth+5) + 'px';
	$(params[3] + 'Root').style.height = (nhght+25) + 'px';
	if (params[4]==='text') {
		$(params[3] + 'Ctnt').style.padding = '3px';
		$(params[3] + 'Ctnt').style.overflow = 'auto';
	}
	if (params[4]==='image') {
		$(params[3] + 'Ctnt').style.padding = '0px';
		$(params[3] + 'Ctnt').style.overflow = 'hidden';
	}
	$(params[3] + 'Ctnt').style.margin = '0px';
	$(params[3] + 'Ctnt').style.width = nwdth + 'px';
	$(params[3] + 'Ctnt').style.height = nhght + 'px';
	$(params[3] + 'Root').style.display = 'block';
}

function toggleObjects(vis, who){
	if (vis!=null && vis != '') {
		// toggle the parent window
		if (typeof window.parent[who] == "undefined") {
	 		tag = parent.document.getElementsByTagName('select');
			for(i=tag.length-1;i>=0;i--) {
				tag[i].style.display=vis;
			}
		}
		// toggle some other window 
		else {
			try {
		 		tag = window.parent[who].document.getElementsByTagName('select');
				for(i=tag.length-1;i>=0;i--) {
					tag[i].style.display=vis;
				}
			} catch ( e ) { alert(e.toString());}
		}	
		
			//alert(who);
		/*
		tag=document.getElementsByTagName('iframe');
		for(i=tag.length-1;i>=0;i--) {
			tag[i].style.display=vis;
		}
		
		tag=document.getElementsByTagName('object');
		for(i=tag.length-1;i>=0;i--) {
			tag[i].style.display=vis;
		}*/
	}
}

