// set up browser detection
var myd, mydom, ie, ie4, ie5x, moz, mac, win, lin, old, ie5mac, ie5xwin, op;

myd = document;
n = navigator;
na = n.appVersion;
nua = n.userAgent;
win = ( na.indexOf( 'Win' ) != -1 );
mac = ( na.indexOf( 'Mac' ) != -1 );
lin = ( nua.indexOf( 'Linux' ) != -1 );

if ( !myd.layers ){
	mydom = ( myd.getElementById );
	op = ( nua.indexOf( 'Opera' ) != -1 );
	konq = ( nua.indexOf( 'Konqueror' ) != -1 );
	saf = ( nua.indexOf( 'Safari' ) != -1 );
	moz = ( nua.indexOf( 'Gecko' ) != -1 && !saf && !konq);
	ie = ( myd.all && !op );
	ie4 = ( ie && !mydom );

	/*
	ie5x tests only for functionality. ( dom||ie5x ) would be default settings. 
	Opera will register true in this test if set to identify as IE 5
	*/

	ie5x = ( myd.all && mydom );
	ie5mac = ( mac && ie5x );
	ie5xwin = ( win && ie5x );
}

//field selection functions

// carries info over
function selectall(thisobj) {
	for (var i=0; i < thisobj.options.length; i++) {
		thisobj.options[i].selected = true;
	}
}

// transfers data from one field to the next
function move(afield,bfield,max) {
	var thisalert = "";
	var thisfirst = true;
	var addvalue = "";
	var addtext = "";
	var addindex = "";
	var thisdupe = false;
	var setmax = true;
	if (afield.options) {

		for (var i=0; i < afield.options.length; i++) {
			if (afield.options[i].selected) {
				if (bfield.options.length < max) {
					addvalue = afield.options[i].value;
					addtext = afield.options[i].text;
					if (!entrydupe(afield.options[i].value,bfield)) {
						addindex = bfield.options.length;
						bfield.options[addindex] = new Option (addtext,addvalue);
						bfield.options[addindex].selected = true;
					}
					else {
						if (thisfirst) {
							//thisalert += "The following areas were duplicated:\n";
							//thisfirst = false;
						}
						//thisalert +=addtext+"\n";
						//thisdupe = true;
					}
				}
				else {
					if (setmax) {
						thisalert += "You may only add "+max+" items.\n";
						setmax = false;
					}
				}
			}
		}
		if (thisdupe || !setmax) {
			window.alert(thisalert+"\nPlease try again.");
		}
	}

}

// checks for duplicate fields
function entrydupe(value,bfield) {
	for (var j=0; j < bfield.options.length; j++) {
		if (bfield.options[j].value == value) {
			return true;
		}
	}
	return false;
}

// removes data from said field
function removeit(bfield) {
	if (bfield.options.length > 0) {
		var intialfield = bfield.options[bfield.options.selectedIndex].value;
		for (var i=0; i < bfield.options.length; i++) {
			if (bfield.options[i].value == intialfield) {
				bfield.options[i] = null;
			}
		}
		if (bfield.options.length > 0) {
			bfield.options[bfield.options.length-1].selected = true;
		}
	}
}

// removes all data from said field
function deleteall(obj) {
	while (obj.options.length > 0) {
		obj.options[0] = null;
	}
}

var clearDefaultTextObjects = new Object;
function clearDefaultText(obj) {
    var objId = obj.id;
    if (clearDefaultTextObjects[objId] != 1) {
        obj.value = '';
    }
    clearDefaultTextObjects[objId] = 1;
}

function openwin(url,winname) {
     my_url = url;
     pic_win = window.open(my_url,winname,'menubar,scrollbars,resizable,copyhistory,width=500,height=480');
     pic_win.focus();
}

function gcopenwin(url,winname) {
     my_url = url;
     pic_win = window.open(my_url,winname,'width=150,height=100');
     pic_win.focus();
}

function show_pic(url) {
     my_url = url;
     pic_win = window.open(my_url,'','menubar,scrollbars,resizable,status,copyhistory,width=420,height=500');
     pic_win.focus();
}

// Radio Button Validation
// copyright Stephen Chapman, 15th Nov 2004,14th Sep 2005
// you may copy this function but please keep the copyright notice with it
function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

function check_em_all() {
     for(var i = 0; i < document.check_box_list.elements.length; i++) {
	  if( document.check_box_list.elements[i].name.indexOf("do_me") > -1 ) {
	       document.check_box_list.elements[i].checked = 'true';
	  }
     }
}

function uncheck_em_all() {
     for(var i = 0; i < document.check_box_list.elements.length; i++) {
	  if( document.check_box_list.elements[i].name.indexOf("do_me") > -1 ) {
	       document.check_box_list.elements[i].checked = '';
	  }
     }
}

function generic_check_em_all(f,test) {
     form_name = f.name;
     this_form = eval ('document.' + form_name);
     
     for(var i = 0; i < this_form.elements.length; i++) {
	  if( this_form.elements[i].name.indexOf(test) > -1 ) {
	       this_form.elements[i].checked = '';
	       this_form.elements[i].click();
	  }
     }
}

function generic_uncheck_em_all(f,test) {
	
	 form_name = f.name;
     this_form = eval ('document.' + form_name);
	
     for(var i = 0; i < this_form.elements.length; i++) {
	  if( this_form.elements[i].name.indexOf(test) > -1 ) {
	       this_form.elements[i].checked = 'true';
	       this_form.elements[i].click();
	  }
     }
     
}

function customFunctionCreateWindow(elementID,width,height,left,top){

	var divId = createNewWindow(width,height,left,top); 
	
	document.getElementById('windowContent' + divId).innerHTML = document.getElementById(elementID).innerHTML;
	
}

function CreateSearchWindow(urlToExternalFile,width,height,left,top){		
    var divId = createNewWindow(width,height,left,top); 
    document.getElementById('windowContent' + divId).innerHTML = 'Content of new window';
    if(urlToExternalFile)addContentFromUrl(urlToExternalFile,divId);	// Add content from external file
}

function updateOptions(theElement, Values) {
     var myElement = document.getElementById(theElement);
     var arrayValues = Values.split('|');
     var have = new Object;
     
     for (var i = 0; i < arrayValues.length; i++) {
        have['v:'+ arrayValues[i]]= 1; 
     }
          
     for (var i = 0; i < myElement.options.length; i++) {
       var option_val = myElement.options[i].value;
       if (have['v:' + option_val] == 1) {
            myElement.options[i].selected = true;
       }
     }
}

function showClass(className) {
    var tags = AJS.$bytc(null,className);
    for (tag in tags){
        try{tags[tag].style.display='inline';}
        catch(x){}
    }
    return true;
}

function hideClass(className) {
    var tags = AJS.$bytc(null,className);
    for (tag in tags){
        try{tags[tag].style.display='none';}
        catch(x){}
    } 
    return true;
}

var fadeChange = function(objId,className) {
    AJS.setClass(AJS.$(objId),className);
    AJS.setOpacity(AJS.$(objId), 0);
    AJS.fx.fadeIn(AJS.$(objId));
}
    
var nofadeChange = function(objId,className) {
    AJS.setClass(AJS.$(objId),className);
}

var removeCurrentClass = function(tagName,className) {
    var tags = AJS.$bytc(tagName,className);
    for (var i = 0; i < tags.length; i++) {
        var tag = tags[0];
        try{AJS.removeClass(tag,'current');}
        catch(x){}
    }
}
function showAdvanced(advOptions) {
        if (document.getElementById) {
                // this is the way the standards work
                var style2 = document.getElementById(advOptions).style;
                style2.display = style2.display? "":"block";
        } else if (document.all) {
                // this is the way old msie versions work
                var style2 = document.all[advOptions].style;
                style2.display = style2.display? "":"block";
        } else if (document.layers) {
                // this is the way nn4 works
                var style2 = document.layers[advOptions].style;
                style2.display = style2.display? "":"block";
        }
}

function showHideElement(theElement, method) {
		
    if (method == 0 || method == '' || !method) {
        method = "inline";
    }
    
    // this is the way the standards work
    var style2 = AJS.$(theElement).style;
    style2.display =  (style2.display == 'none') ? method : 'none';
}

function showElement(theElement, method) {
				
		if (method == 0 || method == '' || !method) {
			method = "inline";
		}
        AJS.$(theElement).style.display = method;
}

function hideElement(theElement, method) {
    // this is the way the standards work
    var style2 = AJS.$(theElement).style;
    style2.display = "none";
}

function toggleElements(Element1,Element2) {
    var style1 = AJS.$(Element1).style;
    var style2 = AJS.$(Element2).style;
    style1.display = "none";
    style2.display = "inline";

}

toggleSliders = function(headedElement){
    var headerId = headedElement.id;
    var headerboxId = headerId + '_box';
    var mydisplay = (AJS.$(headerboxId).style.display == 'none') ? 'block' : 'none' ;
    AJS.setOpacity(AJS.$(headerboxId), 0);
    AJS.fx.fadeIn(AJS.$(headerboxId));
    AJS.$(headerboxId).style.display = mydisplay;    
}

function updateSpan(ElementId,SourceID) {
        if (document.getElementById) {
                // this is the way the standards work
                AJS.$(ElementId).innerHTML = document.getElementById(SourceID).value + " <img src='/images/sugar/edit_inline.gif'>";
        } 
}

function updateSpanText(ElementId,text) {

                AJS.$(ElementId).innerHTML = text;
        
}

function focusOn(ElementId) {
    AJS.$(ElementId).focus();
}

function aggregateFields(formname,fields,aggregateField,crf_id) {

	 var f = document[formname];
	 var aggregates = new Array;
     for(var i = 0; i < f.elements.length; i++) {
	  if( f.elements[i].name.indexOf(fields) > -1 ) {
	  	   if (f.elements[i].checked) {
	  	   		aggregates.push(f.elements[i].value);
	  	   }
	  }
     }
     //alert(aggregates.join('|'));
     
     new Ajax.Updater( aggregateField,  '/ajax_rq.smpl', { evalScripts: true,parameters: 'pid=gwt&t=1157385224&uid=&h=4d36ee41359e232aa34997d07f365a80&'+'fn=mls_update&crf_id='+crf_id+'&f=' + aggregateField + '&v='+aggregates.join('|'),asynchronous: 1,onComplete: function(request){document.getElementById(aggregateField + '_spinner').style.display='none'} } ) ; document.getElementById(aggregateField +'_spinner').style.display='inline';
     
}

function updateField(ElementId,Field,id) {

	 var myElement = AJS.$(ElementId);
	   
     new Ajax.Updater( Field,  '/ajax_rq.smpl', { evalScripts: true,parameters: 'pid=gwt&t=1157385224&uid=&h=4d36ee41359e232aa34997d07f365a80&fn=update_hotspot&hotspot_id='+id+'&f=' + Field + '&v='+myElement.value,asynchronous: 1,onComplete: function(request){document.getElementById(ElementId + '_spinner').style.display='none'} } ) ; document.getElementById(ElementId +'_spinner').style.display='inline';
     
}

function updateRadio(ElementId,fieldvalue,id) {
	   
     new Ajax.Updater( 'RD_' + ElementId,  '/ajax_rq.smpl', { evalScripts: true,parameters: 'pid=gwt&t=1157385224&uid=&h=4d36ee41359e232aa34997d07f365a80&'+'fn=update_hotspot&hotspot_id='+id+'&f=' + ElementId + '&v='+fieldvalue,asynchronous: 1,onComplete: function(request){document.getElementById(ElementId + '_spinner').style.display='none'} } ) ; document.getElementById(ElementId +'_spinner').style.display='inline';
     
}

function sendAllOptions(ElementId,Field,id) {

	 var myElement = document.getElementById(ElementId);
	 var values = new Array;
	 
	 for (var i = 0; i < myElement.options.length; i++) {
     		
     	   var option_val = myElement.options[i].value;
     	   values.push(option_val);	  	   
     }
     
     var stringVals = values.join(',');
	   
     new Ajax.Updater( Field,  '/ajax_rq.smpl', { evalScripts: true,parameters: 'pid=gwt&t=1157385224&uid=&h=4d36ee41359e232aa34997d07f365a80&'+'fn=update_hotspot&hotspot_id='+id+'&f=' + Field + '&v='+stringVals,asynchronous: 1,onComplete: function(request){document.getElementById(ElementId + '_spinner').style.display='none'} } ) ; document.getElementById(ElementId +'_spinner').style.display='inline';
     
}

function saveCheckboxsTohidden(formname,fields,hidden_field) {
	 var f = document[formname];
	 var aggregates = new Array;
     for(var i = 0; i < f.elements.length; i++) {
	  if( f.elements[i].name.indexOf(fields) > -1 ) {
	  	   if (f.elements[i].checked) {
	  	   		aggregates.push(f.elements[i].value);
	  	   }
	  }
     }
     //alert(aggregates.join('|'));
     var myElement = document.getElementById(hidden_field);
     myElement.value = aggregates.join('|');
}

function saveSelectTohidden(the_select,hidden_field) {
    var myElement = document.getElementById(hidden_field);
    var mySelect = document.getElementById(the_select);
    var values = new Array;
    for (var i = 0; i < mySelect.options.length; i++) {
        if (mySelect.options[i].selected){
            var option_val = mySelect.options[i].value;
            values.push(option_val);	
        }
    }
    var stringVals = values.join('|');
    myElement.value = stringVals;
}

function saveTextTohidden(text_box,hidden_field) {
    var myElement = document.getElementById(hidden_field);
    myElement.value = text_box.value;
}

function saveTextFieldTohidden(textfield,hidden_field) {
    var myElement = document.getElementById(hidden_field);
    var text_box = document.getElementById(textfield);
    myElement.value = text_box.value;
}

function saveValueTohidden(myvalue,hidden_field) {
    var myElement = document.getElementById(hidden_field);
    myElement.value = myvalue;
}

function saveCheckBoxTohidden(checkboxID,hidden_field) {
    var myElement = AJS.$(hidden_field);
    if (AJS.$(checkboxID).checked) {
        AJS.$(hidden_field).value = AJS.$(checkboxID).value; 
    } else {
        AJS.$(hidden_field).value = ''; 
    }
}

// cookies.js
// Derived from the Bill Dortch code at http://www.hidaho.com/cookies/cookie.txt

var today = new Date();
var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);

function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) { endstr = document.cookie.length; }
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {
			return getCookieVal (j);
			}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
		}
	return null;
}

function DeleteCookie (name,path,domain) {
	if (GetCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
		}
}

function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

// SAS_List functions

var orders = new Object;

function SAS_List(elementPrefix,arg,standalone,parentID,postCallback) {
    var container = AJS.$(elementPrefix + '_container');
    
    if (parentID) {
        container = AJS.$(parentID + '_' + elementPrefix + '_container');
    }
        
    AJS.RCN(container, AJS.TN("Doing search..."));

    var url = "/json/index.smpl";
    var d = AJS.loadJSONDoc(url);
    d.addCallback(function(o) {
	    showResults(container, o, elementPrefix);
        if ( postCallback ){
            postCallback(o);
        }
    }); 
    
    var form = AJS.$(elementPrefix + '_form');
    
     if (parentID) {
        AJS.$f(form, 'parent').value = parentID;
    }
    
   var req = AJS.formContents(form);
   req.arg = arg;
   req.pid = 'gwt';
   req.t = '###etime###';
   req.uid = '###get_sessionvar u_id###';
   
   // first is 0 based server side - so we need to adjust it
   var server_first = req.first - 1;
   server_first = (server_first < 0) ? 0 : server_first;
   req.first = server_first;
   
    d.sendReq(req);
    
    if (!standalone) {
        return false;
    }
        
}    
      
function showResults(container, o, elementPrefix) {
    var tmpl_image = AJS.$(elementPrefix + '_template').innerHTML;
    AJS.RCN(container, null);
    var form = AJS.$(elementPrefix + '_form'); 
    var total = o.ResultSet.list_meta.total;
    total |= 0;
    AJS.$f(form, 'total').value = total;
    rePage('n',elementPrefix);
    AJS.map(o.ResultSet.list, function(data) {
        var img = AJS.HTML2DOM(AJS.RND(tmpl_image, data));
        AJS.setOpacity(img, 0);
        AJS.fx.fadeIn(img);
        AJS.ACN(container, img);
    });
}

function reSort(val,form) {
    
    var myform = AJS.$(form);
    AJS.$f(myform, 'sort').value = val;
    var order = (orders[val] == 'ASC') ? 'DESC' : 'ASC';
    AJS.$f(myform, 'order').value = order;
    orders[val]= order;

}

function rePage(direction,form_prefix) {
        
    // direction is f(orward) or b(ack) or n(one)
    
    var myform = AJS.$(form_prefix + '_form');
    var perpage = parseInt(AJS.$f(myform, 'pp').value);
    var current_first = parseInt(AJS.$f(myform, 'first').value,10);
    
    var total = AJS.$f(myform, 'total').value;
    total |= 0;
    
    var current_last = parseInt(current_first) + parseInt(perpage);
    
    if (current_last < total) {
        if (direction == 'f') {
            AJS.$f(myform, 'first').value = current_last;
        }
    } 
    
    if (direction == 'b') {
        AJS.$f(myform, 'first').value = parseInt(current_first) - parseInt(perpage);
        if (parseInt(AJS.$f(myform, 'first').value) < 0) {
            AJS.$f(myform, 'first').value = 0;
        }
    }
    
    current_first = parseInt(AJS.$f(myform, 'first').value,10);
    current_first = (current_first < 1) ? 1 : current_first;
    AJS.$f(myform, 'first').value = current_first;
    
    var display_last = parseInt(current_first) + parseInt(perpage) - 1;
    display_last = (display_last > total) ? total : display_last;
    
    AJS.$(form_prefix + '_total').innerHTML = 'of ' + total;
    AJS.$(form_prefix + '_recrange').innerHTML = '-' + display_last;
            
}

/**
* This array is used to remember mark status of rows 
*/
var marked_row = new Array;

/**
* This array is used to remember the default row colors
*/
var defaultColors = new Array;
defaultColors['row1'] = "#e4eedd";
defaultColors['row2'] = "#c9dcbb";

/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
 
//setPointer(this, 'contactListRow%(USER_ID)', 'over', 'row%(ROWMARKER)', '#f0a975', '');
function setPointer(theRow, theRowNum, theAction, theDefaultColorStyle, thePointerColor, theMarkColor) {

    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }
 
    var theDefaultColor = defaultColors[theDefaultColorStyle];

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3
    
    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == '' || currentColor == null
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function


function GW_GetContent(url,elementID,invisibility,no_spin) {
    if (!elementID) {elementID = GW_GetContent_default_elementID;}
    var container = AJS.$(elementID);
    var my_image = AJS.IMG({id: elementID + '_d_spinner', src: '/images/indicator.gif', width: '8'});
    if (!no_spin) {
        AJS.RCN(container, my_image);
    }
    var d = AJS.getRequest(url);
    d.addCallback(function(res_txt, req) { 
            if(invisibility) {
                container.style.display='none';
            } else {
                var response = res_txt;
                var img = AJS.HTML2DOM(response);
                AJS.setOpacity(img, 0);
                AJS.fx.fadeIn(img);
                AJS.RCN(container, img);
                container.style.display='block';
            }
    });
    d.addErrback(function(res_txt, req) {  });
    d.sendReq();
    return false;
}   

function GW_GetDOMContent(containerElmId, templateElmId) {
    var tmpl_image = AJS.$(templateElmId).innerHTML;
    var container = AJS.$(containerElmId);
    var img = AJS.HTML2DOM(tmpl_image);
    AJS.setOpacity(img, 0);
    AJS.fx.fadeIn(img);
    AJS.RCN(container, img);
}

function GW_AjaxWrapper(formId,fn,callback) {
            var url = "/ajax_rq.smpl";
            var d = AJS.getRequest(url);        
            
            var form = AJS.$(formId);
            var req = GW_getformContents(formId);
            
            req.fn = fn;
            req.pid = 'gwt';
            req.t = '###etime###';
            req.uid = '###get_sessionvar u_id###';
            
            if (callback) {
                d.addCallbacks(function(res_txt, req) { eval(callback); });
            }
            
            d.sendReq(req);
}

function GW_AjaxFieldWrapper(fieldID,fn,callback,did) {
            var url = "/ajax_rq.smpl";
            var d = AJS.getRequest(url);        
            
            var req = {};
            req.field = fieldID;
            req.v = AJS.$(fieldID).value;
            req.fn = fn;
            req.pid = 'gwt';
            req.t = '###etime###';
            req.uid = '###get_sessionvar u_id###';

            if (did) {
                req.did = did;
            }

            if (callback) {
                d.addCallbacks(function(res_txt, req) { eval(callback); });
            }

            d.sendReq(req);
}

GW_submitAjaxForm = function(formId,containerId,callback) {
    var d = AJS.getRequest('/rq.smpl?pid=gwt&t=1206635544&uid=2&h=7639ced77118aeca7c9a84ca5e4c39ce&'); 
    var parameters = GW_getformContents(formId);
    
     if (!containerId) {containerId = GW_GetContent_default_elementID;}
    // add in all the 'selected' items
    
    
    if (callback) {
        d.addCallbacks(function(res_txt, req) { eval(callback); });
    }
    
    d.addCallbacks(function(res_txt, req) { document.getElementById('login_spinner').style.display='none';
                                                var response = res_txt;
                                                var img = AJS.HTML2DOM(response);
                                                var container = AJS.$(containerId);
                                                AJS.setOpacity(img, 0);
                                                AJS.fx.fadeIn(img);
                                                AJS.RCN(container, img); });
                                                
    // d.addErrback(function(res_txt, req) { alert("Error encountered.") });
    
    d.sendReq(parameters);
    document.getElementById('login_spinner').style.display='inline'; 
    return false;
}

GW_getformContents = function(formId) {
    var form = AJS.$(formId);
    var r = {};
    var fn = function(elms) {
        AJS.map(elms, function(e) {
            if(e.name)
                if (e.type == 'checkbox') {
                    r[e.name] = (e.checked) ? e.value : '';
                } else {
                    r[e.name] = e.value || '';
                }
        });
    }
    var sfn = function(elms) {
        AJS.map(elms, function(e) {
            if(e.name) {
                r[e.name] = GW_getSelectValue(e.id) || '';
            }
        });
    }
    fn(AJS.$bytc('input', null, form));
    fn(AJS.$bytc('textarea', null, form));
    sfn(AJS.$bytc('select', null, form));
    delete r['extend'];
    return r;
}

GW_getSelectValue = function(selectId) {
    var select = AJS.$(selectId);
    if (select.selectedIndex > -1) {
        return select.options[select.selectedIndex].value;
    } else {
        return '';
    }
}

GW_submitForm = function(formId,containerId) {

    var d = AJS.getRequest(AJS.$(formId).action);
    var parameters = AJS.formContents(AJS.$(formId));
    delete parameters['extend'];
    d.addCallback(function(res_txt, req) { document.getElementById('login_spinner').style.display='none';
                                                var response = res_txt;
                                                var img = AJS.HTML2DOM(response);
                                                var container = AJS.$(containerId);
                                                AJS.setOpacity(img, 0);
                                                AJS.fx.fadeIn(img);
                                                AJS.RCN(container, img); });
    d.addErrback(function(res_txt, req) { alert("Error encountered.") });
    d.sendReq(parameters);
    document.getElementById('login_spinner').style.display='inline'; 
    return false;
}

function move_in(img_name,img_src) {
	document[img_name].src=img_src;
}

function move_out(img_name,img_src) {
	document[img_name].src=img_src;
}

GB_GWShow = function(caption, url, /* optional */ height, width, loading, callback_fn) {
    var options = {
        caption: caption,
        height: height || 500,
        width: width || 500,
        fullscreen: false,
        show_loading: loading || false,
        callback_fn: callback_fn
    }
    var win = new GB_Window(options);
    return win.show(url);
}

var imagePreloader = function(images) {
    var i = 0;
    var imageObj = new Image();
    for(i=0; i< images.length; i++) {
      imageObj.src=images[i];
    }
}

var rotateFlash = function(conf) {

    // usage: rotateFlash({id:'Flash',slideDelay:7000,slideShowRestartDelay:17000,resetToFirstImage:1});
    
    var slideDelay = conf.slideDelay;
    var slideShowRestartDelay = conf.slideShowRestartDelay;
    var divId = conf.id;
    var resetToFirstImage = conf.resetToFirstImage;
    
    var imageCount = jQuery('#' + divId).children().size(); 
    jQuery('#' + divId + ' img').hide();
    jQuery('#' + divId + ' :first-child').fadeIn(1000);
    
    var i = (resetToFirstImage) ? 0 : 1;
        
    var flashInterval = setInterval(function(){
                                                    if (i < imageCount) {
                                                        jQuery('#' + divId + ' :first-child').fadeOut().next('img').fadeIn(1000).end().appendTo('#' + divId);
                                                        i++;
                                                    } else {
                                                        clearInterval(flashInterval);
                                                        if (slideShowRestartDelay > 0) {
                                                            setTimeout ( "rotateFlash({id:'" + divId + "',slideDelay:" + slideDelay + ",slideShowRestartDelay:" + slideShowRestartDelay + ",resetToFirstImage:" + resetToFirstImage + "})", slideShowRestartDelay );
                                                        }
                                                    }
                                                        
                                                },slideDelay);
                                                         
}
