var strClose = "<div style='padding:10px;'>List Updated</p></div>\r\n";

var strAnn = "<center><h4>Add a New Announcement</h4></center>\r\n<form name=addAnnouncementForm id=addAnnouncementForm>\r\n<table border=0 width=100%>\r\n";
strAnn = strAnn + "<MOD>";
strAnn = strAnn + "<tr>\r\n<td align='left'><span class='addAnnouncement'>Title:</span></td>\r\n";
strAnn = strAnn + "<td><input class='addAnnouncement' type=text name=Title></td>\r\n</tr>\r\n";
strAnn = strAnn + "<tr>\r\n<td align='left'><span class='addAnnouncement'>Priority:</span></td>\r\n";
strAnn = strAnn + "<td><input type=radio name=Priority value=1> High <input type=radio name=Priority value=2 checked> Med <input type=radio name=Priority value=3> Low</td>\r\n</tr>\r\n";
strAnn = strAnn + "<tr>\r\n<td colspan=2 align='left'><span class='addAnnouncement'>Announcement:</span><br />\r\n";
strAnn = strAnn + "<textarea class='addAnnouncement' rows=8 cols=40 name=Announcement></textarea></td>\r\n</tr>\r\n";
strAnn = strAnn + "<tr>\r\n<td colspan=2 align=middle>";
strAnn = strAnn + "<input class='addAnnouncement' type=button name=Submit1 value=Submit onClick=\"javascript:var f=document.getElementById('addAnnouncementForm');addAnnouncement(f.Title.value,f.Announcement.value,f.WGID.value);\">";
strAnn = strAnn + "&nbsp;<input class='addAnnouncement' type=button name=Submit2 value=Cancel onClick='javascript:closeAnnDiv();'>\r\n";
strAnn = strAnn + "</td>\r\n</tr>\r\n</table>\r\n</form>";


function displayTravellers(lngTripAvailID) {
    var strFormValues = "taid=" + lngTripAvailID;
    xmlHttp = GetXmlHttpObject();
    xmlHttp.open("POST","sirad/displayTravellers.asp",true);
    xmlHttp.onreadystatechange = function() {
       	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
            var strResponse = new String(xmlHttp.responseText);
	        var e = document.getElementById("displayTravellers");
	        e.innerHTML = strResponse;
	        e.style.top = "50px";
	        e.style.left= "50px";
	        e.style.width = "600px";
	        e.style.border = "1px solid black";
			e.style.visibility = "visible";
			e.style.padding = "5px";
        }
    }
    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    xmlHttp.send(strFormValues);
}


function hideTravellers() {
	var e = document.getElementById("displayTravellers");
	e.style.top = "0px";
	e.style.left= "0px";
	e.style.width = "0px";
	e.style.padding = "0px";
	e.style.border = "";
	e.style.visibility = "hidden";
}	

function getSubs(lngID,divTag,sw) {
    var strFormValues = "id=" + lngID;
    var lnk = document.getElementById(sw);
	if (lnk) {
		if (lnk.innerHTML == "-") {
			lnk.innerHTML = "+";
	        var e = document.getElementById(divTag);
	        e.innerHTML = "";
			e.style.visibility = "hidden";
		}
		else {
			lnk.innerHTML = "-";
			xmlHttp = GetXmlHttpObject();
			xmlHttp.open("POST","getFolders.asp",true);
			xmlHttp.onreadystatechange = function() {
			   	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
			        var strResponse = new String(xmlHttp.responseText);
			        var e = document.getElementById(divTag);
			        e.innerHTML = strResponse;
					e.style.visibility = "visible";
			    }
			}
			xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
			xmlHttp.send(strFormValues);
		}
	}
			
}

function displayFiles(lngID,divTag) {
    var strFormValues = "id=" + lngID;
    xmlHttp = GetXmlHttpObject();
    xmlHttp.open("POST","getFiles.asp",true);
    xmlHttp.onreadystatechange = function() {
       	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
            var strResponse = new String(xmlHttp.responseText);
	        var e = document.getElementById(divTag);
	        e.innerHTML = strResponse;
			e.style.visibility = "visible";
        }
    }
    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    xmlHttp.send(strFormValues);
}

function NewAnnouncement(lngWGID,bolMod) {
    var myString = new String(strAnn);
    rExp = /\<MOD\>/gi;
    if (bolMod==true && lngWGID!=0) {
        strAnn = myString.replace(rExp,"<tr>\r\n<td colspan=2 align='left'>Display for: <input class='addAnnouncement' type=radio value=0 name=WGID> Everyone <input type=radio value="+lngWGID+" name=WGID CHECKED> Group</td>\r\n</tr>\r\n");
    }
    else {
        strAnn = myString.replace(rExp,"<tr>\r\n<input type=hidden value=0 name=WGID>");
    }
    var ad = document.getElementById("addAnnouncementDiv");
    ad.innerHTML = strAnn;
    ad.style.visibility = "visible";
    ad.style.top="100px";
    ad.style.left="200px";
    ad.style.width="360px";
    ad.style.height="300px";
    document.getElementById("addAnnouncementForm").Title.focus();
}

function addAnnouncement(strTitle,strAnnouncement,lngWGID) {

	var f = document.getElementById("addAnnouncementForm");
	var i;
	var lngPriority=0;
	for (i=0;i<3;i++) {
		if (f.Priority[i].checked) lngPriority = i+1;
	}

    if (!lngWGID) { // Must have been radio button..
        lngWGID = getCheckedValue(f.WGID);
    }

    var strFormValues = new String(strTitle)
    rExp = / /gi;
    strFormValues = strFormValues.replace(rExp,"+");
    rExp = /#/gi;
    strFormValues = strFormValues.replace(rExp,"%23");
    rExp = /&/gi;
    strFormValues = strFormValues.replace(rExp,"%26");

    var strValue = "wgid=" + lngWGID + "&priority=" + lngPriority + "&title="+strFormValues

    var strFormValues = new String(strAnnouncement)
    rExp = / /gi;
    strFormValues = strFormValues.replace(rExp,"+");
    rExp = /\#/gi;
    strFormValues = strFormValues.replace(rExp,"%23");
    rExp = /\&/gi;
    strFormValues = strFormValues.replace(rExp,"%26");
    rExp = /\r\n/gi;
    strFormValues = strFormValues.replace(rExp,"<br />");

    strValue = strValue+"&announcement=" + strFormValues

    xmlHttp = GetXmlHttpObject();
    xmlHttp.open("POST","sirad/AddAnnouncement.asp",true)
    xmlHttp.onreadystatechange = function() {
		var ad = document.getElementById("addAnnouncementDiv")
       	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
            var myResponse = new String(xmlHttp.responseText);
            if (myResponse.length>0) {
                ad.innerHTML = "<p>Error!</p>";
            }
            else {
                ad.innerHTML = "<p>Done!</p>";
            }
            ad.style.top="0px";
            ad.style.left="0px";
           	document.location.href = document.location.href;
        }
  	}
    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    xmlHttp.send(strValue);
}

function dismissAnnouncement(aid) {
    strFormValues = "f=rann&aid="+aid

    xmlHttp = GetXmlHttpObject();
    xmlHttp.open("POST","default.asp",true)
    xmlHttp.onreadystatechange = function() {
       	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
           	document.getElementById("Ann"+aid).style.display="none";
        }
  	}
    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    xmlHttp.send(strFormValues);
}

function removeAnnouncement(aid) {
    strFormValues = "aid="+aid

    xmlHttp = GetXmlHttpObject();
    xmlHttp.open("POST","sirad/removeAnnouncement.asp",true)
    xmlHttp.onreadystatechange = function() {
       	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
           	document.getElementById("Ann"+aid).style.display="none";
        }
  	}
    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    xmlHttp.send(strFormValues);
}

function closeDiv() {
  document.all.AddCrewDiv.style.visibility='hidden';
  document.getElementById("AddCrewDiv").innerHTML = strLLF;
}
function closeAnnDiv() {
  var ad = document.getElementById("addAnnouncementDiv");
  ad.style.visibility="hidden";
  ad.style.width="0px";
  ad.style.height="0px";
  ad.innerHTML = strAnn;
}

function editContactList(id,action,search,strParms) {
    var strFormValues = "cid=" + id + "&action=" + action + "&cs=" + escape(search) + "&" + strParms;
    xmlHttp = GetXmlHttpObject();
    xmlHttp.open("POST","sirad/editContactList.asp",true);
    xmlHttp.onreadystatechange = function() {
       	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
            var strResponse = new String(xmlHttp.responseText);
            if(strResponse.indexOf("<!--complete-->")>0) {
                document.getElementById("ContactListForm").style.display="none";
            }
            document.getElementById("ContactList").innerHTML = strResponse;
        }
    }
    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    xmlHttp.send(strFormValues);
}

function submitECForm(f) {
    var strParameters = "";
    var i;
    var id,action;
    var elements = f.elements;
    var ele;

    strParameters = "id=0&action=new"
    for(i=0;i<elements.length;i++) {
        ele = elements[i];
        strParameters = strParameters + '&' + ele.name + '=' + escape(ele.value);
    }
    xmlHttp = GetXmlHttpObject();
    xmlHttp.open("POST","sirad/editContactList.asp",true);
    xmlHttp.onreadystatechange = function() {
       	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
            var strResponse = new String(xmlHttp.responseText);
            if(strResponse.indexOf("<!--complete-->")>0) {
                document.getElementById("ContactListForm").style.display="none";
            }
            document.getElementById("ContactList").innerHTML = strResponse;
        }
    }
    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    xmlHttp.send(strParameters);
}

function escape(str) {
    var result = new String(str);
    var rExp;

    rExp = / /gi;
    result = result.replace(rExp,"+");
    rExp = /#/gi;
    result = result.replace(rExp,"%23");
    rExp = /&/gi;
    result = result.replace(rExp,"%26");
    return result;
}


function GetXmlHttpObject() { 
var objXmlHttp=null
if (navigator.userAgent.indexOf("Opera")>=0)
   {
    alert("This example doesn't work in Opera") 
    return;  
   }
if (navigator.userAgent.indexOf("MSIE")>=0)
   { 
   var strName="Msxml2.XMLHTTP"
   if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
      {
      strName="Microsoft.XMLHTTP"
      } 
   try
      { 
      objXmlHttp=new ActiveXObject(strName)
      //objXmlHttp.onreadystatechange=handler 
      return objXmlHttp
      } 
   catch(e)
      { 
      alert("Error. Scripting for ActiveX might be disabled") 
      return 
      } 
    } 
if (navigator.userAgent.indexOf("Mozilla")>=0)
   {
   objXmlHttp=new XMLHttpRequest()
   //objXmlHttp.onload=handler
   //objXmlHttp.onerror=handler 
   return objXmlHttp
   }
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

