 var http;
 
function setPointer(theRow, theRowNum, theAction, theDefaultColor, 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;
    }

    // 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

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0) 
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = 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;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = 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;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // 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

/*throw out old browsers to browser.php page */
function com_oldbrowsertoss(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)<5)) {
    window.location.href='browser.php'; }}
}
com_oldbrowsertoss(true);

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function mOver(Item) {
 Item.className = "BGwhite";
}

function mOut(Item) {
 Item.className = "fonty";
}

function SNOver(Item) {
 Item.className = "sidenavOver";
}

function SNOut(Item) {
 Item.className = "sidenavOut";
}


//display subnav
function togglesubnav(Item) {
	var divd = document.getElementById(Item);
	var imgdivd = document.getElementById('img'+Item);
 	if(divd.style.display=='none') 
	{
		imgdivd.src = '/images/icons/navarrow_light_f2.png';
		divd.style.display = "block";
	}
	else 
	{
		imgdivd.src = '/images/icons/navarrow_light.png';
		divd.style.display = "none";
	}
}

function sidenavOver(Item) {
 Item.className = "sidenavOver";
}

function sidenavOut(Item) {
 Item.className = "sidenavOut";
}


function TmOver(Item) {
 Item.className = "tabselected";
}

function TmOut(Item) {
 Item.className = "tabnotselected";
}

function ITmOver(Item) {
 Item.className = "indextabselected";
}

function ITmOut(Item) {
 Item.className = "indextabnotselected";
}

function whitetabOver(Item) {
 Item.className = "BGgrayTABselected";
}

function whitetabOut(Item) {
 Item.className = "BGgrayTAB";
}

function midtabOver(Item) {
 Item.className = "midTABhover";
}

function midtabOut(Item) {
 Item.className = "midTAB";
}

function TOPTABOver(Item) {
 Item.className = "TOPTABhover";
}

function TOPTABOut(Item) {
 Item.className = "TOPTAB";
}

function buttonOver(Item) {
 Item.className = "overbuttoncolor";
}

function buttonOut(Item) {
 Item.className = "buttoncolor";
}

function hiddendate(form) {
  
	 Stamp = new Date();
	 var Month;
	 var Day;
	 var Year;
	 Month = Stamp.getMonth();
	 Day = Stamp.getDate();
	 Year = Stamp.getFullYear();
	
	 var Hours;
	 var Mins;
	 var Time;
	 Hours = Stamp.getHours();
	 
	 if (Hours >= 12) {
	 Time = " pm";
	 }
	 else {
	 Time = " am";
	 }
	
	 if (Hours > 12) {
	 Hours -= 12;
	 }
	 if (Hours == 0) {
	 Hours = 12;
	 }
	 
	 Mins = Stamp.getMinutes();
	 if (Mins < 10) {
	 Mins = "0" + Mins;
	 }
	 
 	document.form.userdatetime.value = Year + '-' + Month + '-' + Day + ' ' + Hours + ":" + Mins + Time;
 }

function showHide(thisid) {
	 if(document.all) { // it's IE
	  document.getElementById(thisid).style.display = (document.getElementById(thisid).style.display=='block'?'none':'block');
	  writeCookie(thisid, document.getElementById(thisid).style.display, 2000);
	 }
	 else if(document.layers) { // it's netscape 4.x
	  document.thisid.display = (document.thisid.display=='block'?'none':'block');
	  writeCookie(thisid, document.thisid.display, 2000);
	 }
	 else if(document.getElementById(thisid)) { // it's Netscape 6 (mozilla)
	  document.getElementById(thisid).style.display = (document.getElementById(thisid).style.display=='block'?'none':'block');
	  writeCookie(thisid, document.getElementById(thisid).style.display, 2000);
	 }
}

function show(thisid) {
	 if(document.all) { // it's IE
	  document.getElementById(thisid).style.display='block';
	  writeCookie(thisid, document.getElementById(thisid).style.display, 2000);
	 }
	 else if(document.layers) { // it's netscape 4.x
	  document.thisid.display='block';
	  writeCookie(thisid, document.thisid.display, 2000); 
	 }
	 else if(document.getElementById(thisid)) { // it's Netscape 6 (mozilla)
	  document.getElementById(thisid).style.display='block';
	  writeCookie(thisid, document.getElementById(thisid).style.display, 2000);
	 }
}

function Hide(thisid) {
	 if(document.all) { // it's IE
	  document.getElementById(thisid).style.display='none';
	  writeCookie(thisid, document.getElementById(thisid).style.display, 2000);
	 }
	 else if(document.layers) { // it's netscape 4.x
	  document.thisid.display='none';
	  writeCookie(thisid, document.thisid.display, 2000);
	 }
	 else if(document.getElementById(thisid)) { // it's Netscape 6 (mozilla)
	  document.getElementById(thisid).style.display='none';
	  writeCookie(thisid, document.getElementById(thisid).style.display, 2000);
	 }
}

function hidedivs(theseids) {
	
	var ar = theseids;
	
	for(i=0;i<ar.length;i++) {
		
		 if(document.all) { // it's IE
		  document.getElementById(ar[i]).style.display='none';
		 }
		 else if(document.layers) { // it's netscape 4.x
		  document.ar[i].display='none';
		 }
		 else if(document.getElementById(ar[i])) { // it's Netscape 6 (mozilla)
		  document.getElementById(ar[i]).style.display='none';
		 }
	 
	}
}

function createRequestObject() {
var request = null;
    try {
		request = new XMLHttpRequest();
	} catch (trymicrosoft) {
		
		try {
			request = new ActiveXObject("MSxml2.XMLHTTP");	
		} catch (othermicrosoft) {
			try {
					request = new ActiveXObject("Microsoft.XMLHTTP");	
			} catch (failed) {
				request = null;
			}
		}
	}
	return request;
}


function ajaxloader(divid)
{
	document.getElementById(divid).innerHTML = '<div align="center" style="padding:20px"><img src="/images/icons/appspin.gif" alt="Loading" title="Loading" /><br />Loading...</div>';
}


/* You can get more specific with version information by using 
	parseInt(navigator.appVersion)
	Which will extract an integer value containing the version 
	of the browser being used.
*/
/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject(); 
var request = createRequestObject(); 

/* checks if you have an ajax enabled browser */
function pingajax(pingpage)	{
	var ppage = pingpage;
	if(request != null)
	{
		http.open("GET",ppage,true);
		http.onreadystatechange = handlenulReturn;
		http.send(null);
	}
}

function handlenulReturn(){
	if(http.readyState == 4){ 
		var response = http.responseText;
	}
}

var the_count = 0;
var the_timeout;
function timedsessionping()
{
	pingajax('/includes/ajax/alertinclude.php');
	the_timeout = setTimeout("timedsessionping();", 30000);
}
timedsessionping();




/* Function called to get the product categories list */
function ajaxtoolbar() 
{
	request.open('get', '/includes/ajax/toolbar.php',true);
	request.onreadystatechange = handletooBReturn;
	request.send(null);
}

function handletooBReturn(){
	if(request.readyState == 4)
	{ 
		var response = request.responseText;
		if(response)
		{
			document.getElementById('toolbar').innerHTML = response;
		}
	}
}

var toolBcount = 0;
var toolBtimeout;
function timedtoolBping()
{
	ajaxtoolbar();
	toolBtimeout = setTimeout("timedtoolBping();", 60000);
}

/* Function called to get the product categories list */
function getUsername(field){
	
	var thisfield = field;
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	http.open('get', '/includes/ajax/check_username.php?action=get_username&username=' 
			+ field.value);
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */

	http.onreadystatechange = handleReturn;
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}


function handleReturn(){
/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = http.responseText;
		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
		//document.getElementById('product_cage').innerHTML = response;
		if(response)
		{
			alert(response);
			document.signup.username.focus();
		}
	}
}

function sndReq(action,vary) {
    http.open('get', '/includes/ajax/ajax.php?action='+action+'&var=' + vary);
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();

        if(response.indexOf('|' != -1)) {
            update = response.split('|');
			if(update[0]=='divdisplay') {
            	document.getElementById(update[1]).innerHTML = update[2]; 
			}
			else if(update[0]=='formcheck') {
				alert(update[2]);
				var myObject = eval(update[1]);
				myObject.focus();
			}
        }
    }
}
// Example:
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}

function refreshopenerclosewin(url)
{
	window.opener.location.reload();
	window.close();
}

//////////////////////////////////
//sliding divs
//////////////////////////////////

/*
put HIGHER value to make go faster
*/
var slidecontent_slideSpeed=10;
/*
put LOWER value to make go faster
*/
var slidecontent_timer=10;

var objectIdToSlideDown=false;
var slidecontent_activeId=false;
var slidecontent_slideInProgress=false;
function showHideContent(e,divid)
{
	if(slidecontent_slideInProgress)return;
	slidecontent_slideInProgress=true;
	if(!divid)divid=this.id;
	divid=divid + '';
	var numericId=divid.replace(/[^0-9]/g,'');
	var answerDiv=document.getElementById('slidecontent_a' + numericId);

	objectIdToSlideDown=false;
	
	if(!answerDiv.style.display || answerDiv.style.display=='none'){		
		if(slidecontent_activeId &&  slidecontent_activeId!=numericId){			
			objectIdToSlideDown=numericId;
			slideContent(slidecontent_activeId,(slidecontent_slideSpeed*-1));
		}else{
			
			answerDiv.style.display='block';
			answerDiv.style.visibility='visible';
			
			slideContent(numericId,slidecontent_slideSpeed);
		}
	}else{
		slideContent(numericId,(slidecontent_slideSpeed*-1));
		slidecontent_activeId=false;
	}	
}

function slideContent(divid,direction)
{
	
	var obj =document.getElementById('slidecontent_a' + divid);
	var contentObj=document.getElementById('slidecontent_ac' + divid);
	height=obj.clientHeight;
	if(height==0)height=obj.offsetHeight;
	height=height + direction;
	rerunFunction=true;
	if(height>contentObj.offsetHeight){
		height=contentObj.offsetHeight;
		rerunFunction=false;
	}
	if(height<=1){
		height=1;
		rerunFunction=false;
	}

	obj.style.height=height + 'px';
	var topPos=height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top=topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent(' + divid + ',' + direction + ')',slidecontent_timer);
	}else{
		if(height<=1){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=divid){
				document.getElementById('slidecontent_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('slidecontent_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,slidecontent_slideSpeed);				
			}else{
				slidecontent_slideInProgress=false;
			}
		}else{
			slidecontent_activeId=divid;
			slidecontent_slideInProgress=false;
		}
	}
}



function initShowHideDivs()
{
	var divs=document.getElementsByTagName('DIV');
	var divCounter=1;
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='slideheader'){
			divs[no].onclick=showHideContent;
			divs[no].id='slidecontent_q'+divCounter;
			var answer=divs[no].nextSibling;
			while(answer && answer.tagName!='DIV'){
				answer=answer.nextSibling;
			}
			answer.id='slidecontent_a'+divCounter;	
			contentDiv=answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top=0 - contentDiv.offsetHeight + 'px'; 	
			contentDiv.className='slidecontent_content';
			contentDiv.id='slidecontent_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';
			divCounter++;
		}		
	}	
}

window.onload=initShowHideDivs;

//////////////////////////////////
//end sliding divs
//////////////////////////////////

