var req; 

function getXMLHTTP()
{
    if ((typeof XMLHttpRequest) != "undefined") {
        /* XMLHTTPRequest present, use that */
        return new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        /*  there are several versions of IE's Active X control, use the most recent one available */
        var xmlVersions = ["MSXML2.XMLHttp.5.0",
                           "MSXML2.XMLHttp.4.0",
                           "MSXML2.XMLHttp.3.0",
                           "MSXML2.XMLHttp",
                           "Microsoft.XMLHTTP"];

        for (var x = 0; x < xmlVersions.length; x++) {
            try {
                var xmlHTTP = new ActiveXObject(xmlVersions[x]);
                return xmlHTTP;     
            } catch (e) {
                //continue looping
            }
        }
    }

    /* if none of that worked, return false, to indicate failure */
    return false;
}


function fcCell(url) {
	
		req = getXMLHTTP();
		if(req) {
			//req.onreadystatechange = processReqChange;
			furl = "";
			if( url.charAt(0) == "." )  {
				furl = url.substr(1) + ".php";
			} else {
				furl = url + ".html";
			}
			//alert(furl);
			req.open("GET", "frags/"+furl, false);
			req.send("");
			processReqChange();
		}

}

function processReqChange() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
	  var ccel = parent.document.getElementById("content_cell");
        // only if "OK"
        if (req.status == 200) {
		ccel.innerHTML = req.responseText;
        } else {
	      ccel.innerHTML = "SERVER ERROR";
             //alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
    }
}


function fytCell(url) {

		req = getXMLHTTP();
		if(req) {
			//req.onreadystatechange = processReqChangeYT;
			furl = "";
			if( url.charAt(0) == "." )  {
				furl = url.substr(1) + ".php";
			} else {
				furl = url + ".html";
			}
			//alert(furl);
			req.open("GET", "frags/"+furl, false);
			req.send("");
			processReqChangeYT();
		}

}

function processReqChangeYT() {
    // only if req shows "loaded"
     if (req.readyState == 4) {
	  var ccel = parent.document.getElementById("youtube_tr");
        // only if "OK"
       if (req.status == 200) {
		try {
			ccel.innerHTML = req.responseText;
		} catch (e) {
			// IE fails unless we wrap the string in another element.
			try {
				var oCell = ccel.insertCell(-1);
				oCell.style.align="center";
				oCell.colSpan="4";
				oCell.style.width="100%";
				oCell.innerHTML=req.responseText;
			} catch (e) {
				alert(e.description);
			}
		}
        } else {
	      ccel.innerHTML = "SERVER ERROR";
             //alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
    }

}

function getURLVar(urlVarName) {
	//divide the URL in half at the '?'
	var urlHalves = String(document.location).split('?');
	var urlVarValue = '';
	
	if(urlHalves[1]){
		//load all the name/value pairs into an array
		var urlVars = urlHalves[1].split('&');
		
		//loop over the list, and find the specified url variable
		for(i=0; i<=(urlVars.length); i++){
			if(urlVars[i]){
				//load the name/value pair into an array
				var urlVarPair = urlVars[i].split('=');
				if (urlVarPair[0] && urlVarPair[0] == urlVarName) {
				//I found a variable that matches, load it's value into the return variable
					urlVarValue = urlVarPair[1];
				}
			}
		}
	}

	return urlVarValue;   
}


function firstLoad(defval)
{

	var override = getURLVar('sp');
	if (override!='') {
		defval=override;
	} 

	fcCell(defval);

}
