function asyncInit(userID)
{
	
	var sKey = 'none';//dummy value. not used but van be uased as a name of a div to display additional info
	if (userID)
	{
		performRequest("requestAction.cfm?class=ajax.miscFacade&method=asyncUserInit('"+userID+"')&key="+sKey+"",_genericCallback);
	}
}

function viewImage(imagePath)
{

	var key = 'profileImages'; //the div that we will popluate
		
	/*ajax loading*/
	if (document.getElementById('ajaxLoader')) {
      el = document.getElementById('ajaxLoader');
	  el.style.display = 'inline';
      el.innerHTML ='loading image...';
	}
	
	performRequest(
		"requestAction.cfm?class=ajax.miscFacade&method=viewImage('"+imagePath+"')&key="+key+"",_genericCallback);
	

}

function getChildData(parentObject, keyDiv, selectName)
{

	var lstParent = ''; //list of parents selected
	
	if(!selectName)	selectName = ''; //empty select name

	for (var i=0; i<parentObject.options.length; i++) {
		if (parentObject.options[i].selected == true) {
				if ( (lstParent.length)==0 ){
					lstParent = parentObject.options[i].value;
				}
				else{
				lstParent = lstParent + ',' + parentObject.options[i].value;
				}
		}
	}

	/*ajax loading*/
	if (document.getElementById('ajaxLoader')) {
      el = document.getElementById('ajaxLoader');
	  el.style.display = 'inline';
      el.innerHTML ='loading data...';
	}
		

	performRequest(
		"requestAction.cfm?class=ajax.miscFacade&method=getObject('"+lstParent+"', '"+selectName+"')&key="+keyDiv+"",_genericCallback, false);
	

}

function checkUser(objName) {  
		
	var o = document.getElementById(objName);
	if (o)
	{
		var value = o.value;
		var field = o.id;
		var sKey = 'CheckUser';// used in callback function
	performRequest("requestAction.cfm?class=ajax.miscFacade&method=getUser('"+value+"', '"+field+"')&key="+sKey+"",_genericCallback);

	}

}

function saveUserDisclaimer(userID,disclaimerID, statusID) {	

	if (userID)
	{
		var thisUserID = document.getElementById(userID).value;

	}
	else
	{
		var thisUserID = '';
	}
	
	if (disclaimerID)
	{
		var thisDisclaimerID= document.getElementById(disclaimerID).value;

	}
	else
	{
		var thisDisclaimerID = '';
	}
	
	if (statusID)
	{
		var thisStatusID = document.getElementById(statusID).value;

	}
	else
	{
		var thisStatusID = '';
		
	}	

	var sKey = 'none';// dummy value - OK as long it is not null
	
performRequest("requestAction.cfm?class=ajax.miscFacade&method=addUserDisclaimer('"+thisUserID+"','"+thisDisclaimerID+"','"+thisStatusID+"')&key="+sKey+"",_genericCallback);
	
	}
	

function saveSearchAttribute(attribute,order, parentID) {	

	var oTypeID = document.getElementById(attribute);
	var typeID = oTypeID.id;
	var value = oTypeID.value;
	
	value = value.replace(/\'/g,'$singlequotation|');
	value = value.replace(/\&/g,'$amp|');
	value = value.replace(/\#/g,'$hash|');
	value = value.replace(/\;/g,'$scolon|');
	
	var oOrderID = document.getElementById(order);
	var order = oOrderID.value;

	if (parentID){
		//if parentid defined
		var oParentID = document.getElementById(parentID);
		var parentID = oParentID.value;
	}else{	
		var parentID = '';
	}
	var sKey = 'existing' + attribute;// used in the callback function to display alert

performRequest("requestAction.cfm?class=ajax.miscFacade&method=AddSearchAttribute('"+typeID+"','"+value+"','"+parentID+"','"+order+"')&key="+sKey+"",_genericCallback);
	
	}
	

function _genericCallback(xmlHttp)
{
	var xmlDoc = xmlHttp.responseXML;
	
	if(xmlDoc == null || xmlDoc.documentElement == null)
	{
		outputRequestError(xmlHttp.responseText);	
	}
	else
	{	
		var root = xmlDoc.documentElement;
		var cn = root.childNodes;
		var l = cn.length;
		var error = null;
		var result = null;
		var req = null;
		var sClass = null;
		var sMmethod = null;
		var sKey = null;
		
		for(var i = 0; i < l; i++) 
		{
			
			switch(cn[i].tagName)
			{
				case "error":
					//error = cn[i].xml;
					error = cn[i].firstChild.nodeValue;
					break;
					
					
				case "result":
					result = cn[i].firstChild.nodeValue;
					break;

				case "request":
					req = cn[i].childNodes;
					var l2 = req.length;
					for(var x=0;x<l2;x++)
					{
						switch(req[x].tagName)
						{
							case 'class':
								sClass = req[x].firstChild.nodeValue;
								break;
							case 'method':
								sMethod = req[x].firstChild.nodeValue;
								break;
							case 'key':
								sKey = req[x].firstChild.nodeValue;
								break;
						}
					}
					break;

			}
		}
		
		if(error)
		{
			outputRequestError(error);
		}
		else if(result)
		{
			
			if(sKey.length){
				
				var oDiv = document.getElementById(sKey);
				if (oDiv)
				{
					oDiv.innerHTML = result;
					//ajax loading
					if (document.getElementById('ajaxLoader')){
						el = document.getElementById('ajaxLoader');
						el.style.display='none';					
					}
		
				}
				else
				{	
					//  sKey is set in js calling function, result is set if ajaxFacade.
					if (sKey == 'CheckUser' && result.length > 2) { alert(result)};
					alert(result);
				}
		
			}
		   
		}
		else
		{
			alert("A problem has occured, please refresh your page and try again.");
		}
	}
}



function outputRequestError(errorString)
{
	e = document.getElementById("scriptOutput");
	if(e)
	{
		e.innerHTML = errorString.replace(/</,"&lt;");
	}
	else
	{
		//alert('error');
		//alert(errorString) ;
		document.write(errorString);
	}
}

var Drag = {

    obj : null,

    init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
    {
        o.onmousedown    = Drag.start;

        o.hmode            = bSwapHorzRef ? false : true ;
        o.vmode            = bSwapVertRef ? false : true ;

        o.root = oRoot && oRoot != null ? oRoot : o ;

        if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
        if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
        if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
        if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

        o.minX    = typeof minX != 'undefined' ? minX : null;
        o.minY    = typeof minY != 'undefined' ? minY : null;
        o.maxX    = typeof maxX != 'undefined' ? maxX : null;
        o.maxY    = typeof maxY != 'undefined' ? maxY : null;

        o.xMapper = fXMapper ? fXMapper : null;
        o.yMapper = fYMapper ? fYMapper : null;

        o.root.onDragStart    = new Function();
        o.root.onDragEnd    = new Function();
        o.root.onDrag        = new Function();
    },

    start : function(e)
    {
        var o = Drag.obj = this;
        e = Drag.fixE(e);
        var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
        var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
        o.root.onDragStart(x, y);

        o.lastMouseX    = e.clientX;
        o.lastMouseY    = e.clientY;

        if (o.hmode) {
            if (o.minX != null)    o.minMouseX    = e.clientX - x + o.minX;
            if (o.maxX != null)    o.maxMouseX    = o.minMouseX + o.maxX - o.minX;
        } else {
            if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
            if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
        }

        if (o.vmode) {
            if (o.minY != null)    o.minMouseY    = e.clientY - y + o.minY;
            if (o.maxY != null)    o.maxMouseY    = o.minMouseY + o.maxY - o.minY;
        } else {
            if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
            if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
        }

        document.onmousemove    = Drag.drag;
        document.onmouseup        = Drag.end;

        return false;
    },

    drag : function(e)
    {
        e = Drag.fixE(e);
        var o = Drag.obj;

        var ey    = e.clientY;
        var ex    = e.clientX;
        var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
        var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
        var nx, ny;

        if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
        if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
        if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
        if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

        nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
        ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

        if (o.xMapper)        nx = o.xMapper(y)
        else if (o.yMapper)    ny = o.yMapper(x)

        Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
        Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
        Drag.obj.lastMouseX    = ex;
        Drag.obj.lastMouseY    = ey;

        Drag.obj.root.onDrag(nx, ny);
        return false;
    },

    end : function()
    {
        document.onmousemove = null;
        document.onmouseup   = null;
        Drag.obj.root.onDragEnd(    parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
                                    parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
        Drag.obj = null;
    },

    fixE : function(e)
    {
        if (typeof e == 'undefined') e = window.event;
        if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
        if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
        return e;
    }
};
//this displays div if it's hidden and hides it if it's displayed
function showHideDiv(divName) {
	if (document.getElementById(divName).style.display=="block") {
		document.getElementById(divName).style.display="none";
	} else {
		document.getElementById(divName).style.display="block";
	}
}
//this displays the showDiv, and hides the hideDiv
function showDivHideDiv(showDiv, hideDiv) {

		document.getElementById(showDiv).style.display="block";
		document.getElementById(hideDiv).style.display="none";

}
//this displays the page that is passed through, and hides the rest
function showHideDivPage(divName) {
	
	for(i=0; i<6; i++){
		pageName = 'page' + i;
		if(document.getElementById(pageName)){
		//if div exists, then hide it, UNLESS its the divName specified
			if(pageName == divName){
				document.getElementById(pageName).style.display="block";				
			}else{ 
				document.getElementById(pageName).style.display="none";		
			}
		}
		
	}	
}

function currentTab(idName){
		
		//loop through other tabs, if other tab is selected and name doesn't equal to the one selected, then change back
		var i=1;
		var nomoretabs=0;
		do 
		{
			var tabName = "tab" + i;
			if(document.getElementById(tabName)){
				if(document.getElementById(tabName).className == "" && tabName == idName){
					document.getElementById(tabName).className = "current";
				} else {
					document.getElementById(tabName).className = "";
				}
				i=i+1;
			}else{
				nomoretabs=1;
			}
		}
		while (nomoretabs==0)		

}

function getSubLocation(){
	if(parent.frames['locationFrame'] && parent.frames['locationFrame'].document.getElementById('location').value != ""){
		document.forms[0].location.value = parent.frames['locationFrame'].document.getElementById('location').value;
		document.forms[0].subLocation.value = parent.frames['locationFrame'].document.getElementById('subLocation').value;
	}

	if(parent.frames['nativeFrame'] && parent.frames['nativeFrame'].document.getElementById('location').value != ""){
	
		document.forms[0].nativeLocation.value = parent.frames['nativeFrame'].document.getElementById('location').value;
		document.forms[0].nativeSublocation.value = parent.frames['nativeFrame'].document.getElementById('subLocation').value;
	}
}

function checkFields(fieldList) {
	var fieldArray = fieldList.split(",");
	var requiredList='';
	for(var i=0; i<fieldArray.length; i++){	
		if (document.getElementById(fieldArray[i]).value=='') requiredList+=fieldArray[i]+' required.\n';
	}
	if (requiredList!='') {
		alert(requiredList);
		return false;	
	} else {
		return true;	
	}
}

// shows div
function showDiv(divName) {
		document.getElementById(divName).style.display="block";
}

// hides div
function hideDiv(divName) {
		document.getElementById(divName).style.display="none";
}

function showHideById(id) {
	if (document.getElementById(id).style.display == "none") {
		document.getElementById(id).style.display = "";	
	} else {
		document.getElementById(id).style.display = "none";
	}
}

function showHideImage(img) {
	if(img.src.indexOf('showHide') == -1) {
		img.src = 'images/showHide.gif';
	} else {
		img.src = 'images/hide.gif';
	}	
}

function showImageUploadField(s) {
	if (s == 'images') {
		document.getElementById('fullImageNote').style.display = '';
		document.getElementById('thumbImageField').style.display = '';
		document.getElementById('fileThumbField').disabled = '';
		document.getElementById('requiredFields_fileThumbField').name = 'requiredFields';
	} else {
		document.getElementById('fullImageNote').style.display = 'none';
		document.getElementById('thumbImageField').style.display = 'none';
		document.getElementById('fileThumbField').disabled = true;
		document.getElementById('requiredFields_fileThumbField').name = '_';
	}
}