function hidediv(id)
{
    //safe function to hide an element with a specified id
    if (document.getElementById)
    {
        // DOM3 = IE5, NS6
        document.getElementById(id).style.display = 'none';
    }
    else
    {
        if (document.layers)
        {
           // Netscape 4
            document.id.display = 'none';
        }
        else
        {
           // IE 4
           document.all.id.style.display = 'none';
        }
    }
}

function giftBoxCheck(redirectURL, sessionID, clientID, eventID) {
     
    var gift = document.getElementById('gift' + sessionID);
    //window.alert(document.getElementById('gift' + sessionID));
    if(gift && gift.checked == true) {
        cartParams = '&client_id='  + clientID + '&event_id=' + eventID + '&addtocart=' + sessionID;
        giftwin=dhtmlwindow.open('giftWindow', 'iframe', 'http://www.dcprovidersonline.com/request.php?func=giftCard' + cartParams, 'Gift Card:', 'width=400px,height=200px,center=1');
        //window.parent.location.href=redirectURL + "&GIFT"; 
    } else {
        window.parent.location.href=redirectURL;
    }
    
}
 function send_input_elements(doc)
 {

     //loop through all the form elements and display them by the input type then identify them by input name.
     var input_data = '';

     for (i = 0; i < doc . elements . length; i++)
     {
         var key = doc . elements[i] . name;
         if (doc.elements[i] . getAttribute('type') == 'radio')
         {
             	var id = doc. elements[i].id;
             	if (doc.elements[i].checked) { 

	                var value = doc . elements[i] .value;
	                input_data = input_data + doc . elements[i] . name + '=' +  value + '&';
				}
         } else {
         var value = doc . elements[i] . value ;
         input_data = input_data + doc . elements[i] . name + '=' +  value + '&';

         }

     }
     return input_data;
 }
 
 function $()
{
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++)
        {
        var element = arguments[i];
        if (typeof element == 'string')
            element = document.getElementById(element);
        if (arguments.length == 1)
            return element;
        elements.push(element);
        }
    return elements;
}

 function getData(dataSource, divID, doc)
 {

	 if (XMLHttpRequestObject)
     {
     	
			
         eval("var obj = document.getElementById(divID);");

         XMLHttpRequestObject . open("POST", dataSource);
         XMLHttpRequestObject . setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');


         XMLHttpRequestObject . onreadystatechange = function ()
         {
             if (XMLHttpRequestObject . readyState == 4 && XMLHttpRequestObject . status == 200)
             {
                 obj . innerHTML = XMLHttpRequestObject . responseText;

					// Login Clause - refresh page if valid login.
                	if (divID == 'login_box' ) {
                 	window.location.reload(true);
                	}
                	///////
                	
             }
         }


         if ($(doc))
         {
             var input_data = send_input_elements($(doc));
         } else
         {
             input_data = null;
         }
         XMLHttpRequestObject . send(input_data);
     }
 }

function show_inline_div(id)
{
    //safe function to show an element with a specified id
    if (document.getElementById)
    {
        // DOM3 = IE5, NS6
        document.getElementById(id).style.display = 'inline';
    }
    else
    {
        if (document.layers)
        {
           // Netscape 4
            document.id.display = 'inline';
        }
        else
        {
            // IE 4
            document.all.id.style.display = 'inline';
        }
    }
}
function showdiv(id)
{
    //safe function to show an element with a specified id
    if (document.getElementById)
    {
        // DOM3 = IE5, NS6
        document.getElementById(id).style.display = 'block';
    }
    else
    {
        if (document.layers)
        {
           // Netscape 4
            document.id.display = 'block';
        }
        else
        {
            // IE 4
            document.all.id.style.display = 'block';
        }
    }
}

function togglediv(id)
{
    //safe function to hide an element with a specified id
    if (document.getElementById)
    {
        // DOM3 = IE5, NS6
        if (document.getElementById(id).style.display == 'block') {
        document.getElementById(id).style.display = 'none';
        }
        if (document.getElementById(id).style.display == 'none') {
        document.getElementById(id).style.display = 'block';
        }
    }
    else
    {
        if (document.layers)
        {
           // Netscape 4
           if (document.id.display == 'none') {
            document.id.display = 'block';
            }
           if (document.id.display == 'block') {
            document.id.display = 'none';
            }
        }
        else
        {
           // IE 4
           if (document.all.id.style.display == 'none') {
           document.all.id.style.display = 'block';
           }
           if (document.all.id.style.display == 'block') {
           document.all.id.style.display = 'none';
           }
        }
    }
}

function validate_checkout_form()
{
		
		if(document.purchaseform.valid_user.value=='') {
		window.alert ('Please LOG IN or Create an Account.');
		return false;
		}
		if(document.purchaseform.card_number.value=='') {
		window.alert ('Please enter Credit Card #.');
		return false;
		}
		if(document.purchaseform.expire_month.value=='') {
		window.alert ('Please enter expiration month.');
		return false;
		}
		if(document.purchaseform.expire_year.value=='') {
		window.alert ('Please enter expiration year.');
		return false;
		}
}

function validate_register_form()
{
  
	if(document.registerform.user_name.value=='') {
	window.alert ("You must enter a username!");
	return false;
	}
	
	if(document.registerform.user_email.value=='') {
	window.alert ("You must enter your email address!");
	return false;
	}
	if(document.registerform.firstname.value=='') {
	window.alert ("Please enter your first name!");
	return false;
	}
	if(document.registerform.lastname.value=='') {
	window.alert ("Please enter your last name!");
	return false;
	}
	if(document.registerform.address1.value=='') {
	window.alert ("Please enter your street address!");
	return false;
	}
	
	if(document.registerform.city.value=='') {
	window.alert ("Please enter your city!");
	return false;
	}
	
	if(document.registerform.state.value=='') {
	window.alert ("Please enter your state!");
	return false;
	}
	
	if(document.registerform.zipcode.value=='') {
	window.alert ("Please enter your zip code!");
	return false;
	}

	if(document.registerform.homephone.value=='') {
	window.alert ("Please enter your home phone!");
	return false;
	}

}

function register_password_verification () {

	if(document.registerform.password.value=='') {
		window.alert ('Please enter a password.');
		return false;
		}
	
	if(document.registerform.password_verify.value=='') {
		window.alert ('Please Re-Enter your password.');
		return false;
		}
	
	if(document.registerform.password.value!=document.registerform.password_verify.value) {
		window.alert ('Passwords Dont Match!');
		return false;
		}	
	
}

function ChangeBGColor(field, color){
	document.getElementById(field).style.backgroundColor=color;
}

function viewpreview(theURL) { //v2.0
try {
msgWindow = open(theURL, 'FlashPlayer', 'width=730,height=610,left=0,top=0, location=no, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no');
if (msgWindow.opener == null) msgWindow.opener = self;
if (window.focus) msgWindow.focus();
	}
catch (e) {
		alert ("Popups are blocked");
	
}
}



// ==== LAMPCODER2005: RIGHT MENU FUNCTIONS ==== //
// define here list of used class names
var rm_class_names = {
  ch_over: 'over',
  ch_out: 'out'
};
// define here right menu table id
var rm_parent_id = 'right-menu';
var rm_childs_tagname = 'li';

// right menu style & event actions initialisation function
function RightMenu_Init()
{

  // get parent object
  var parent = document.getElementById(rm_parent_id);
  // if parent not found - exit
  if (!parent) return;

  // get all childs of this parents
  var childs = parent.getElementsByTagName(rm_childs_tagname);
  // run through all childs and :
  // 1) set class name to them
  // 2) set onMouseOver event action
  // 3) set onMouseOut event action
  for (var i = 0; i < childs.length; i++)
  {
    childs[i].className   = rm_class_names.ch_out;
    childs[i].onmouseover = RightMenu_OnMouseOver;
    childs[i].onmouseout  = RightMenu_OnMouseOut;
  }

  return;
}

function RightMenu_OnMouseOver(e)
{
  RightMenu_ChangeCellStyle(e,'over');
  return;
}

function RightMenu_OnMouseOut(e)
{
  RightMenu_ChangeCellStyle(e,'out');
  return;
}

function RightMenu_ChangeCellStyle(e, e_type)
{
  var e = e || window.event;
  if(!e) return;

  var td = e.target ? e.target : (e.srcElement ? e.srcElement : null);
  if (td == null) return;

  td.className = rm_class_names['ch_'+e_type];

  return;
}
function viewpreview(theURL) { //v2.0
try {
msgWindow = open(theURL, 'FlashPlayer', 'width=470,height=400,left=200,top=200, location=no, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no');
if (msgWindow.opener == null) msgWindow.opener = self;
if (window.focus) msgWindow.focus();
	}
catch (e) {
		alert ("Popups are blocked");
	
}
}
function UploaderPopUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=450,height=350,left = 440,top = 312');");
}

function check_session(field) {
if (arr.in_array(document.sessionform.sessiond_id)) {
alert('session exists!');
}
}
	
function switchid(id){	
hideallids();
showdiv(id);
}
	
function hideallids(){
//loop through the array and hide each element by id
for (var i=0;i<ids.length;i++){
hidediv(ids[i]);
}		  
}

function disableform(){  
var header_logo = document.getElementById('header_logo'); 
var upper_right = document.getElementById('upper_right');
var upper_left = document.getElementById('upper_left');
var catheaderbg = document.getElementById('catheaderbg'); 
var main_color = document.getElementById('main_color'); 
var light_shade = document.getElementById('light_shade'); 
var dark_shade = document.getElementById('dark_shade');
header_logo.disabled=true;
upper_right.disabled=true;
upper_left.disabled=true;
catheaderbg.disabled=true;
main_color.disabled=true;
light_shade.disabled=true;
dark_shade.disabled=true;
} 

function enableform(){  
var header_logo = document.getElementById('header_logo'); 
var upper_right = document.getElementById('upper_right');
var upper_left = document.getElementById('upper_left');
var catheaderbg = document.getElementById('catheaderbg'); 
var main_color = document.getElementById('main_color'); 
var light_shade = document.getElementById('light_shade'); 
var dark_shade = document.getElementById('dark_shade');
header_logo.disabled=false;
upper_right.disabled=false;
upper_left.disabled=false;
catheaderbg.disabled=false;
main_color.disabled=false;
light_shade.disabled=false;
dark_shade.disabled=false;
} 
function grayOut(vis, options) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 70;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }   
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';				 
  } else {
     dark.style.display='none';
  }
  }
///////////////////////////////////////////////////////////////////////////
//                                                                       //
// NOTICE OF COPYRIGHT                                                   //
//                                                                       //
// "Open Compass" - opencompass.org                                      //
//                                                                       //
// Copyright (C) 2009 onwards Compass Integrated Solutions LLC	         //
//                                                                       //
// All rights reserved.                                                  //
// This material may not be duplicated for any profit-driven enterprise. //
//                                                                       //
///////////////////////////////////////////////////////////////////////////

/// AJAX FILTER/SORT FUNCTIONS
var AJAX_LOADING = 0;


// AJAX VARS
var AJAX_TIMEOUT = 20000;
var AJAX_BUST_CACHE = false;
var CP_CLASS_ajaxconnectionerror = 'Connection Error';
/*
/ Login Block class functions
*/                        
	/*
	/  Timer function fired with multi-site selection 
	/  Will automatically login user after specified number of seconds
	/  Time is set when the function is called from the login class (10sec default)
	*/
	var login_timer;
    auto_login_timer = function(time) {
		o = $('failedmessage');
	    if (o) {
	    	o.innerHTML=CP_LOGIN_autologinin+' '+time+' '+CP_LOGIN_timedisplaysec;
	    	time = time-1;
		}
	    if (time > 0 && $('ajax_form_action').value != 'login') {
	    	login_timer = setTimeout("auto_login_timer("+time+");", 1000, "Javascript");
	    	return login_timer;
	    } else {
	    	return login();
	    }
	}; 
	process_login = function(url) {
       	clearTimeout(login_timer);
	    $('login_button').disabled = true;
	    if ($('site_select'))
	    	$('site_select').disabled = true;
		o = $('failedmessage');
    	o.innerHTML="<img src='./images/ajax-loader_circle.gif' />";
	    var paramstring = parse_form('login_form');
		thisDiv = $('formDiv');
	    ajax_loadhtml(url, thisDiv, paramstring, 1);
	};

function cp_return_top_window() {
	currwin=window;
    while(currwin.parent.location.href != currwin.location.href){currwin=currwin.parent};
    return currwin;
}

function cp_getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

/*
/ Display AJAX message and loading functions
*/                        

getPos = function (el,sProp) {
	var iPos = 0
	while (el!=null) {
	iPos+=el["offset" + sProp]
	el = el.offsetParent
	}
	return iPos
};

display_message_div = function(t,colors,text,width,noscreen) {
	/// if a messagediv is found, remove it
    message_remove()
    if (!colors) {
    	var color = '#fff1a8';
        var text_color = '#000';
    } else {  
    	colors = colors.split('|');
        var color = colors[0];
        var text_color = colors[1];
    }
    offsets = $(t.getAttribute('id')).cumulativeOffset();
	var divTop = offsets['top']
	var divLeft = offsets['left']
    dims = t.getDimensions();
    var divHeight = dims['height']
    var divWidth = dims['width']
    if (!noscreen) {
		c = t;
	    offsets = $(c.getAttribute('id')).cumulativeOffset();
		var cdivTop = offsets['top']
		var cdivLeft = offsets['left']
	    dims = c.getDimensions();
	    var cdivHeight = dims['height']
	    var cdivWidth = dims['width']
	    /// create iframe screen
	       	f = document.createElement('iframe')
		    f.setAttribute('id','messageframe')
		    f.src='about:blank'
		    i = f.style
		    i.position='absolute'
		    i.top = cdivTop+'px'
		    i.left = cdivLeft+'px' 
		    i.opacity = .0
		    i.filter = 'alpha(opacity=0)'
		    i.border='none';
	        i.backgroundColor='#fff'
		    i.width=c.offsetWidth+'px'
		    i.height=c.offsetHeight+'px'
                i.zIndex = 900;
				if (document.body.firstChild){
					document.body.insertBefore(f, document.body.firstChild);
				} else {
					document.body.appendChild(f);
				}
	    /// attach and position loader image
		    img = document.createElement('img')
		    //preloaddiv.appendChild(img)
		    img.setAttribute("src", "/images/ajax-loader_circle.gif")
		    img.style.zIndex='10'
		    img.style.position='absolute'
		    img.style.top = ((c.offsetHeight/2)-10)+'px'
		    img.style.left=((c.offsetWidth/2)-110)+'px'
    }
    /// create message div
	   	o = document.createElement('div')
	    o.setAttribute('id','messagediv')
	    m = o.style
		if (width)
	        m.width = width
	       m.paddingLeft = '5px'
	       m.paddingRight = '5px'
	    m.textAlign = 'center'
	    m.fontSize = '12px'
	    m.position = 'absolute'
	    m.padding = '6px';
	    m.color = text_color
	    m.zIndex='11'
	    o.innerHTML = text
	    m = o.style
	    m.backgroundColor = color
			m.zIndex = 990;
			if (document.body.firstChild){
				document.body.insertBefore(o, document.body.firstChild);
			} else {
				document.body.appendChild(o);
			}
	    m.top = (divTop+1)+'px'
	    m.left = ((divLeft+t.offsetWidth/2)-(o.offsetWidth/2))+'px'
}
/// message remove function
message_remove = function() {
	if ($('messagediv'))
		$('messagediv').parentNode.removeChild($('messagediv'))
	if ($('messageframe'))
		$('messageframe').parentNode.removeChild($('messageframe'))
}
progress_message = function(percent) {
	l.innerHTML = percent+CP_CLASS_percentcomplete; // l is defined within html code setup
};

/*
/ AJAX Loader functions
*/                        

var ajax_div_loader = function(url,divID,paramstring) {
	this.url = url;
    this.divID = divID;
    this.paramstring = paramstring;
    this.displayState = false;
    var self = this;
    this.loadDivHTML = function(){
	   this.display_ajax_loader(this.divID);
       ajax_loadhtml(this.url, $(this.divID), paramstring, 1);
       this.displayState = true;
	};
	this.display_ajax_loader = function(divID) {
	    $(this.divID).innerHTML = '';
        img = document.createElement('img')
	    img.setAttribute("src", "/images/ajax-loader_circle.gif")
	    $(this.divID).appendChild(img)
	}
};

ajax_loadhtml = function(url, t, params, nomessage, placement){
    if (AJAX_LOADING == 1) {
	    ajax_queue.add_to_queue(url, t, params, nomessage, placement);
    	return false;
	}
    AJAX_LOADING = 1;
	var paramstring = 'params='+params
    var page_request = false
	var bustcacheparameter = "" 
   	if (!nomessage)
    	display_message_div(t,null,"Loading")
	if (window.XMLHttpRequest) // if Mozilla, IE7, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE6 or below
		try {
		page_request = new ActiveXObject("Msxml2.XMLHTTP")
		}
		catch (e){
			try{
			page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	else
		return false
    ajax_timer = ajax_request_timeout()
	page_request.onreadystatechange=function(){ajax_inserthtml(page_request, t, ajax_timer, url, params, nomessage, placement)}
	if (AJAX_BUST_CACHE) //if bust caching of external page
		bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
	page_request.open('POST', url+bustcacheparameter, true)
		//Send the proper header information along with the request
		page_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		page_request.setRequestHeader("Content-length", paramstring.length);
		page_request.setRequestHeader("Connection", "close");
	page_request.send(paramstring)
	ajax_stop_request = function(alertStr) {
		if (AJAX_LOADING == 0)
        	return false;
		page_request.abort();
        if (!alertStr)
        	var alertStr = CP_CLASS_ajaxtimedout;
		stop_loading_screen();
        alert(alertStr);
	}
};

ajax_request_timeout = function() {
	return setTimeout("ajax_stop_request();", AJAX_TIMEOUT, "Javascript");
};

ajax_inserthtml = function(page_request, t, ajax_timer, url, params, nomessage, placement){
    
    url = 'http://www.dcprovidersonline.com/dcp_admin/' + url;
	if (page_request.readyState == 4){
    	if (page_request.status==200 || window.location.href.indexOf("http")==-1) {
	    	clearTimeout(ajax_timer);
	        if (page_request.responseText == 'abort')
	        	return ajax_stop_request(CP_CLASS_classscripterror);
			stop_loading_screen();
	        response = page_request.responseText.split('##js##');
	        if (response[0] != '##noreload##' && response[0].length > 0) {
                if (!placement)
                	t.innerHTML=response[0];
                else
                	t.innerHTML = (placement == 'before') ? response[0]+t.innerHTML : t.innerHTML+response[0];
	        } 
            page_request.abort();
            if (response[1]) {
				for (i=1; i < response.length; i++) {
					eval(response[i]);
	            }
			}
            if (!ajax_queue.empty())
            	ajax_queue.run_next();
        } else {
	    	clearTimeout(ajax_timer);
			stop_loading_screen();
            retryLoad = function () {
				stop_loading_screen();
            	ajax_loadhtml(url, t, params, nomessage, placement);	
            }
                        window.alert(url);
            if (!nomessage)
            	display_message_div(t,'#FFC7A1',CP_CLASS_ajaxconnectionerror,'250px',1);
            else
            	if (confirm(CP_CLASS_ajaxconnectionerrorconfirm)) retryLoad();
        }
	}
};
 
stop_loading_screen = function() {
	if ($('messagediv') || $('messageframe'))
    	message_remove()
	AJAX_LOADING = 0;
};

ajax_loader_queue = function () {
	this.requests = new Array();
	this.add_to_queue = function(url, t, params, nomessage, placement) {
    	var queue = new Object();
        queue.url = url;
        queue.t = t;
        queue.params = params;
        queue.nomessage = nomessage;
        queue.placement = placement;
	    this.requests.push(queue);
	}
    this.run_next = function() {
    	queue_object = this.requests.shift();
        ajax_loadhtml(queue_object.url, queue_object.t, queue_object.params, queue_object.nomessage, queue_object.placement);
    }
    this.empty = function() {
    	return (this.requests.length==0);
    }
}
ajax_queue = new ajax_loader_queue();

function fadeOut(fadeBack) {
	bottomStep = (fadeBack) ? fadeBack : 0;
    if(fadeStep < bottomStep) {
    	if (fadeBack)
    		window.setTimeout("fadeIn()", 50);
        else
        	return;
    }
    setOpacity(fadeElem, (fadeStep/fadeSteps));
    fadeStep--;
    window.setTimeout("fadeOut("+fadeBack+")", 50);
};
function fadeIn() {
    if(fadeStep > fadeSteps)
        return;
    setOpacity(fadeElem, (fadeStep/fadeSteps));
    fadeStep++;
    window.setTimeout("fadeIn()", 50);
};
function setOpacity( el, opacity){
    if(el.style.opacity != undefined){
        el.style.opacity = opacity;
    }else if( el.style.MozOpacity != undefined){
        el.style.MozOpacity = opacity;
    }else if ( el.style.filter != undefined){
        el.style.filter="alpha(opacity=" + Math.round(opacity * 100) + ")";
    }
};

/*
/ Shared Class functions
*/                        

//
// parse_form & Element.addMethods use prototype.js library to create a JSON string of form elements
// Element.toJSON custom method allows escape for each pair and filters elements without names 
//
parse_form = function(form_id) {
	var inputs = $(form_id).getElements();
    var vars = new Array();
    for (i=0; i < inputs.length; i++) {
    	if (inputs[i].toJSON())
    		vars.push(inputs[i].toJSON()); 
    }
    if (vars.length > 0)
		return '{'+vars.join(',')+'}';
    else
    	return false
}

array_to_json = function(arr) {
    var vars = new Array();
    for (i=0; i < arr.length; i++) {
    	if (arr[i].toJSON())
    		vars.push(arr[i].toJSON()); 
    }
    if (vars.length > 0)
		return '{'+vars.join(',')+'}';
    else
    	return false
}

Element.addMethods( {
  toJSON: function(element) {
    element = $(element);
    var name = element.name;
    if (element.type == 'select-multiple')
    	name = name.replace('[]','');
    var name = escape(name);
    var value = element.getValue();
    if (element.type == 'radio' && !value)
    	return false;
    value = r_escape(value);
    if (name.length > 0)
    	return name.toJSON() + ":" + value.toJSON();
    else
    	return false;
  }
})

//
// Takes Array and/or string and escapes recursively
// Used by toJSON method for elements in parse_form
//
r_escape = function(e) {
	if (!e)
    	return '';
    if (e.constructor == Array) {
		var arr = new Array();
		for (n=0; n < e.length; n++)
	    	arr[n] = r_escape(e[n]);
	    return arr;
    } else {
    	return encodeURIComponent(e);
    }
}

//
// Used by sortlist class to submit selected rows(using checkboxes) to a new class (url)
// form_id is data source for submitted data
// functionName = method called from new class
//
submit_new_content = function(form_id,url,functionName) {
    $('functionName').value = functionName;
    var paramstring = parse_form(form_id);
	thisDiv = $('masterListDiv').parentNode;
    ajax_loadhtml(url,thisDiv, paramstring)
};

//
// Calls AJAX to load new content from new class (url)
// vars and values are comma-separated lists of var
//
load_new_content = function(formdiv,url,paramstring) {
   	paramstring = $H(paramstring.toQueryParams()).toJSON();
	thisDiv = $(formdiv).parentNode;
    ajax_loadhtml(url,thisDiv,paramstring)
};

load_content_to_div = function(url,paramstring,div,placement) {
   	paramstring = $H(paramstring.toQueryParams()).toJSON();
	thisDiv = $(div);
    ajax_loadhtml(url,thisDiv,paramstring,null,placement)
};

deselect_disabled = function(e) {
	if (e.type == 'select-multiple' || e.type == 'select-one') {
		for (var i = 0; i < e.length; i++) {
			if (e.options[i].disabled == true && e.options[i].selected == true) {
				if (e.type == 'select-multiple')
                   	e.options[i].selected = false;
				else
                   	e.value = null;
			}
		}
	}
}

/*
/ Form Class functions
*/                        

reload_form = function(url,action,form_id,div_id,nomessage) {
    var f = $(form_id);
    f.elements['ajax_form_action'].value = action;
    var paramstring = parse_form(form_id);
	thisDiv = $(div_id);
    ajax_loadhtml(url,thisDiv, paramstring, nomessage)
};

/*
/	Useful for submitting form data to the main page
/	when needing to reload for some reason.
/	By doing this, you can halt the operation without reloading the page.
/	However, you'll not be able to run any javascript without reloading page.
*/
submit_direct_form_action = function(url,action,form_id) {
	var f=$(form_id);
    f.elements['ajax_form_action'].value = action;
	f.action=url;
	f.submit();
    f.elements['ajax_form_action'].value = '';
	f.action='';
};

/*
/	Useful for submitting form data to an iframe
/	when creating files for download.
/	The iframe will be created if it's not already (within the 'formDiv').
/	By doing this, we can halt the script and call javascript (an alert) without affecting the main page.
/	The form class method 'display_alert_from_iframe'
*/
submit_iframe_form_action = function(url,action,form_id) {
	var f=$(form_id);
    var iframe_name = 'form_target';
    f.elements['ajax_form_action'].value = action;
    if ($(iframe_name)) {
    	var this_iframe = $(iframe_name);
        this_iframe.src = url;
		f.action = url;
		f.target = iframe_name;
	    f.onSubmit = '';
		f.submit();
		f.action = '';
		f.target = '';
	    f.onSubmit = 'return false;';
	}
    f.elements['ajax_form_action'].value = '';
};

//
// Primary function used to submit form data for delete, undelete, and update resource methods
// called by functions defined in index.php file as well as methods within form.class.php
//
save_resource = function(url,action) {
    reload_form(url,action,'resource_form','formDiv');
};

//
// Primary function used to submit form data for new resource creation
//
save_new_resource = function(url,action) {
    reload_form(url,action,'resource_form',$('masterFormDiv').parentNode);
};

//
// Used to execute save action to specific class (url)
// action specifies method to use
// form_id supplies form data for method
// div_id is target div for response
//
save_resource_addnl_form = function(url,action,form_id,div_id) {
    reload_form(url,action,form_id,div_id);
};

upload_file_AJAX = function(url,action,target,file_ext_req) {
	if (file_ext_req) { 
    	f=$('file_upload'); 
        fp = f.value.split(".");
        if (file_ext_req != fp[fp.length-1]) {
        	alert(CP_CLASS_wrongfiletype+' (.'+fp[fp.length-1]+') '+CP_CLASS_expecting+' .'+file_ext_req+'.');
            return false;
        }
	}
    t=$('formDiv');
   	display_message_div(t,null,CP_CLASS_uploadingfile+'...');
	t=$(target);
    t.src=url;
	f=$('resource_form');
    f.elements['ajax_form_action'].value = action;
	f.action=url;
    f.target='upload_target';
	f.submit();
    f.elements['ajax_form_action'].value = '';
	f.action='';
    f.target='';
    return true;
};

start_progress = function(url,name) {
	if (AJAX_LOADING == 1)
    	return false;
	t=$('formDiv');
    $('using_iframe').value = '1';
	submit_to_iframe(url,'edit_resource',name+'_iframe_target');
    $('using_iframe').value = '0';
	AJAX_LOADING = 1;
    return true;
};

submit_to_iframe = function(url,action,target) {
	t=$(target);
    t.src=url;
    t.target='_self';
	f=$('resource_form');
    f.elements['ajax_form_action'].value = action;
	f.action=url;
    f.target=target;
	f.submit();
    f.elements['ajax_form_action'].value = '';
	f.action='';
    f.target='';
    stop_iframe_load = function() {
		t=$(target);
	    t.src=url;
        stop_loading_screen();
        return true;
    }
};

/*
/ Sortlist Class functions
*/                        

reload_list = function(url) {
	$('functionName').value = 'build_list';
    var paramstring = parse_form('filter_form');
	thisDiv = $('listDiv');
    ajax_loadhtml(url,thisDiv, paramstring)
};

execute_sortlist_ajax_action = function(action) {
	f=$('filter_form');
    f.elements['ajax_form_action'].value = action;
    f.elements['form_action'].value = 'filter';
    update_list();
    $('filter_form').elements['ajax_form_action'].value = '';
};

execute_form_action = function(form_id,action,target) {
	f=$(form_id);
    f.elements['form_action'].value = action;
	f.action=target;
	f.submit();
    f.elements['form_action'].value = '';
	f.action='';
};

start_iframe_load = function(url,name,action) {
    $('using_iframe').value = '1';
	submit_action_to_iframe(url,action,name+'_iframe_target');
    $('using_iframe').value = '0';
};

submit_action_to_iframe = function(url,action,target) {
	t=$(target);
    t.src=url;
    t.target='_self';
	f=$('filter_form');
    f.elements['form_action'].value = action;
	f.action=url;
    f.target=target;
	f.submit();
    f.elements['form_action'].value = '';
	f.action='';
    f.target='';
};

select_all_opts = function(selname) {
    var s = $(selname); 
    for (var i = 0; i < s.length; i++) {
        s.options[i].selected = true;
    }
};

rows_selected = function() {
	  void(d=document);
	  void(el=d.getElementsByTagName('INPUT'));
	  for(i=0;i<el.length;i++) {
	  	if (el[i].id.substring(0,4) == 'row_') { 
	    	if (el[i].checked==1) {
				return true;
			}
		}
	  }
	  alert(CP_CLASS_makeaselection);
};

check_all_rows = function() {
	  void(d=document);
	  void(el=d.getElementsByTagName('INPUT'));
	  for(i=0;i<el.length;i++) {
	  	if (el[i].id.substring(0,4) == 'row_' && el[i].disabled == false) { 
	    	void(el[i].checked=1);
		}
	  }
};

uncheck_all_rows = function() {
	  void(d=document);
	  void(el=d.getElementsByTagName('INPUT'));
	  for(i=0;i<el.length;i++) {
	  	if (el[i].id.substring(0,4) == 'row_') { 
	    	void(el[i].checked=0);
		}
	  }
};

exec_on_enter = function(e,jsFunction) {
	var keynum;
    if(window.event) // IE
		keynum = e.keyCode;
	else if(e.which) // Netscape/Firefox/Opera
		keynum = e.which;
	if (keynum == 13) {
    	eval(jsFunction+'();');
    }
    return true;	
}; 

update_list_now = function() {
	f=$('filter_form');
    f.elements['form_action'].value = 'filter';
   	update_list();
};

/*
/ Upload Progress functions
*/                        

/// upload progress is a work-in-progress : required APC for PHP to be installed
start_upload_progress = function(url){
    $("file_progress").innerHTML=CP_CLASS_uploadingstarted;
    setTimeout("ajax_get_progress('"+url+"','file_progress')", 10);
};

ajax_get_progress = function(url,div){
	if (window.XMLHttpRequest) // if Mozilla, IE7, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE6 or below
		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(){
    	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
            if (page_request.responseText.length > 0)
            	$(div).innerHTML=page_request.responseText+'%';
			if (page_request.responseText < 100)
	    		setTimeout("ajax_get_progress('"+url+"','"+div+"')", 100);
        }
    }
	page_request.open('GET', url, true)
	page_request.send(null)
};

show_div = function(divID,set_pref) {
	var vis;
	elem = $(divID);
	vis = elem.style;
	// if the style.display value is blank we try to figure it out here
	if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
		vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
	vis.display = (vis.display==''||vis.display=='block')?'none':'block';
	if (elem = $(divID+'Open'))
		elem.value = vis.display;
	if (set_pref == 1)
	    set_user_pref(divID,vis.display);
    return vis.display;
};

set_user_pref = function(pref_name,pref) {
	vars = new Array();
	vars.push('"pref_name":"'+escape(pref_name)+'"');
	vars.push('"pref":"'+escape(pref)+'"');
	vars.push('"classType":"form_base"');
	vars.push('"ajax_form_action":"set_user_pref"');
	params = '{'+vars.join(',')+'}';
	var paramstring = 'params='+params;
    var url = CPAUTH_FOLDER+"/classes/form.class.php";
	simple_ajax_push(url,paramstring);
}

simple_ajax_push = function(url,paramstring) {
    req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
	if(req) {
		req.open("POST", url, true);
		//Send the proper header information along with the request
		req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		req.setRequestHeader("Content-length", paramstring.length);
		req.setRequestHeader("Connection", "close");
		req.send(paramstring);
		req.onreadystatechange = function() {//Nothing to do here.
			if(req.readyState == 4 && req.status == 200) {
		        if (req.responseText == 'abort')
		        	return alert(CP_CLASS_classscripterror);
		        response = req.responseText.split('##js##');
		        if (response[1]) {
					for (i=1; i < response.length; i++)
						eval(response[i]);
				}
			}
		}
	}
};

cp_rowRollover = function(myId, isInRow) {
	// myId is our own integer id, not the DOM id
	// isInRow is 1 for onmouseover, 0 for onmouseout
	var row = $('tr_' + myId);
	row.className = (isInRow) ? 'rowselected' : ( (myId&1) ? 'white' : 'shade' );
}

cp_get_hashed_value = function (key) {
	if (window.location.hash.length < 1)
    	return false;
    var hash = window.location.hash.replace("#","");
    var params = hash.split("&");
	for (i=0; i < params.length; i++) {
    	paramarr = params[i].split("=");
        if (paramarr[0] == key && paramarr[1].length > 0)
        	return paramarr[1];
    }
    return false;
}

cp_unescape = function (str) {
	str = "" + str;
	while (true)
	{
		var i = str . indexOf ('+');
		if (i < 0)
			break;
		str = str . substring (0, i) + '%20' +
			str . substring (i + 1, str . length);
	}
	return unescape (str);
};

var TimeToFade = 400.0;
function fade_out(eid,startOp)
{
  var element = $(eid);
  if(element == null)
    return;
    element.startOp = startOp;
    element.FadeTimeLeft = TimeToFade;
    setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33);
}
function animateFade(lastTick,eid)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
  var element = $(eid);
  if(element.FadeTimeLeft <= elapsedTicks)
  {
    element.style.opacity = 0;
    element.style.filter = 'alpha(opacity = ' + 0 + ')';
   	element.parentNode.removeChild(element);
    return;
  }
  element.FadeTimeLeft -= elapsedTicks;
  var newOpVal = element.startOp*(element.FadeTimeLeft/TimeToFade);
  element.style.opacity = newOpVal;
  element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
  setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}

var nativeHTML='';
function cp_build_drop_down_menu (id,menuid,list,relative,withContent) {
        if ($(menuid))
        	return;
        if (id == 'header') {
        	id = ($('header')) ? 'header' : 'header-home';
        }
        o = document.createElement('div');
	    o.setAttribute('id',menuid);
	    o.className='jqueryslidemenu';
        m=o.style;
        if (menuid == 'compassmenu') m.zIndex=300;
	    o.innerHTML = list
	    if (withContent && !$(menuid+'_contentDiv')) {
			c = document.createElement('div')
			c.setAttribute('id',menuid+'_contentDiv')
	        if (relative == 'inplaceof') {
			    c.className='menuDiv';
	        	nativeHTML = $(id).innerHTML;
	            $(id).innerHTML = '';
	            c.innerHTML = nativeHTML;
	        }
        }
        if (relative == 'after') {
            par = $(id).parentNode;
			par.insertBefore(o, $(id).nextSibling);
		    if (withContent && c)
				par.insertBefore(c, $(id).nextSibling);
        } else {
		    if (withContent && c)
				$(id).insertBefore(c, $(id).firstChild);
			$(id).insertBefore(o, $(id).firstChild);
        }
        m.marginLeft = "auto";
        m.marginRight = "auto";
        m.width = $(id).style.width;
        jqueryslidemenu.buildmenu(menuid);
        if (nativeHTML)
        	return nativeHTML;
        return null;
}

load_menu_content = function(menuid,url,paramstring,div,placement) {
   	paramstring = $H(paramstring.toQueryParams()).toJSON();
	thisDiv = $(div);
	thisDiv.className = 'menuDiv';
    ajax_loadhtml(url,thisDiv,paramstring,null,placement)
};

function dumpProps(obj, parent) {
   // Go through all the properties of the passed-in object
   for (var i in obj) {
      // if a parent (2nd parameter) was passed in, then use that to
      // build the message. Message includes i (the object's property name)
      // then the object's property value on a new line
      if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
      // Display the message. If the user clicks "OK", then continue. If they
      // click "CANCEL" then quit this level of recursion
      if (!confirm(msg)) { return; }
      // If this property (i) is an object, then recursively process the object
      if (typeof obj[i] == "object") {
         if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
      }
   }
}

