var preloadFlag = false;

//----------- New Images:PhotoShop@3/6/03 -----------------------//
function preloadImages() {
	if (document.images) {
		//alert("Preloaded Images");
	}
}

//----------- New Images:PhotoShop@3/6/03 -----------------------//
function newImage(arg) {
  if (document.images) {
    rslt = new Image();
    rslt.src = arg;
    return rslt;
  }
}

//----------- Change Images:Jon Lokken@3/6/03 -------------------//
function changeImagesSrc() {
	//alert("In the change:"+ arguments[0].src);
  if (document.images && (preloadFlag == true)) {
    for (var i=0; i<arguments.length; i+=2) {
      arguments[i].src = arguments[i+1].src;
    }
  }
}

//----------- Change Images:PhotoShop@3/6/03 --------------------//
function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			changeImages.arguments[i].src = eval(changeImages.arguments[i+1]).src;
		}
	}
}

//----------- Expand/Collapse Menu:Jon Lokken@3/6/03 ------------//
// Expand or Collapse a folder or subfolder.
function expandCollapse(folder){
  var thisFolder  = folder;
  var myRegExp    = new RegExp("^"+thisFolder+"_\\d*$", "i");
  var plusReg     = /plus.gif/i;
  var minusReg    = /minus.gif/i;
  var arrowReg    = /arrow.gif/i;
  var arrowDownReg= /arrowdown.gif/i;
  var currentSpan = document.getElementById(folder);
  var spanImages  = currentSpan.all.tags("table")[0].all.tags("img");
  var mySpans     = document.getElementById(thisFolder).all.tags('span');
  //alert("thisfolder: "+thisFolder);
  //alert("Images within this span:"+spanImages.length);
  for(i=0;i<spanImages.length;i++){
  	//alert("Images path:"+spanImages[i].src);
  	if(plusReg.test(spanImages[i].src)){
  		changeImagesSrc(spanImages[i], minus);
  	}
  	else if(minusReg.test(spanImages[i].src)){
  		changeImagesSrc(spanImages[i], plus);
  	}
  	else if(arrowReg.test(spanImages[i].src)){
  		changeImagesSrc(spanImages[i], arrowDown);
  	}
  	else if(arrowDownReg.test(spanImages[i].src)){
			changeImagesSrc(spanImages[i], arrow);
		}
  }
  
  for(i=0;i<mySpans.length;i++){
    if(myRegExp.test(mySpans[i].id)){
      //alert("mySpans[i].id: "+mySpans[i].id+" : "+mySpans[i].style.display);
      if(mySpans[i].style.display == "none"){
        mySpans[i].style.display = "";
        //alert("mySpans[i].id:(display) "+mySpans[i].id);
        if(expandCollapse.arguments.length > 2){
          //alert(expandCollapse.arguments[1]+", "+minuspath+", "+expandCollapse.arguments[2]+", "+folderopenpath);
          changeImages(expandCollapse.arguments[1], minuspath);
          changeImages(expandCollapse.arguments[2], folderopenpath);
        }
      }
      else{
        mySpans[i].style.display = "none";
        //alert("mySpans[i].id:(hide) "+mySpans[i].id);
        if(expandCollapse.arguments.length > 2){
          //alert(expandCollapse.arguments[1]+", "+minuspath+", "+expandCollapse.arguments[2]+", "+folderopenpath);
          changeImages(expandCollapse.arguments[1], pluspath);
          changeImages(expandCollapse.arguments[2], folderclosepath);
        }
      }
    }
  }
}

//-------- Open Up Application Window:Jon Lokken 4.8.2005 --------------//
//- Used to open a new window to show how the application works in .asp
function openApplication(applicationURL){
   var strAttrib = "height=600,width=800,ScreenX=0,screenY=0,left=0,top=0,resizable,toolbar=no,menubar=no,location=no,scrollbars=yes"
   var today =  new Date()
   var millisec = today.getMilliseconds()
   var strWinRef = "title" + millisec
   strWinRef = window.open(applicationURL, strWinRef, strAttrib);
}

//-------- Open Up Application Window:Jon Lokken 4.8.2005 --------------//
//- Used to open a new window to show how the application works in .asp
function openPictures(applicationURL){
   var strAttrib = "height=600,width=525,ScreenX=0,screenY=0,left=0,top=0,resizable=no,toolbar=no,menubar=no,location=no,scrollbars=no"
   var today =  new Date()
   var millisec = today.getMilliseconds()
   var strWinRef = "title" + millisec
   strWinRef = window.open(applicationURL, strWinRef, strAttrib);
}

//-------- Call the rss feed application -------//
//- Used to get news
function ajaxFunction(otherFeed) {
	var myOtherFeed = "" + otherFeed;
	
	if(otherFeed == "undefined" || otherFeed == null || otherFeed == "null"){
		myOtherFeed = "http://rss.news.yahoo.com/rss/topstories";
	} else if (otherFeed == ""){
		alert("Enter your RSS Feed URL in the textbox!");
		myOtherFeed = "http://rss.news.yahoo.com/rss/topstories";
	}

    //document.getElementById("news").innerHTML="Getting Feed..."+myOtherFeed;
    document.getElementById("news").innerHTML = '<img src="/images/gettingRSSFeed2.gif" width="32" height="32" alt="" border="0">';
	
	var xmlHttp;
	try {  
  	// Firefox, Opera 8.0+, Safari  
  	xmlHttp=new XMLHttpRequest();
  	//alert("You are using IE 7.0, Firefox, Opera 8.0+, or Safari!");
  } catch (e) {  
  	// Internet Explorer  
  	try {    
  		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  		//alert("You are using IE 6.0 +with MSXML12.XMLHTTP");
  	} catch (e) {
  		try {
  			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  			//alert("You are using IE 5.5+ with XMLHTTP");
  		} catch (e) {
  			alert("Your browser does not support AJAX!");
  			return false;
  		}
  	}
  }
  
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4){
		  //document.myForm.time.value=xmlHttp.responseText;
		  document.getElementById("news").innerHTML=xmlHttp.responseText;
		}
		/*
		* 0=The request is not initialized
		* 1=The request has been set up
		* 2=The request has been sent
		* 3=The request is in process
		* 4=The time request is complete
		*/	
	}
	
	var rssUrl = "/applications/programming/AJAX/ajaxrssrealtime.asp?rss="+escape(myOtherFeed);
	xmlHttp.open("GET",rssUrl,true);
	xmlHttp.send(null);	
}
