function stripe(id) {
  var even = false;
  var evenColor = arguments[1] ? arguments[1] : "#bdecfe";
  var oddColor = arguments[2] ? arguments[2] : "#d9fbfc";
  var table = document.getElementById(id);
  var off  = document.getElementById('noStripe');
  if (! table || off) { return; }
  var tbodies = table.getElementsByTagName("tbody");

  for (var h = 0; h < tbodies.length; h++) {
    var trs = tbodies[h].getElementsByTagName("tr");

    for (var i = 0; i < trs.length; i++) {
      if (! trs[i].style.backgroundColor) {
        var tds = trs[i].getElementsByTagName("td");

        for (var j = 0; j < tds.length; j++) {
          var mytd = tds[j];
 //         if (! mytd.style.backgroundColor) {
            mytd.style.backgroundColor = even ? evenColor : oddColor;
 //         }
        }
      }
      even =  ! even;
    }
  }
}



function OpenRequestedPopup(strUrl, strTarget,width,height)
{
 var WindowObjectReferenceOfRequestedPopup;
var windowWidth, windowHeight, windowLeft, windowTop;

if(typeof window.screenX == "number" && typeof window.innerWidth == "number")
        {
        windowWidth = window.innerWidth * .68;
        windowHeight = window.innerHeight * .68;
        windowLeft = window.screenX + window.innerWidth * .16;
        windowTop = window.screenY + window.innerHeight * .16;
        }
else if(typeof window.screenTop == "number" && typeof document.documentElement.offsetHeight == "number")
        {
        windowWidth = document.documentElement.offsetWidth * .68;
        windowHeight = document.documentElement.offsetHeight * .68;
        windowLeft = window.screenLeft + document.documentElement.offsetWidth * .16;
        windowTop = window.screenTop - 50;
        }
else
        {
        windowWidth = 800;
        windowHeight = 250;
        windowLeft = 60;
        windowTop = 40;
        };

/* The above code is just to define reasonable sizes and initial positions to the popup to be. */

if (WindowObjectReferenceOfRequestedPopup == null || WindowObjectReferenceOfRequestedPopup.closed)
        {
		var tstamp = new Date().getTime();
        WindowObjectReferenceOfRequestedPopup = window.open(strUrl, strTarget+tstamp, "top=" + windowTop + ",left=" + windowLeft + ",width=" + windowWidth * width + ",height=" + windowHeight * height + ",menubar,toolbar,location,resizable,scrollbars,status");
        }
else
        {
        WindowObjectReferenceOfRequestedPopup.focus();
        };

/*
 * The above 9 lines of code creates the popup; if the popup is already opened, then it is only brought on top. This feature is possible only if the user allows it via the setting Edit/Preferences.../category:Advanced/Scripts & Plugins/Allow webpages to:/Raise or lower windows
 * */
}


function AddLink(title, url) {
	var count = document.getElementById("LinkCount");
	count.value++;
	divobj = document.createElement("DIV");
	divobj.id="Link"+count.value;
	document.getElementById("LinkContainer").appendChild(divobj);
	document.getElementById("Link"+count.value).innerHTML += "<table width='100%'><tr> "+
				"<td width='30px'>Title</td><td width='250px'><input name=\"Link"+count.value+"[]\" style='width:90%' value=\""+ title + "\"></td>"+
				"<td width='30px;'>URL</td><td width='450px'><input name=\"Link"+count.value+"[]\" style='width:90%' value=\""+ url + "\"></td> "+
				"<td width='75px'><input type='checkbox' name=\"Link"+count.value+"[]\"  value='1'>Popup</td></tr></table>";
}

function AddLinkToSelectedLink(id) {
	var request = new XMLHttpRequest(); 
        	
        	request.onreadystatechange = function() {  
        		if(request.readyState == 4) {
        			if (request.status == 200)  {
        				var resp = request.responseText;
        				var startTxt = '<itemLink>';
        				var itemsStart = resp.indexOf(startTxt) + startTxt.length;
        				var itemsEnd = resp.indexOf('</itemLink>');
        				var idArray = resp.substring(itemsStart, itemsEnd).split(",");
					AddLink(idArray[0],idArray[1]);
				}
				else 
					alert("There was a problem retrieving the XML data:\n" + request.statusText);
			}
  
			}; 
        	request.open("POST", "getItemLink.php", true);  
  		request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  		request.send('id=' + id);   
}

function AjaxRequest(location,url,post) {
        var http_request = false;

        if (window.XMLHttpRequest) {
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
            }
        } else if (window.ActiveXObject) {
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }
        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        http_request.onreadystatechange = function() {changeStatus(http_request); };
        http_request.open('POST',url, true);
        http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        http_request.send(post);
    function changeStatus(http_request) {
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
            	 if(location != null && location != "")
                        document.getElementById(location).innerHTML = http_request.responseText;
                        stripe('stripe');
            }
        }

   }
}

function RemoveRecord(tid,msg) {
        msg = msg ? msg : "delete";
        if (confirm('Are you sure you want to '+msg+' ?')) {
                document.delform.DelID.value=tid;
                timer =  setTimeout('document.delform.submit();', 500);
        }
}


function SaveAndBack() {
	document.getElementById("SAB").value = 1;	
	timer =  setTimeout('document.EditSection.submit();', 300);
	return true;
}

function VerifySave() {

	if(confirm('Leaving the page will caused unsaved work to be lost. Are you sure you want to leave? ')) {
		return true;
	} else {
		return false;
	}
}

