// Copyright (c) Custom Browser, Inc.

// Adds document.getElementById support to IE
if(document.all && !document.getElementById) {
    document.getElementById = function(id) {
         return document.all[id];
    }
}

// Confirms deletion of an item
function confirmDelete(name) {
	return confirm("Are you sure you want to delete \"" + name + "\"?")
}

// Confirms the execution of a scenario
function confirmExecuteScenario(name) {
	return confirm("Are you sure you want to execute the scenario \"" + name + "\"?")
}

// Validates the password length
function validatePasswordLength(oSrc, args) {
	args.IsValid = (args.Value.length >= 6);
}

function SelectAll( controlName ) {
	if ( typeof( document.getElementById ) == "undefined" ) return;
    
    var control = document.getElementById( controlName );
    
    if ( control == null ) return;
    
    control.focus();
    control.select();
}

function toggleVisibility(target) {
	obj = document.getElementById(target);
	obj.style.display = ( (obj.style.display=='none') ? '' : 'none' );
}

function WriteLocalDate(utcDateString) {
	var utcDate = new Date(utcDateString);
	var localDate = GetLocalDate(utcDate);
	
	document.write(GetDateString(localDate));
}

function GetDateString(d) {
	var days = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
	var month = d.getMonth() + 1;
	//var s = days[d.getDay()] + " " + month + "/" + d.getDate();
	var s = month + "/" + d.getDate() + "/" + d.getFullYear();
	
	var hours = d.getHours();
	var minutes = d.getMinutes();
	//var seconds = d.getSeconds();
	var ampm = "";
	
	if( hours >= 12 )
		ampm = "PM";
	else
		ampm = "AM";
	
	if( hours >= 13 )
		hours -= 12;
		
	if( hours == 0 )
		hours = 12;
	
	//if( seconds < 10 )
	//	seconds = "0" + seconds;
	
	if( minutes < 10 )
		minutes = "0" + minutes;
		
	var time = hours + ":" + minutes + " " + ampm;
	
	return s + " " + time;
}

function GetLocalDate(utcDate) {
	var localDate = utcDate;
	localDate.setMinutes(utcDate.getMinutes() - utcDate.getTimezoneOffset());
	return localDate;
}


// Checkbox code
// Based on MetaBuilder's RowSelector
function DesktopAlert_CheckedRepeater_SelectAll( parentName ) {
    if ( typeof( document.getElementById ) == "undefined" ) return;
    
    var parentCheckBox = document.getElementById( parentName );
    if ( parentCheckBox == null || typeof( parentCheckBox.participants ) == "undefined" ) return;
    
    var participants = parentCheckBox.participants;
    for ( var i=0; i < participants.length; i++ ) {
        var participant = participants[i];
        if ( participant != null ) {
            participant.checked = parentCheckBox.checked;
        }
    }
}
function DesktopAlert_CheckedRepeater_Register( parentName, childName ) {
    if ( typeof( document.getElementById ) == "undefined" ) return;
    var parent = document.getElementById( parentName );
    var child = document.getElementById( childName );
    if ( parent == null || child == null ) {
        return;
    }
    if ( typeof( parent.participants ) == "undefined" ) {
        parent.participants = new Array();
    }
    parent.participants[parent.participants.length] = child;
}
function DesktopAlert_CheckedRepeater_CheckChildren( parentName ) {
	if ( typeof( document.getElementById ) == "undefined" ) return;
    
    var parent = document.getElementById( parentName );
    
    if ( parent == null || typeof( parent.participants ) == "undefined" ) return;
    
    var participants = parent.participants;
    
    for ( var i=0; i < participants.length; i++ ) {
        var participant = participants[i];
        if ( participant != null && !participant.checked ) {
				parent.checked = false;
				return;
        }
    }
    parent.checked = true;
}