function resize_iframe(id, txtid)
{
	if(document.getElementById(id).height<500)
		document.getElementById(id).height=500; 
	else
		document.getElementById(id).height=0;

	if(document.getElementById(txtid).innerHTML== '(click to see)')
		document.getElementById(txtid).innerHTML= '(click to hide)';
	else
		document.getElementById(txtid).innerHTML= '(click to see)';

}

function resize_iframe_to_contents(id, name)
{
	document.getElementById(id).height=100

	document.getElementById(id).height=window.frames[name].document.body.scrollHeight + 20;
} 


function popup(url, w, h, scroll) 
{
	detailWindow=window.open(url,'detailWin','width=' + w + ',height=' + h + 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1');
	detailWindow.focus();
}	



function confirmSubmit()
{
	var agree=confirm("Are you sure you want to delete this?");
	if (agree)
	{
		//alert('true');
		return true;
		
	}
	else
	{
		//alert('f');
		return false;
	}
}


function confirmSubmitTags(num, name)
{
	var agree=confirm("Are you sure you want to delete this tag? " + num + " pages are coded \"" + name + "\"");
	if (agree)
	{
		//alert('true');
		return true;
		
	}
	else
	{
		//alert('f');
		return false;
	}
}


function confirmApprove()
{
	var agree=confirm("Are you sure you want to approve this?");
	if (agree)
	{
		return true;
	}
	else
		return false;
}
function ajaxthis(url, postdata, changearray)
{
	
	//get with ajax the info for that sec
	var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) 
    {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) 
    {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', url, true);
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
             var myArray = self.xmlHttpReq.responseText.split('``');
             
             for (var j=0; j<myArray.length; j++)
             {
             	document.getElementById(changearray[j]).innerHTML = myArray[j];
             }
             
           if (document.recalc) document.recalc();//for ie only from ie7
        } 
    }
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.send(postdata);	
}

function storeAddress() 
{
  // Prepare query string and send AJAX request
 var pars = 'signup=' + escape(document.getElementById('signuptext').value);
 // Update user interface
 document.getElementById('response').innerHTML = 'Adding email address...';
 var myAjax = ajaxthis('mailinglist.php', pars, ['response']);
}



// Twisty.js
//
// Copyright (c) 2007 Red Hat, Inc.
// 
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// 
// Provide a nice interface for creating disclosure triangles in a web page
// To use: 
//
// put onload="initTwisty();" in your <body> tag.
//
// You should have this in your style sheet:
//
//     .twisty:hover {
//      background-color: #f0f0f0;
//      border: 1px solid #e0e0e0;
//      margin-left: -1px;
//    }
//
//    .twisty {
//      cursor: hand;
//      cursor: pointer;
//    }
//
// When you have a section you wish to expose/hide, put:
//
// <div>Some Label <img class="twisty" src="twisty-down.gif" onclick="toggleTwisty('childid'); return false;">
//   <div id="childid">
//     <div>Some content</div>
//   </div>
// </div>

function hideTwisty (id) {
  var el = getElemById (id);
  var twisty;

  if (el) {
    setStyle (el, {display: 'none'});
  }

  for (var i = 0; i < el.parentNode.childNodes.length; i++) {
    if (el.parentNode.childNodes[i].nodeName == 'A') {
      var t = el.parentNode.childNodes[i];
      for (var j = 0; j < t.childNodes.length; j++) {
	if (t.childNodes[j].className == 'twisty')
	  twisty = t.childNodes[j];
      }
    }
  }
  
  if (typeof twisty != "undefined")
    twisty.setAttribute('src', 'twisty-hidden.gif');

}

function toggleTwisty (id) {
    var el = getElemById (id);
    var twisty;
    
    for (var i = 0; i < el.parentNode.childNodes.length; i++) {
      if (el.parentNode.childNodes[i].nodeName == 'A') {
	var t = el.parentNode.childNodes[i];
	for (var j = 0; j < t.childNodes.length; j++) {
	  if (t.childNodes[j].className == 'twisty')
	    twisty = t.childNodes[j];
	}
      }
    }
    

    twisties = getElementsByClassName (document, "img", "twisty");

    for (var i = 0; i < twisties.length; i++) {
	if (twisties[i].src.indexOf('twisty-do-down.gif') != -1) {
	    twisties[i].setAttribute ('src', 'twisty-down.gif');
	} else if (twisties[i].src.indexOf('twisty-do-hidden.gif') != -1) {
	    twisties[i].setAttribute ('src', 'twisty-hidden.gif');
	}
    }
    
    if (el.style.display == "none") {
      if (typeof twisty != "undefined")
	twisty.setAttribute('src', 'twisty-do-down.gif');
      if (typeof Effect != "undefined") {
	Effect.toggle(id, "Slide", {duration:.4});
      } else {
	setStyle(el, {display: 'block'});
      }
    } else {
      if (typeof twisty != "undefined")
	twisty.setAttribute('src', 'twisty-do-hidden.gif');
      if (typeof Effect != "undefined") {
	Effect.toggle(id, "Slide", {duration:.4});
      } else {
	setStyle(el, {display: 'none'});
      }
    }
}


function getElementsByClassName(oElm, strTagName, strClassName){
  var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
  var arrReturnElements = new Array();
  strClassName = strClassName.replace(/\-/g, "\\-");
  var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
  var oElement;
  for(var i=0; i<arrElements.length; i++){
    oElement = arrElements[i];
    if(oRegExp.test(oElement.className)){
      arrReturnElements.push(oElement);
    }
  }
  return (arrReturnElements);
}

function getElemById(aID){ 

  if (document.getElementById)
    return document.getElementById(aID);
  
  return document.all[aID];
}

function setStyle(element, style) {
  for (var name in style) {
    var value = style[name];
    element.style[name] = value;
  }
  return element;
}
////END TWISTY///////////////////////////////////////////////////



function toggle(id, show) 
{
	if(show == 'hide')
	{
		document.getElementById(id).style.display = 'none';
	}
	if(show == 'show')
	{
		document.getElementById(id).style.display = '';
	}
}

function autotoggle(id, form)
{
	if(document.getElementById(id).style.display == 'none')
	{
		//alert('show');
		toggle(id, 'show');
	}
	else
	{
		//alert('hide');
		toggle(id, 'hide');
		//remove_action_date(form);
	}
}




function resize_toggle(id, txtid)
{
	//alert(document.getElementById(id).style.display);
	if(document.getElementById(id).style.display=='none')
		document.getElementById(id).style.display='block'; 
	else
		document.getElementById(id).style.display='none';

	if(document.getElementById(txtid).innerHTML= '(&#8744;)')
		document.getElementById(txtid).innerHTML= '(&#8743;)';
	else
		document.getElementById(txtid).innerHTML= '(&#8744;)';

}


function getObjInnerText (obj) {
return (obj.innerText) ? obj.innerText
: (obj.textContent) ? obj.textContent
: "";
} 

function getParent(element, parent){
if(typeof element=="string"){element=document.getElementById(element);};
if(!element){return null;};
var elements=[];
if(typeof parent!="string"){/*no parent: gets all parents till #document*/
	while(element.parentNode){
	element=element.parentNode;
	elements.unshift(element);
		if(element==parent){return elements;};
	}
}
else{/*string, presumes you want to locate the first parent node that is such TAG*/
parent=parent.toUpperCase();
	while(element.parentNode){
	element=element.parentNode;
	elements.unshift(element);
		if(element.nodeName && element.nodeName.toUpperCase()==parent){return elements;};
	}
};
return elements;
/* keep this comment to reuse freely:
http://www.fullposter.com/?1 */}



function showselected(fieldname)
{
	var selected='';
	for (i=0; i < document.mentor[fieldname].length; i++)
	{
		if(document.mentor[fieldname][i].checked)
		{
			var parent = getParent(document.mentor[fieldname][i], 'LABEL');
			//alert(parent[0].innerHTML);
			selected=selected + getObjInnerText(parent[0]) + "<br>";
		}
	}
	var field = fieldname.replace("[]", '');
	document.getElementById(field).innerHTML=selected;
}



function clearform(which, text)
{
	if (which.value==text)
	{
		which.value='';
		which.style.color='#000';
	}
}

function searchtxt(which, text)
{
	if (which.value=="")
	{
		which.value=text;
		which.style.color='#999';
	}
}



var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;

// open hidden layer
function mopen(id)
{	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
	
	// get new layer and show it
	if(document.getElementById(id))
	{
		ddmenuitem = document.getElementById(id);
		ddmenuitem.style.visibility = 'visible';
	}

}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 


var currentContent = null;

function togglePannelAnimatedStatus(content, interval, step, moreid)
{
    // wait for another animated expand/collapse action to end
    if (currentContent==null)
    {
        var mycontent=document.getElementById(content);
        currentContent = mycontent;
        var expand = (mycontent.style.display=="none");
        if (expand)
            mycontent.style.display = "block";
        var max_height = mycontent.offsetHeight;

        var step_height = step + (expand ? 0 : -max_height);
        toggleChevronIcon(moreid);
                
        // schedule first animated collapse/expand event
        mycontent.style.height = Math.abs(step_height) + "px";
        //alert(Math.abs(step_height));
        
        setTimeout("togglePannelAnimatingStatus("
            + interval + "," + step
            + "," + max_height + "," + step_height + ")", interval);
            
    }
}

function togglePannelAnimatingStatus(interval,
    step, max_height, step_height)
{
    var step_height_abs = Math.abs(step_height);

    // schedule next animated collapse/expand event
    if (step_height_abs>=step && step_height_abs<=(max_height-step))
    {
        step_height += step;
        currentContent.style.height = Math.abs(step_height) + "px";
        setTimeout("togglePannelAnimatingStatus("
            + interval + "," + step
            + "," + max_height + "," + step_height + ")", interval);
    }
    // animated expand/collapse done
    else
    {
        if (step_height_abs<step)
            currentContent.style.display = "none";
        currentContent.style.height = "";
        currentContent = null;
        testheight('content', 'sidebar');
    }
}

// change chevron icon into either collapse or expand
function toggleChevronIcon(moreid)
{
    if(document.getElementById(moreid))
    {
		if(moreid!='dropissues')
		{
			//alert(document.getElementById(moreid).innerHTML);
			str=document.getElementById(moreid).innerHTML;
			//alert(str.search('Read More'));
			if(str.search('Read More')>-1)
				document.getElementById(moreid).innerHTML='<span class=\"plusminus\">-</span> Minimize';
			else
				document.getElementById(moreid).innerHTML='<span class=\"plusminus\">+</span> Read More';
		}
		else
		{
			if(document.getElementById("dropissues").style.backgroundImage != "url(images/dropissues2.png)")
				document.getElementById("dropissues").style.backgroundImage = "url(images/dropissues2.png)";
			else
				document.getElementById("dropissues").style.backgroundImage = "url(images/dropissues.png)";
				
		}
	}
	else
		return;
}


function testheight(id, id2)
{
	if(document.getElementById(id) && document.getElementById(id2))
	{
		//alert(document.getElementById(id).offsetHeight + ' -- ' + document.getElementById(id2).offsetHeight);
		if(document.getElementById(id).offsetHeight < document.getElementById(id2).offsetHeight)
		{
			document.getElementById(id).style.height=document.getElementById(id2).offsetHeight + 'px';
		}
		else
		{
			document.getElementById(id).style.height='auto';
			if(document.getElementById(id).offsetHeight < document.getElementById(id2).offsetHeight)
			{
				document.getElementById(id).style.height=document.getElementById(id2).offsetHeight + 'px';
			}
			else
			{
				document.getElementById(id).style.height='auto';				
				if(document.getElementById('sideprebot'))
				{
					document.getElementById('sideprebot').style.height=document.getElementById(id).offsetHeight - document.getElementById(id2).offsetHeight + 'px';
				}	
			}
		}
	}
	
}

function friendlyURL (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '-';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        //output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
        output += '';
      }
      x++;
    }
  }
  return output;
}




function seturl()
{
	var tit=document.getElementById('title').value;
	if(document.getElementById('url').value=='')
	document.getElementById('url').value=friendlyURL(tit);
}


function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

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



function rollthis(o, img)
{
	o.parentNode.parentNode.style.background="url(" + img + ")";
}

function rolloutthis(o, img)
{
	o.parentNode.parentNode.style.background="url(" + img + ")";
}

function dispnone(id)
{
	//alert(id);
	document.getElementById(id).style.display='none';
}

function dispnblock(id)
{
	//alert(id);
	document.getElementById(id).style.display='';
}

function dispbold(id)
{
	document.getElementById('numzero').style.fontWeight='normal';
	document.getElementById('numone').style.fontWeight='normal';
	document.getElementById('numtwo').style.fontWeight='normal';
	document.getElementById(id).style.fontWeight='bold';		document.getElementById('numzero').style.textDecoration='underline';
	document.getElementById('numone').style.textDecoration='underline';
	document.getElementById('numtwo').style.textDecoration='underline';
	document.getElementById(id).style.textDecoration='none';	
}


function ouropacity(id, numid)
{

    
    var speed = Math.round(500 / 100);
    var timer = 0;
    
	//fade out others
	for(j = 0; j <= 2; j++)
	{
		ban=document.getElementById('bannernumber' + j);
		//alert(j + " -- " + ban.style.display);
		if(ban.style.display!='none')
		{
			for(i = 100; i >= 0; i--) 
            {
            	//bans[i].id
            	setTimeout("changeOpac(" + i + ",'" + 'bannernumber' + j + "')",(timer * speed));
            	timer++;
            	if(i==0)
            	{
            		setTimeout("dispnone('bannernumber" + j + "')", (100 * speed));
            	}
        	}
		}
	}

	//fade ours in
	changeOpac(100, id);
	setTimeout("dispnblock('" + id + "')", (100 * speed));
    //document.getElementById(id).style.display='block';
	for(i = 0; i <= 100; i++)
	{
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
    }
	setTimeout("dispbold('" + numid + "')", (timer*speed));
	
}


function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 


document.getElementsByClassName = function(clsName){
    var retVal = new Array();
    var elements = document.getElementsByTagName("*");
    for(var i = 0;i < elements.length;i++){
        if(elements[i].className.indexOf(" ") >= 0){
            var classes = elements[i].className.split(" ");
            for(var j = 0;j < classes.length;j++){
                if(classes[j] == clsName)
                    retVal.push(elements[i]);
            }
        }
        else if(elements[i].className == clsName)
            retVal.push(elements[i]);
    }
    return retVal;
}


function edit_permalink()
{
	urldata = document.getElementById('url-name-full').innerHTML;
	document.getElementById('url-name-full').innerHTML='<input type="text" name="url" id="url" value=' + urldata +  '>';
	
	document.getElementById('save_perma').style.display="inline";
	document.getElementById('edit-slug-buttons').style.display="none";
}

function cancel_permalink(orig)
{
	document.getElementById('url-name-full').innerHTML=orig;
	
	document.getElementById('save_perma').style.display="none";
	document.getElementById('edit-slug-buttons').style.display="inline";
}

function save_permalink()
{
	urldata = document.getElementById('url').value;
	document.getElementById('url-name-full').innerHTML=urldata;
	
	document.getElementById('save_perma').style.display="none";
	document.getElementById('edit-slug-buttons').style.display="inline";
}

