function openWindow(url, width, height, properties)
{
	var props;
	
	if (properties == '')
		props = "resizable=no,scrollbars=no,menubar=no,status=no,toolbar=no,location=no";
	else
		props = properties;
		
	var win = window.open(url, 'window', 'width=' + width + ',height=' + height + ',' + properties);
}

function returnDate(date)
{
    var container = getQuerystringValue('c');
    var element = 'ctl00_ctl00_MainContentHolder_ContentHolder_' + getQuerystringValue('e');
    parent.displayDate(container, element, date);
    parent.showHide(container);
}
		
function displayDate(container, element, date)
{
    if (document.getElementById) // NS
        field = document.getElementById(element);
    else if (document.all) // IE
        field = document.all[element];
	
	field.value = date;
}

function ShowPhoto()
{
    if (document.getElementById) // NS
        photo = document.getElementById('ctl00_ctl00_MainContentHolder_ContentHolder_txtPhoto');
    else if (document.all) // IE
        photo = document.all['ctl00_ctl00_MainContentHolder_ContentHolder_txtPhoto'];
    
    if (photo.value != '')
        openWindow(photo.value, 350, 300);
}

function showSection(element, action)
{
    if (document.getElementById) // NS
        target = document.getElementById(element);
    else if (document.all) // IE
        target = document.all[element];
        
    if (action == "show")
		target.style.display = "";
	else
		target.style.display = "none";
}

function showHide(element)
{
    if (document.getElementById) // NS
        target = document.getElementById(element);
    else if (document.all) // IE
        target = document.all[element];

    if (target)
    {
        if( target.style.display == "none" )
            target.style.display = "";
        else
            target.style.display = "none";
    }
}

function addSchool()
{
    if (document.getElementById) // NS
        box = document.getElementById('ctl00_ctl00_MainContentHolder_ContentHolder_hdnColleges');
    else    // IE
        box = document.all['ctl00_ctl00_MainContentHolder_ContentHolder_hdnColleges'];
    
    var schools = getQuerystringValue('schools');
    
    if (schools != null)
        schools = parseInt(schools) + 1;
    else
        schools = parseInt(box.value) + 1;
    
    document.aspnetForm.action = 'education.aspx?schools=' + schools;
}

function addCollege()
{
    if (document.getElementById) // NS
    {
        collegeBox = document.getElementById('ctl00_ctl00_MainContentHolder_ContentHolder_hdnColleges');
        seminaryBox = document.getElementById('ctl00_ctl00_MainContentHolder_ContentHolder_hdnSeminaries');
    }
    else    // IE
    {
        collegeBox = document.all['ctl00_ctl00_MainContentHolder_ContentHolder_hdnColleges'];
        seminaryBox = document.all['ctl00_ctl00_MainContentHolder_ContentHolder_hdnSeminaries'];
    }
    
    var schools = getQuerystringValue('schools');
    var seminaries = getQuerystringValue('seminaries');
    
    if (schools != null)
        schools = parseInt(schools) + 1;
    else
        schools = parseInt(collegeBox.value) + 1;
    
    if (seminaries == null)
        seminaries = seminaryBox.value;
    
    document.aspnetForm.action = 'education.aspx?seminaries=' + seminaries + '&schools=' + schools;
}

function addSeminary()
{
    if (document.getElementById) // NS
    {
        collegeBox = document.getElementById('ctl00_ctl00_MainContentHolder_ContentHolder_hdnColleges');
        seminaryBox = document.getElementById('ctl00_ctl00_MainContentHolder_ContentHolder_hdnSeminaries');
    }
    else    // IE
    {
        collegeBox = document.all['ctl00_ctl00_MainContentHolder_ContentHolder_hdnColleges'];
        seminaryBox = document.all['ctl00_ctl00_MainContentHolder_ContentHolder_hdnSeminaries'];
    }
    
    var schools = getQuerystringValue('schools');
    var seminaries = getQuerystringValue('seminaries');
    
    if (seminaries != null)
        seminaries = parseInt(seminaries) + 1;
    else
        seminaries = parseInt(seminaryBox.value) + 1;
    
    if (schools == null)
        schools = collegeBox.value;
    
    document.aspnetForm.action = 'education.aspx?seminaries=' + seminaries + '&schools=' + schools;
}

function addChild()
{
    if (document.getElementById) // NS
        box = document.getElementById('ctl00_ctl00_MainContentHolder_ContentHolder_hdnChildren');
    else    // IE
        box = document.all['ctl00_ctl00_MainContentHolder_ContentHolder_hdnChildren'];

    var children = getQuerystringValue('children');
    
    if (children != null)
        children = parseInt(children) + 1;
    else
        children = parseInt(box.value) + 1;
    
    document.aspnetForm.action = 'PersonalData.aspx?children=' + children;
}

function confirmDelete(control)
{
    if (document.getElementById) // NS
    {
        checkbox = document.getElementById('ctl00_ctl00_MainContentHolder_ContentHolder_chkDelete');
        button = document.getElementById('ctl00_ctl00_MainContentHolder_ContentHolder_btnSubmit');
    }
    else if (document.all) // IE
    {
        checkbox = document.all['ctl00_ctl00_MainContentHolder_ContentHolder_chkDelete'];
        button = document.all['ctl00_ctl00_MainContentHolder_ContentHolder_btnSubmit'];
    }
    
    if (control.value == "Disapprove" & button.value == "Approve Add")
    {
        return confirm('Are you sure you want to delete this item?');
    }
    else
    {
        if (checkbox.checked == true)
            return confirm('Are you sure you want to delete this item?');
        else
            return true;
    }
}

/****************************************************************
*	Name: isDefined
*	Purpose: determines if a variable is defined or not
*	Attributes:
*		-->variable: STRING with the name of the variable to check
*		<--return: BOOLEAN value
****************************************************************/
function isDefined(variable)
{
	return (typeof(variable) == "undefined") ? false : true;
}

/****************************************************************
*	Name: getQuerystringValue
*	Purpose: gets a value from the querystring
*	Attributes:
*		-->arg: STRING with the name of the variable to get
*		<--return: a STRING of the value or NULL
****************************************************************/
function getQuerystringValue(arg)
{
	var queryString = location.search;
	if ( queryString.indexOf(arg) >= 0 )
	{
		var position = queryString.indexOf(arg + "=") + arg.length + 1;
		if ( queryString.indexOf("&", position) >= 0 )
			return queryString.substring(position, queryString.indexOf("&", position));
		else
			return queryString.substring(position, queryString.length);
	}
	else
	{
		return null;
	}
}
