var url ;
var NSIPADDR;
var req;
function ext_refresh(func,argname,argval,detailview,standalone){
	NSIP = Get_Cookie ( 'domain' );
	ns1 = Get_Cookie ( 'NSAPI' );
	if (!ns1)
	{
		top.location.href = "/loggedout.html";
		return;
	}
	
	window.status="Refreshing...";
	url = "/ws/generic_api_call.pl?function=" + func + "&argname=" + argname + "&arg=" + argval + "&outputformat=DATA" + "&detailview=" + detailview + "&standalone=" + standalone;
	NSIPADDR = NSIP;
	ext_refresh2();
}

function ext_refresh2() 
{
 	ndiv = document.getElementById("image");
	if (ndiv) {
		ndiv.innerHTML = "<img src=\"/images/in_progress.gif\" width=\"16\" height=\"16\">";
	}
				
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}

	var url1 = url+"&id="+Math.random(); 
	req.open("GET", url1, true);
	req.onreadystatechange = callback;
	req.send(null);
	//callback();
}

function callback() {
	if (req.readyState == 4) {
	 if ((req.status == 200) || (req.status == -1) || !(req.status)){
		     var xmlDoc = req.responseXML;
	    	      var rootNode = xmlDoc.getElementsByTagName("messages")[0];
	       		  for (var j=0; j < rootNode.childNodes.length; j++) {
					if (rootNode.childNodes[j].nodeName == "message") {
						var idattr = rootNode.childNodes[j].attributes.getNamedItem("colname");
							if (idattr) {
								var valattr = rootNode.childNodes[j].attributes.getNamedItem("val");
								mdiv = document.getElementById(idattr.value);
								if (mdiv) {
									var regex = /(\w*)\.png/;
									var temp = valattr.value;
									//alert(temp);
									if (temp.match(regex)){
										//alert("Found");
										picture1 = new Image(200,200);
										picture1.src = valattr.value;
										var image = document.getElementById("img" + idattr.value);
										image.src = picture1.src;
									}
									else{
										if (valattr.value == "DOWN"){
											mdiv.innerHTML = "<img src=\"/images/sdown.gif\">" + valattr.value;
										}
										else if (valattr.value == "UP"){
											mdiv.innerHTML = "<img src=\"/images/sup.gif\">" + valattr.value;
										}
										else if (valattr.value == ""){
											mdiv.innerHTML = "&nbsp;";
										}
										else{
											mdiv.innerHTML = valattr.value;
										}
									}
			 				   	} else {
									//alert("Value "+idattr.value);
								}
							} else {
								alert("col name not there ");
							}
			 			} 
					}
   	      	 		setTimeout("ext_refresh2()",7000);
					window.status="Done";
					ndiv = document.getElementById("image");
					if (ndiv) {
						ndiv.innerHTML = "<img src=\"/images/spacer.gif\" height=\"16\" width=\"16\"/>";
					}
		    }
			else {
			alert("There was an error in retrieving data." + "\nStatus message:" + req.statusText + " (" + req.status + ")");
	        }
 	}
}

function Get_Cookie( name ) {
	
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}
	
function loadhomepage(base) {
	document.location = base+"/index.html";
}

function validate_login() {
	ns1 = Get_Cookie ( 'NSAPI' );
	if (!ns1)
	{
		top.location.href = "/loggedout.html";
		return;
	}
}




