var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
	try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
		xmlhttp = false;
	}
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	xmlhttp = new XMLHttpRequest();
}

function getObject(id){
	var itm = null;
	if (document.getElementById) {
		itm = document.getElementById(id);
	} else if (document.all){
		itm = document.all[id];
	} else if (document.layers){
		itm = document.layers[id];
	}
	return itm;
}

function stripetable(id){ tablestripe(id); }
function tablestripe(id){

    // the flag we'll use to keep track of 
    // whether the current row is odd or even
    var even = false;
  
    // if arguments are provided to specify the colours
    // of the even & odd rows, then use the them;
    // otherwise use the following defaults:
    var evenColor = arguments[1] ? arguments[1] : "#ffffff";
    var oddColor = arguments[2] ? arguments[2] : "#edf3fe";
  
    // obtain a reference to the desired table
    // if no such table exists, abort
    var table = document.getElementById(id);
    if (! table) { return; }
    
    // by definition, tables can have more than one tbody
    // element, so we'll have to get the list of child
    // &lt;tbody&gt;s 
    var tbodies = table.getElementsByTagName("tbody");

    // and iterate through them...
    for (var h = 0; h < tbodies.length; h++) {
    
     // find all the &lt;tr&gt; elements... 
      var trs = tbodies[h].getElementsByTagName("tr");
      
      // ... and iterate through them
      for (var i = 0; i < trs.length; i++) {

        // avoid rows that have a class attribute
        // or backgroundColor style
        if (! hasClass(trs[i]) &&
            ! trs[i].style.backgroundColor) {
 		  
          // get all the cells in this row...
          var tds = trs[i].getElementsByTagName("td");
        
          // and iterate through them...
          for (var j = 0; j < tds.length; j++) {
        
            var mytd = tds[j];

            // avoid cells that have a class attribute
            // or backgroundColor style
            if (! hasClass(mytd) &&
                ! mytd.style.backgroundColor) {
        
              mytd.style.backgroundColor =
                even ? evenColor : oddColor;
            
            }
          }
        }
        // flip from odd to even, or vice-versa
        even =  ! even;
      }
    }
  }
  
  function hasClass(obj) {
     var result = false;
     if (obj.getAttributeNode("class") != null) {
         result = obj.getAttributeNode("class").value;
     }
     return result;
  }   

function handleEnter (field, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		return false;
	}else{
		return true;
	}
}
function handleEnterGo (field, event, nextfield) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		field.form[nextfield].focus();
		return false;
	}else{
		return true;
	}
}

function insertAtCursor(myField, myValue) {
  //IE support
  if (document.selection) {
    myField.focus();
    sel = document.selection.createRange();
    sel.text = myValue;
  }
  //MOZILLA/NETSCAPE support
  else if (myField.selectionStart || myField.selectionStart == '0') {
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
	var scrollTop = myField.scrollTop;
    myField.value = myField.value.substring(0, startPos)
                  + myValue 
                  + myField.value.substring(endPos, myField.value.length);
	cursorPos = startPos + myValue.length;
	myField.selectionStart = cursorPos;
	myField.selectionEnd = cursorPos;
	myField.scrollTop = scrollTop;
  } else {
    myField.value += myValue;
  }
  myField.focus();
}

function foldmenu(begin){
	var url = "/ajax/savemenu.php?m="+begin.id.substr(6)+"&s=";
	for(i=0;i<begin.parentNode.childNodes.length;i++){
		if(begin.parentNode.childNodes[i].className == "modulesdiv"){
			var links = begin.parentNode.childNodes[i].getElementsByTagName("a");
			begin.parentNode.childNodes[i].style.height = getCSSProperty(begin.parentNode.childNodes[i],"height");
			
			if(parseInt(getCSSProperty(begin.parentNode.childNodes[i],"height")) > 0){
				newx = -1;
				for(x=0;x<movDiv.length;x++){
					if(movDiv[x] == begin.parentNode.childNodes[i]){
						newx = x;
						break;
					}
				}
				if(newx == -1){
					movDiv.push(begin.parentNode.childNodes[i]);
					newx = movDiv.length-1;
				}
				shrinkdiv(newx);
				url += "0";
			}else{
				newx = -1;
				for(x=0;x<movDiv.length;x++){
					if(movDiv[x] == begin.parentNode.childNodes[i]){
						newx = x;
						break;
					}
				}
				if(newx == -1){
					movDiv.push(begin.parentNode.childNodes[i]);
					newx = movDiv.length-1;
				}
				growdiv(newx, links.length);
				url += "1";
			}
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readystate == 4){
			alert(xmlhttp.responseText);
		}
	}
	xmlhttp.send(null);
}
var movDiv = new Array();
function shrinkdiv(x){
	var div = movDiv[x];
	div.style.height = Math.max(0,parseInt(div.style.height) - 5) + "px"
	if(parseInt(div.style.height) > 0){
		setTimeout('shrinkdiv('+x+')',10);
	}
}
function growdiv(x, links){
	var div = movDiv[x];
	div.style.height = Math.min(links*23,parseInt(div.style.height) + 5) + "px"
	if(parseInt(div.style.height) < links*23){
		setTimeout('growdiv('+x+','+links+')',10);
	}
}


function getCSSProperty(oNode, sProperty){
	if(document.defaultView){
		return document.defaultView.getComputedStyle(oNode, null).getPropertyValue(sProperty);
	}else if(oNode.currentStyle){
		var sProperty = sProperty.replace(/-\D/gi, function(sMatch)
		{
			return sMatch.charAt(sMatch.length - 1).toUpperCase();
		});

		return oNode.currentStyle[sProperty];
	}
	else return null;
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function photographer(){
     var base_url = "http://www.ypu.org/photographer/"+arguments[0];
     if(arguments.length > 1){ base_url += "&p="+arguments[1]; }
     var temp_w = (screen.width - 1000 - 50)/2;
     var temp_h = (screen.height - 700 - 50)/2;
     var options = 'height=600,width=1000,top='+temp_h+',left='+temp_w+',toolbar=no,scrollbars=auto,resizable=1,resize=yes';
     temp = popWindow=window.open(base_url,'photographer',options);
     temp.focus();
}


function popwin(url,h,w){
     var base_url = url;
     var temp_w = (screen.width - w - 50)/2;
     var temp_h = (screen.height - h - 50)/2;
     var options = 'height='+h+',width='+w+',top='+temp_h+',left='+temp_w+',toolbar=no,scrollbars=auto,resizable=1,resize=yes';
     temp = popWindow=window.open(base_url,'popup',options);
     temp.focus();
}

