// Ektron JavaScript Document
function OpenCloseDiv(divID, listID, anchorID)
{
    var divList = document.getElementById(divID);
    var List = document.getElementById(listID);
    SetSelectedAnchor(anchorID);
    if (divList.style.display == "none")
    {
        divList.style.display = "block";
        List.className = "open";
    } else {
        divList.style.display = "none";
        List.className = "closed";
    }
}

function SetSelectedAnchor(anchorID)
{
    var allAnchors = document.getElementsByTagName('a');
    for (var i = 0; i < allAnchors.length; i++)
    {
        allAnchors[i].className = "";
    }
    document.getElementById(anchorID).className = "selected"
}

function ecmPopUpWindow(url, hWind, nWidth, nHeight, nScroll, nResize)
{
    var popupwin;
    var cToolBar;
    cToolBar = 'toolbar=0,location=0,directories=0,status=' + nResize + ',menubar=0,scrollbars=' + nScroll + ',resizable=' + nResize + ',width=' + nWidth + ',height=' + nHeight;
    popupwin = window.open(url, hWind, cToolBar);
    return popupwin;
}

function ValidateElement(ElementID)
{
    if (Trim(document.getElementById(ElementID).value) == "")
    {
        document.forms[0].AddButton.disabled=true;
    }
    else
    {
        document.forms[0].AddButton.disabled=false;        
    }
}  

function Trim (string) {
	if (string.length > 0) {
		string = RemoveLeadingSpaces (string);
	}
	if (string.length > 0) {
		string = RemoveTrailingSpaces(string);
	}
	return string;
}

function RemoveLeadingSpaces(string) {
	while(string.substring(0, 1) == " ") {
		string = string.substring(1, string.length);
	}
	return string;
}

function RemoveTrailingSpaces(string) {
	while(string.substring((string.length - 1), string.length) == " ") {
		string = string.substring(0, (string.length - 1));
	}
	return string ;
}
 

function checkForIlligalChars(ElementID)
{
    elem = document.getElementById(ElementID);
    if (Trim(elem.value) == "")  
    {
        alert("Please enter all required fields.");
        return false;
    }     
    if((elem.value.indexOf(';') > -1) || (elem.value.indexOf('+') > -1) || (elem.value.indexOf('{') > -1) || (elem.value.indexOf('}') > -1) || (elem.value.indexOf('#') > -1) || (elem.value.indexOf('%') > -1) || (elem.value.indexOf('\'') > -1) || (elem.value.indexOf('/') > -1) || (elem.value.indexOf('>') > -1) || (elem.value.indexOf('<') > -1) || (elem.value.indexOf('*') > -1) || (elem.value.indexOf('&') > -1) || (elem.value.indexOf('"') > -1) || (elem.value.indexOf('\\') > -1) || (elem.value.indexOf(':') > -1))
    {
       alert("The name can not contain ';', '+', '{', '}','#','%','\'', '/', '>', '<', '*', '&', '\"', '\\', ':'.");
       return false;        
    }  
      
     if(!checkForSpecial(elem.value))
   {   
        return false;
    }
    
    return true;
}

function checkForSpecial(Wiki_name) 
{ 
 var wikiRE = /\W/; 

 if (Wiki_name.match('&&&'))
  { 
  
  alert( "The sequence &&& is invalid.Please choose a different name" ); 
   return false; 
 } 
 else 
 { 
   
   return true; 
 } 
 }

function SubmitAddProject()
{
    if (checkForIlligalChars('ProjectName'))
    {
        AddProject();
    }      
}

function SubmitAddClient()
{
    if (checkForIlligalChars('ClientName'))
    {
        AddClient();
    }  
}

function clickButton(e, ElementID, callBack)
{ 

    var evt = e ? e : window.event;
    var bt = document.getElementById('AddButton');
    var elem;
  
    if (bt)
    
    { 
         
        if (evt.keyCode == 13)
        {                   
            document.forms[0].onsubmit = function () 
            { 
                return false;
            }
           
            evt.cancelBubble = true;
            if (evt.stopPropagation) 
                evt.stopPropagation();
            if (checkForIlligalChars(ElementID))
            {
                eval(callBack);
            }                  
            return false;        
        }
           
    }
  
  
  
   ValidateElement(ElementID);
  
     
}

function OpenCloseMilestoneDetail(anchorID, divID)
{
    if (document.getElementById(divID).style.display == "none")
    {
        document.getElementById(divID).style.display = "block";
        document.getElementById(anchorID).className = "open";
    } else {
        document.getElementById(divID).style.display = "none";
        document.getElementById(anchorID).className = "closed";
    }
}



function ShowUsergroupError(error)
{
    /* Usergroup warning that appears if a membership usergroup is inadvertantley deleted */
    /* Detail: */
    /* The process that generates InformationArchitecture.XML will catch an error if a membership  */
    /* usergroup for any given client does not exist.  This can happen if, for some reason, AddClient() */
    /* doesn't fully complete, or if someone deletes this usergorup manually from the workarea.  */
    /* If this is the case, the process that generates InformationArchitecture.xml does not throw,  */
    /* rather it catches the error, adds an "error" attribute to the client's node and an onclick event   */
    /* that callsthis function.  */
    p = '<h4 class=\'Warning\'>';
    p+= 'Warning';
    p+= '</h4>'; 
    p+= '<p>';
    p+= 'The membership usergroup for <b>' + error + '</b> appears to have been removed.  The StarterApp has attempted to fix this problem by re-creating the group.';
    p+= '</p><p>';
    p+= 'If this message continues to appear, add this membership usergroup manually through the Workarea.';
    p+= '</p>';
    document.getElementById('ActionContent').innerHTML = "";
    document.getElementById('ActionContent').innerHTML = p;
    document.getElementById('Actions').style.display = "block";
}


/*******************************************/
/* Begin Microformat Integration */
/*******************************************/
function GetvCard(client, project, summary, dtstart, dtend, description)
{
    var location = "actions/vCalendar.aspx?client=" + client + "&project=" + project + "&summary=" + summary + "&dtstart=" + dtstart + "&dtend=" + dtend + "&description=" + description;
	document.location = location;
}
/*****************************************/
/* End Microformat Integration */
/*****************************************/