//<!--
//break framesets
if (window.top.frames.length > 0)
{
	window.top.frames.location.href = document.location.href; 
}

//used to 
function LaunchDocEditor(sDN)
{

	//sURL = '/adx/admin/Editors/adxDocEditor.asp?ObjectClass=adxDocument.1&Mode=Edit&ID=LDAP:' + sDN + '&AppName=LDAP&AppID=' + sDN
	sURL = '/admin/Editors/adxDocEditor.asp?ObjectClass=adxDocument.1&Mode=Edit&ID=LDAP:' + sDN + '&AppName=LDAP&AppID=' + sDN
	sURL += '&Node=<Node ID="LDAP:'+sDN+'" AppName="LDAP" AppID="'+sDN+'" ObjectClass="adxDocument.1" Flags=" Orderable Editable CopyPaste IsContainer"  />';//state="closed" selected="true" highlighted="true"
	sWindowName = '_blank'
	style = 'menubar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=1,width=600,height=560';
	popupWin = window.open(sURL,sWindowName,style)
	setTimeout('popupWin.focus()',500);	
}

//Used for drop down menus
function MenuOnChange (oSelect)
{
   if (oSelect.selectedIndex >= 0 && (oSelect.options[oSelect.selectedIndex].value!=null &&oSelect.options[oSelect.selectedIndex].value!=''))
   {
         window.top.location.href = oSelect.options[oSelect.selectedIndex].value;
   }
}

function JLoad(imgName,imgType,imgPath)
{
	eval(imgName + " = new Image();");
	eval(imgName + ".src = \"/images/"+ imgPath + imgName + imgType+"\"");
}

function preLoad(imgName,imgNum,imgType) {
    
	imgType = (imgType == null) ? ".gif\";" : ".jpg\";";
	for (i=0; i < imgNum; i++) {
		eval(imgName + i + " = new Image();");
		eval(imgName + i + ".src = \"/images/" + imgName + i + imgType);
	}
}

function swapImg(imageLoc,imageFile)
{
	document.images[imageLoc].src = eval(imageFile + ".src");

}

function flipImg(imgName,imgSrc) 
{
    if(document.images[imgName] != null)
    {
   	    document.images[imgName].src = imgSrc;
   	}
}
	

//get a random number
function rand(n) 
{
	var now = new Date();
	var seed = now.getTime() % 0xffffffff;
    seed = (0x015a4e35 * seed) % 0x7fffffff;
    return (seed >> 16) % n;
}

//Submit the searchForm to "/search/results.asp" 
function searchSubmit()
{
    document.forms.searchForm.method = "POST"
    document.forms.searchForm.action = "/search/results.asp"                
    document.forms.searchForm.submit()
} 

//Check Browser
function BrowserCheck()
{
		var b = navigator.appName
		if (b=="Netscape") this.b = "ns"
		else if (b=="Microsoft Internet Explorer") this.b = "ie"
		else this.b = b
		this.v = parseInt(navigator.appVersion)
		this.ns = (this.b=="ns" && this.v>=4)
		this.ns4 = (this.b=="ns" && this.v==4)
		this.ns5 = (this.b=="ns" && this.v==5)
		this.ie = (this.b=="ie" && this.v>=4)
		this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0)
		this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0)
		if (this.ie5) this.v = 5
		this.min = (this.ns||this.ie)
		var p = navigator.platform
		//if (p=="MacPPC") this.p = "mac"
		//else this.p = p
	}

// get a today's date returned in a "January 28, 2000" format.
 function Now()
 {
	var sDate = null;
	var monthNames = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	var now = new Date();
	return (monthNames[now.getMonth()] + " " + now.getDate() +", "+ now.getFullYear());
 }

// this is the code to switch from the loading display to the body display
// this would be called onLoad , there must be introsec, and bodysec div's defined
 function switchV() 
{
    document.all.introsec.style.visibility =  "hidden";
    document.all.introsec.style.display =  "none";
    document.all.bodysec.style.visibility =  "visible";
    document.all.bodysec.style.display =  "";
}

//Create Popup tile (IE 5.5)
function PopTile(sTopic, x, y, h, w)
{
    var oPopup = window.createPopup();
    var oPopupBody = oPopup.document.body;
    oPopupBody.innerHTML = ''
    oPopupBody.innerHTML += '<TABLE ID="help" border="1" width="100%" height="100%"><TR><TD valign="top"><DIV style="height: 100%; overflow: auto;">' + sTopic + '</DIV></TD></TR></TABLE>';
    oPopup.show (x,y,h,w,document.body);
}


function clientTime()
{
    //this function gets the clients current time and writes it
    
    var oDate = new Date()
    
    var aMonths = new Array("January",
                         "February",
                         "March",
                         "April",
                         "May",
                         "June",
                         "July",
                         "August",
                         "September",
                         "October",
                         "November",
                         "December")
                         
    var aDays= new Array("Sunday",
                         "Monday",
                         "Tuesday",
                         "Wednesday",
                         "Thursday",
                         "Friday",
                         "Saturday")                         
 
    
    var sDate = aDays[oDate.getDay()] + ", " + aMonths[oDate.getMonth()] + " " + oDate.getDate() + ", " + oDate.getFullYear()
    
    document.write(sDate)
}

function OpenConnection(url)
{
	style = 'menubar=1,toolbar=1,location=1,directories=1,status=1,scrollbars=1,resizable=1,';
	style += '';
	windowName = 'popUp';

	//if popping media attachment then add on the host name to the url.
	if(url.search('/adx/Common/GetMedia') > -1 || url.search('/attachments/') > -1)
	{
        url = "http://"+ window.location.host + url	
	}
	
	if(url.search('http://')==-1 && url.search('HTTP://')==-1)
	{
	    url='http://'+url
	}	
    
	popupWin = window.open(url, windowName, style);
	setTimeout('popupWin.focus()',500);

}


function SubmitSurveyForm()
{
	  var sErrorMsg = '';
	  	
	  //if (document.SurveyForm.realname.value == '') { sErrorMsg += "  Your Name Required\n"; }

	  if (sErrorMsg != '')
	  {
		//sErrorMsg = "We’re sorry, requires the entry of the following form fields in order to process this form: Your Name and Message. Please review your entry, complete the necessary fields and click Send Message."
	  }
	  if (sErrorMsg == '')
	  {
		//document.forms.SurveyForm.action="/Default.asp?DN=<%//=sDN%>"
        document.forms.SurveyForm.submit(); 
	  }
	  else
	  {
		alert(sErrorMsg);
	  }
}

function disable_Text(oText)
{
	//oText.disabled = true;
	
	//if (oText.disabled) 
	//{	
	oText.blur();		
	//}	
}

function disable_checkbox(oCheck)
{
	//alert(oCheck.checked)
	if (oCheck.checked)
	{
	 oCheck.checked = false
	 //alert("1="+oCheck.checked)
	}
	else
	{
	 oCheck.checked = true
	 //alert("2="+oCheck.checked)
	}
}

function ClearFormFields(oForm)
{
   // This function currently handles only single-select drop down and 
   // text input fields.
   var iKey;
   for (iKey = 0; iKey < oForm.length; iKey++)
      if (oForm[iKey].type == "select-one")
         oForm[iKey].selectedIndex = -1;
      else
         oForm[iKey].value = oForm[iKey].defaultValue;
}

function checkForm()
{
	var sValue = document.SurveyForm.Message.value; 
	var sLength = document.SurveyForm.Message.value.length;
	if (sLength > 12500)
	{
		alert('This text area has a maximum of 2500 words')
		document.SurveyForm.Message.value = sValue.substring(0,12500); 
	}
}
function clickReda(iNum)
{
	var iCN = 2974
	iCN = iCN + iNum
	window.location.href = "default.aspx?DN=cn="+iCN+",2973,2970,2936,Documents"
}
function changeMode()
{
	var sCurrentMode = document.getElementById("viewspan").innerHTML;
	if (sCurrentMode == "Preview Document")
	{
		document.cookie = "IRADMINPreviewMode=false"
		document.getElementById("viewspan").innerHTML = "Public Document";
	}
	else
	{
		document.cookie = "IRADMINPreviewMode=true"
		document.getElementById("viewspan").innerHTML = "Preview Document";
	}
}
//opens a new window
function openWindow(url,name,style)
{
	if(name == null || name == '')
	{
		name = 'popwinwindow'
	}
	
	window.open(url,name,style);
}
function openEditor(sURL,sName)
{
	var sVersion = navigator.appVersion.toLowerCase();
	
	var style = '';
	
	if(sVersion.indexOf("msie 5.5") == -1 &&
		sVersion.indexOf("msie 5.22") == -1 &&
		sVersion.indexOf("msie 6.0") == -1)
    {
        //check version of MSIE
        //sURL =  "/adx/distribution/GetMSIE.asp";
        //window.top.location.href = "/adx/distribution/GetMSIE.asp"
        alert("This functionality is only available with Internet Explorer version 5.5 or greater.");
    }
	else
	{
		var iLeft = window.screenLeft;
		var iTop = window.screenTop;
		var iWidth = 500;
		var iHeight = 620;
		
		style = 'top='+iTop+',left='+iLeft+',menubar=0,toolbar=0,location=0,directories=0,status=0,resizable=1,dependent=0,width='+iWidth+',height='+iHeight;
		window.open(sURL,"Editor"+sName,style)
	}
	
}	
	
function openConsole()
{
	var sVersion = navigator.appVersion.toLowerCase();
	var sURL = '/adx/admin'
	var style = '';
	
	if(sVersion.indexOf("msie 5.5") == -1 &&
		sVersion.indexOf("msie 5.22") == -1 &&
		sVersion.indexOf("msie 6.0") == -1)
    {
        //check version of MSIE
        alert("This functionality is only available with Internet Explorer version 5.5 or greater.");
    }
	else
	{
		window.open(sURL,"Console")
	}
}

//
// slideshow functions
//
function openSlide(sDN)
{
	var sScript = "slideshow.aspx"
	
	window.open(sScript+"?DN="+sDN,"_blank","menubar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,width=600px,height=383px,center=1")
	//window.open(sScript+"?DN="+sDN,"_blank")
} 

function EmailValidate(Email)
{
	var re=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
	return re.test(Email);
}

function clearForm () {
//      alert(elements(8).type)
        var elements = document.getElementsByTagName('input'); 
        for (var i=0;  i<elements.length; i++) {
            if (elements(i).type == "text") {
                elements(i).value = "";
            }
        }      
        
        var elements2 = document.getElementsByTagName('select');   
        for (var i=0; i<elements2.length; i++) {
//          alert(elements2(i).type)
            elements2(i).options[0].selected = "Selected";
        }
        
        var elements3 = document.getElementsByTagName('textarea');
        for (var i=0; i<elements3.length; i++) {
            elements3(i).value = "";
        }
    }

///<summary>
/// Validates that all of the required fields in the contact form are valid
///</summary>
function ValidateContactUs()
{
    var oFN = document.ContactUs.FirstName;
    var oLN = document.ContactUs.LastName;
    var oMsg = document.ContactUs.Message;
	var oEmail = document.ContactUs.Email;
	var oCat = document.ContactUs.Category;
    var ErrorMsg = "";
    
    ResetErrorsContactUsForm();
     
    
//    if(oCat.selectedIndex <1)
//    {
//		ErrorMsg += " - Please select a recipient.\n";
//		oCat.className += " CUInputError";
//    }
    
    if(oFN.value.length < 1)
    {
        ErrorMsg += " - Please supply your first name.\n";
        oFN.className += " CUInputError";
    }
    
    if(oLN.value.length < 1)
    {
        ErrorMsg += " - Please supply your last name.\n";
        oLN.className += " CUInputError";
    }
    
    if(oMsg.value.length < 1)
    {
        ErrorMsg += " - Please supply a message.\n";
        oMsg.className += " CUInputError";
    }
    
    if(oEmail.value.length < 1)
    {
		ErrorMsg += " - Please supply your email address.\n";
        oEmail.className += " CUInputError";
    }
    
    if(ErrorMsg.length > 0)
    {
        alert("We're sorry, we could not deliver your message as entered.\n" + ErrorMsg);
    }
    else
    {
        document.ContactUs.submit();
    }
    
}//ValidateContactUs

///<summary>
/// Resets the error backgrounds on the inputs
///</summary>
function ResetErrorsContactUsForm()
{
    var oFN = document.ContactUs.FirstName;
    var oLN = document.ContactUs.LastName;
    var oMsg = document.ContactUs.Message;
    var oEmail = document.ContactUs.Email;
    oFN.className = oFN.className.replace(" CUInputError", "");
    oLN.className = oLN.className.replace(" CUInputError", "");
    oMsg.className = oMsg.className.replace(" CUInputError", "");
    oEmail.className = oEmail.className.replace(" CUInputError", "");
}//ResetErrorsContactUsForm

///<summary>
/// Using the attributes in the form HTML, validate the form, itself.
/// You can put a teeny tiny bit of formating into the field names for display to the end user
/// but using underscores in the field name. A single underscore will be replaced with a space
/// and 2 underscores together will be replaced with a single quote.
///<example>
/// 'My_Friend__s_Email_Address' would become 'My Friend's Email Address'
///</example>
///</summary>
///<param name="oForm">The form object we are to validate</param>
function GenericFormValidate(oForm)
{
    var ErrorMessage = "";
    var oEls = oForm.elements;
    
    // clear out previous errors
    GenericFormReset(oEls, null);
    
    // loop through all elements
    for(var i=0; i<oEls.length; i++)
    {
        var CurEl       = oEls[i];
        var ValType     = CurEl.getAttribute("ValidationType");
        var ValDataType = CurEl.getAttribute("ValidationDataType");    
        var CurName     = CurEl.name.replace(/__/g, "'").replace(/_/g, " ");
        if(ValType != null && ValType.toLowerCase() == "required")
        {
            if(CurEl.value.length < 1)
            {
                ErrorMessage += " - Please provide your " + CurName + ".\n";
                SetFieldError(CurEl);
            }
            else if(ValDataType != null)
            {
                ValDataType = ValDataType.toLowerCase();
                
                // all of our valid data types
                if(ValDataType == "email")
                {
                    if(!EmailValidate(CurEl.value))
                    {
                        ErrorMessage += " - " + CurName + " does not have the value of a valid email address\n";
                    }
                }
                
                /*
                else if(ValDataType == "integer")
                {
                }
                else if(ValDataType == "float")
                {
                }                
                else if(ValDataType == "date")
                {
                }                
                else if(ValDataType == "betty")
                {
                }                
                */
            }
        }//required element
    }//for each element  
    
    if(ErrorMessage.length > 0)  
    {
        alert("We're sorry, we could not deliver your message as entered.\n" + ErrorMessage);
    }
    else
    {   
        oForm.submit();
    }
}//ValidateEmailAFriend

///<summary>
/// Sets a field as an error field
///</summary>
function SetFieldError(oField)
{
    oField.className += " CUInputError";
    oField.setAttribute("Error", "true");
}//SetFieldError

///<summary>
/// Removes the error state of a field
///</summary>
function ResetFieldError(oField)
{
    oField.className = oField.className.replace(" CUInputError", "");
    oField.removeAttribute("Error");
}//ResetFieldError

///<summary>
/// Resets any and
///</summary>
///<param name="oElList">A list of the elements in the form, (optional)</param>
///<param name="oForm">The form object we are to validate</param>
function GenericFormReset(oElList, oForm)
{
    if(oElList == null)
    {
        oElList = oForm.elements;
    }
    
    // find all nodes that are in error and reset them
    for(var i=0; i<oElList.length; i++)
    {
        if(oElList[i].getAttribute("Error") == "true")
        {
            ResetFieldError(oElList[i]);
        }
    }//for each element    
    
    // only reset the form if we have the form object
    if(oForm != null)
    {
        oForm.reset();
    }
}//GenericFormReset
		
//-->