//***********************************************************

var childwin=null;

//===================================================

function ask(msg, target) {
    
	if (confirm(msg) == true)
	location.replace(target);		
}

//===================================================

function open_smallwindow(link, title){
    
	if(childwin && childwin.closed==false)
	childwin.close(); 
	childwin = window.open(link, title, "width=800, height=600,toolbar=no,scrollbars=yes,resizable=yes,menubar=yes,screenX=200,screenY=50");
}
//===================================================

function open_uploadwindow(link, title){
    
	if(childwin && childwin.closed==false)
	childwin.close(); 
	childwin = window.open(link, title, "width=400, height=300,toolbar=no,scrollbars=no,resizable=no,menubar=no,screenX=200,screenY=50");    
}

//===================================================    

function open_newwindow(link, title) {
    
	childwin = window.open(link, title, "width=800, height=600,toolbar=yes,scrollbars=yes,resizable=yes,menubar=no,screenX=200,screenY=50");
}


//***********************************************************

function createTarget(title) {

    if(childwin && childwin.closed==false)
    childwin.close(); //width=800, height=600,

	childwin = window.open("", title, "toolbar=no,menubar=yes, scrollbars=yes,resizable=yes,screenX=0,screenY=0");
    return true;
}

//===========================================================

function confirm_submit() {

    if(confirm('Are you sure you would now like to close the Interactve Evaluation for this Standard? You will not be able to post questions once it is been closed.')) {

        return true;
    }
    return false;
}

function confirm_amendment_submit() {
    
    if(confirm('Are you sure you would now like to close the Amendments for this Standard? The program will not be able to make any amendments once it is been closed.')) {

        return true;
    }
    return false;    
}    

function confirm_amendment_complete() {
    
    if(confirm('Are you sure you would now like to close the Amendments for this Standard? You will not be able to make any amendments once it is been closed.')) {

        document.forms.amendment.submit();
    }
    document.forms.amendment.amendment_status.checked = '';
    return false;    
}    

function confirm_corrections_complete() {
    
    if( confirm('Are you sure you would now like to release the Corrections for this Standard? You will not be able to make any changes once it is been closed.\nClick the Save button to submit.')) {

        document.forms.program_corrections.submit();
    }
    document.forms.program_corrections.corrections_status.checked = '';
    return false;    
}   

function confirm_message_release() {

    if(confirm('Are you sure you would now like to Post this Question and Send a Notification Email to the Program Users?\nYou will not be able to edit the question once it has been posted.')) {

        return true;
    }
    return false;
}

function confirm_response_release() {

    if(confirm('Are you sure you would now like to Post this Response and Send a Notification Email to the Site Visitor?\nYou will not be able to edit the response once it has been posted.')) {

        return true;
    }
    return false;
}

function confirm_sv_report_revise() {

    if(confirm('Are you sure you would now like to revise the Preliminary Site Visit Report?')) {

        return true;
    }
    return false;
}

function confirm_site_visit_report_release() {

    var report_status = document.forms.release_report.release_status.value;
    var report_action = document.forms.release_report.submit.value;

    if(confirm('Are you sure you would now like to '+report_action+' this Site Visit Report?')) {

        return true;
    }
    return false;    
}

function confirm_board_report_release() {

    var report_status = document.forms.release_report.release_status.value;
    var report_action = document.forms.release_report.submit.value;

    if(confirm('Are you sure you would now like to '+report_action+' this Board Report?')) {

        return true;
    }
    return false;    
}    
//===========================================================

function confirm_draft_complete() {
    
    var status_checked = 0;
    for (var i=0; i < document.forms[0].accred_status.length; i++)  { 
        
        if ( document.forms[0].accred_status[i].checked && document.forms[0].accred_status[i].value != 3 )  {

            status_checked = document.forms[0].accred_status[i].value;
        } 
    }
    
    if( status_checked == 0 ) {
    
        alert('Please select a valid reccommended status level for this report before releasing it to the Site Visit Chair\n');
        return false;
    }
   
    if(confirm('Are you sure you would now like to submit your Status Level and Accompanying Statement for this Standard to the Site Visit Chair?\nYou will not be able to edit this statement further once it is been submitted.')) {
        document.forms.draft.submit();
    }
    return false;    
}    

function confirm_author_report_revise() {
    
    if(confirm('Are you sure you would now like to return this report to Primary reviewer for further edits?')) {
        return true;
    }
    return false;    
        
}
    
function confirm_report_release() {
    
    var status_checked = 0;
    for (var i=0; i < document.forms[0].accred_status.length; i++)  { 
        
        if ( document.forms[0].accred_status[i].checked && document.forms[0].accred_status[i].value != 3 )  {

            status_checked = document.forms[0].accred_status[i].value;
        } 
    }
    
    var report = document.forms[1].member_comments.value;
    
    /*
    var pattern_found = 0;    
    var valid_text_pattern = /^\w+$/;
    alert(report);
    pattern_found = report.search(valid_text_pattern);
    alert("Valid Text "+valid_text);
    */

    pattern_found = report.length;        
                
    if( status_checked == 0 && pattern_found <= 0 ) {

        alert('Please select a reccommended status level and write an accompanying statement for this report before releasing it to the Program\n');
        return false;        
    }        
    
    
    if( status_checked == 0 ) {
    
        alert('Please select a reccommended status level for this report before releasing it to the Program\n');
        return false;
    }
   
    if( pattern_found <= 0 ) {
    
        alert('Please write a valid statement for this report before releasing it to the Program\n');
        return false;
    }
       
    if(confirm('Are you sure you would now like to release the Status Level and Accompanying Statement for this Standard to become part of the Preliminary Site Visit Report?\nYou will not be able to edit this statement further unless you click \'Revise Report\' link')) {

        document.forms.draft.submit();
    }
    return false;    
}    


function confirm_follow_up_release() {
    
    if(confirm('Are you sure you would now like to release the Follow Up instructions to the program?')) {

        document.forms.follow_up.submit();
    }
    return false;    
} 

function confirm_follow_up_reopen() {
    
    if(confirm('Are you sure you would now like to reopen Follow Up response section for the program?')) {

        document.forms.follow_up.submit();
    }
    return false;    
} 

function confirm_follow_up_release_to_agency() {

    if(confirm('Are you sure you would now like to Submit the Follow Up responses to ACAE? \nYou will not be able to edit any of the above responses.')) {

        document.forms.follow_up.submit();
    }
    return false;        
}
    
function confirm_self_study_submit_to_agency() {
    
    if(confirm('Are you sure you would now like to Submit the Program Self-Study to ACAE? \nYou will not be able to edit any of the responses.')) {

        document.forms.self_study.submit();
    }
    return false;            
}

function confirm_self_study_revise() {

    if(confirm('Are you sure you would now like to revise  self-study response for this standard?')) {
        return true;
    }
    return false;        
}
        

function setAccess(obj) {

	var nam = obj.name;
	var chkd = eval('document.forms[0].'+nam+'.checked');
	var chk = nam.replace('W', 'S');
	var n = eval('document.forms[0].'+chk+'.checked');
	
	if(chkd && !n)
	{
		eval('document.forms[0].'+chk+'.checked = true;');
	}	
}

   
