vFormName = 'mainform';
vState = 'state';
var saved_campus_key = '';

window.onload = "preloadImages";


//FIELD NAME,DISPLAY NAME,TYPE
//TYPE (name,phone,zip,email,text,select)
vRequiredFields = '';
vRequiredFields += 'firstname,First Name,text,';
vRequiredFields += 'lastname,Last Name,text,';
vRequiredFields += 'address1,Address,text,';
vRequiredFields += 'city,City,text,';
vRequiredFields += 'state,State,select,';
vRequiredFields += 'zip,Zip,zip,';
vRequiredFields += 'phone,Preferred Phone,phone,';
vRequiredFields += 'phone2,Alternate Phone,phoneNR,';
vRequiredFields += 'email,Email,email,';
vRequiredFields += 'extrafield15,Highest Level of Education,select,';
vRequiredFields += 'extrafield1,Online or Campus-based Learning,radio,';
vRequiredFields += 'extrafield13,Area of Interest,select,';
vRequiredFields += 'program_key,Program,select,';
vRequiredFields += 'extrafield10,US Citizen,radio,';
vRequiredFields += 'extrafield12,Contact Me,checkbox';


function dynamic_exclude() {
    thisForm = document.forms[vFormName];

    getProgram();
    program_optgroup_text = thisForm.elements["extrafield13"][thisForm.elements["extrafield13"].selectedIndex].text;
    //alert(program_optgroup_text);
   
    programSelect = document.getElementById("program_key")
    optgroups = programSelect.getElementsByTagName("optgroup");
    //alert(optgroups.length);
    if( program_optgroup_text != 'Show all' || thisForm.elements["extrafield13"].selectedIndex == 0 ){
        for (i=optgroups.length-1; i>=0; i--) {
            //alert(optgroups[i].label + " " + optgroups[i].childNodes.length);
            //if( optgroups[i].childNodes.length == 0 ){
            if( optgroups[i].label != program_optgroup_text ){
                optgroups[i].parentNode.removeChild(optgroups[i]);
            }
        }
    }
   
    if( thisForm.program_key.length < 2 )
    {
        alert("Sorry, there is no Program available under this area of interest. Please pick another Area of Interest or select Show All.");
        thisForm.elements["extrafield13"].selectedIndex = 0;
    }
}

function modality_change() {
    thisForm = document.forms[vFormName];
   
    if(saved_campus_key == '')
        saved_campus_key = document.forms['mainform'].campus_key.value;

    if(thisForm.extrafield1[0].checked) {
        thisForm.campus_key.value = thisForm.state[thisForm.state.selectedIndex].value;
    } else {
        thisForm.campus_key.value = saved_campus_key;
    }
    getProgram();
    //dynamic_exclude();
}

function modality_online() {
    thisForm = document.forms[vFormName];
    newstatestring = thisForm.state[thisForm.state.selectedIndex].text.replace(/ /g,'-');
    state_text = thisForm.state[thisForm.state.selectedIndex].text;
   setCookie('school_type', 'O', 1 );
    form_id_array = new Array("2543","2544","2545","2546","2547","2548","2549","2550","2551","2552","2553","2554","2555","2556","2557","2558","2559","2560","2561","2562","2563","2564","2565","2566","2567","2568","2569","2570","2571","2572","2573","2574","2575","2576","2577","2578","2579","2580","2581","2582","2583","2584","2585","2586","2587","2588","2589","2590","2591","2592","2593","2595","2596","2597");
    form_statename_array = new Array("alabama","alaska","arizona","arkansas","california","colorado","connecticut","delaware","district of columbia","florida","georgia","hawaii","idaho","illinois","indiana","iowa","kansas","kentucky","louisiana","maine","maryland","massachusetts","michigan","minnesota","mississippi","missouri","montana","nebraska","nevada","new hampshire","new jersey","new mexico","new york","north carolina","north dakota","ohio","oklahoma","oregon","pennsylvania","rhode island","south carolina","south dakota","tennessee","texas","utah","vermont","virginia","washington","west virginia","wisconsin","wyoming","armed forces international","armed forces americas","armed forces pacific");
    form_link_array = new Array("/ce/u_of_phoenix/state-alabama.php","/ce/u_of_phoenix/state-alaska.php","/ce/u_of_phoenix/state-arizona.php","/ce/u_of_phoenix/state-arkansas.php","/ce/u_of_phoenix/state-california.php","/ce/u_of_phoenix/state-colorado.php","/ce/u_of_phoenix/state-connecticut.php","/ce/u_of_phoenix/state-delaware.php","/ce/u_of_phoenix/state-district-of-columbia.php","/ce/u_of_phoenix/state-florida.php","/ce/u_of_phoenix/state-georgia.php","/ce/u_of_phoenix/state-hawaii.php","/ce/u_of_phoenix/state-idaho.php","/ce/u_of_phoenix/state-illinois.php","/ce/u_of_phoenix/state-indiana.php","/ce/u_of_phoenix/state-iowa.php","/ce/u_of_phoenix/state-kansas.php","/ce/u_of_phoenix/state-kentucky.php","/ce/u_of_phoenix/state-louisiana.php","/ce/u_of_phoenix/state-maine.php","/ce/u_of_phoenix/state-maryland.php","/ce/u_of_phoenix/state-massachusetts.php","/ce/u_of_phoenix/state-michigan.php","/ce/u_of_phoenix/state-minnesota.php","/ce/u_of_phoenix/state-mississippi.php","/ce/u_of_phoenix/state-missouri.php","/ce/u_of_phoenix/state-montana.php","/ce/u_of_phoenix/state-nebraska.php","/ce/u_of_phoenix/state-nevada.php","/ce/u_of_phoenix/state-new-hampshire.php","/ce/u_of_phoenix/state-new-jersey.php","/ce/u_of_phoenix/state-new-mexico.php","/ce/u_of_phoenix/state-new-york.php","/ce/u_of_phoenix/state-north-carolina.php","/ce/u_of_phoenix/state-north-dakota.php","/ce/u_of_phoenix/state-ohio.php","/ce/u_of_phoenix/state-oklahoma.php","/ce/u_of_phoenix/state-oregon.php","/ce/u_of_phoenix/state-pennsylvania.php","/ce/u_of_phoenix/state-rhode-island.php","/ce/u_of_phoenix/state-south-carolina.php","/ce/u_of_phoenix/state-south-dakota.php","/ce/u_of_phoenix/state-tennessee.php","/ce/u_of_phoenix/state-texas.php","/ce/u_of_phoenix/state-utah.php","/ce/u_of_phoenix/state-vermont.php","/ce/u_of_phoenix/state-virginia.php","/ce/u_of_phoenix/state-washington.php","/ce/u_of_phoenix/state-west-virginia.php","/ce/u_of_phoenix/state-wisconsin.php","/ce/u_of_phoenix/state-wyoming.php","/ce/u_of_phoenix/state-armed-forces-international.php","/ce/u_of_phoenix/state-armed-forces-americas.php","/ce/u_of_phoenix/state-armed-forces-pacific.php");
   
    if( top.location.hostname == 'accounting.topcareerschools.com'  ) { //10.10.0.127
        if(thisForm.state.selectedIndex != 0) {
            //alert(newstatestring.toLowerCase());
            state_value = newstatestring.toLowerCase();
            for(i=0; i < form_statename_array.length; i++) {
                if( form_statename_array[i] == state_value ) {
                    //alert(i + ' ' + form_statename_array[i]); alert('3_' + form_id_array[i]);
                    parent.changeIframe(form_id_array[i],'University of Phoenix');
                }
            }
        } else {
            thisForm.extrafield1[0].checked = false;
            thisForm.extrafield1[1].checked = false;
            alert('Please select your state first!');
        }
    } else {
        if(thisForm.state.selectedIndex != 0) {
            if(state_text != 'Alberta' && state_text != 'British Colombia' && state_text != 'Guam' && state_text != 'Manitoba' && state_text != 'New Brunswick' && state_text != 'Newfoundland' &&
               state_text != 'Nova Scotia' && state_text != 'Northwest Territories' && state_text != 'Nunavut' && state_text != 'Ontario' && state_text != 'Puerto Rico' && state_text != 'Prince Edward Island' && state_text != 'Quebec' &&
               state_text != 'Saskatchewan' && state_text != 'Virgin Islands' && state_text != 'Yukon') {
                window.location= 'state-' + newstatestring.toLowerCase() + '.php?firstname=' + thisForm.firstname.value +
                        '&lastname=' + thisForm.lastname.value + '&salutation=' + thisForm.extrafield14.value + '&address1=' + thisForm.address1.value + '&address2=' + thisForm.address2.value +
                        '&city=' + thisForm.city.value + '&zip=' + thisForm.zip.value + '&state=' + thisForm.state.value + '&phone=' + thisForm.phone.value + '&phone2=' + thisForm.phone2.value +
                        '&email=' + thisForm.email.value + '&extrafield15=' + thisForm.extrafield15.value;
            }
        } else {
            thisForm.extrafield1[0].checked = false;
            thisForm.extrafield1[1].checked = false;
            alert('Please select your state first!');
        }
    }
}

function modality_campus() {
    thisForm = document.forms[vFormName];
	setCookie('school_type', 'C', 1 );
    if( top.location.hostname == 'accounting.topcareerschools.com'  ) {
        if( thisForm.zip.value != '' ) {
            if( parent.uop_previousid != '' ) {
                parent.changeIframe(parent.uop_previousid,'University of Phoenix');
            }
        } else {
            thisForm.extrafield1[1].checked = false;
            thisForm.extrafield1[0].checked = false;
            alert('Please enter your zip code first!');
        }
    } else {
        if( thisForm.zip.value != '' ) {
            window.location = 'search.php?firstname=' + thisForm.firstname.value +
                        '&lastname=' + thisForm.lastname.value + '&salutation=' + thisForm.extrafield14.value + '&address1=' + thisForm.address1.value + '&address2=' + thisForm.address2.value +
                        '&city=' + thisForm.city.value + '&zip=' + thisForm.zip.value + '&state=' + thisForm.state.value + '&phone=' + thisForm.phone.value + '&phone2=' + thisForm.phone2.value +
                        '&email=' + thisForm.email.value + '&extrafield15=' + thisForm.extrafield15.value;
        } else {
            thisForm.extrafield1[1].checked = false;
            thisForm.extrafield1[0].checked = false;
            alert('Please enter your zip code first!');
        }
    }
}
/*var exclude_array = new Array();
exclude_array[0] = new Array("extrafield15", "Do not have / not pursuing High School diploma", "Master","Doctoral");
exclude_array[1] = new Array("extrafield15", "Have High School Diploma / GED", "Master","Doctoral");
exclude_array[2] = new Array("extrafield15", "Completed Less than One Year Post-Secondary Education", "Master","Doctoral");
exclude_array[3] = new Array("extrafield15", "Completed 1-2 Years Post-Secondary Education", "Master","Doctoral");
exclude_array[4] = new Array("extrafield15", "Completed More than 2 Years Post-Secondary Education", "Doctoral");
exclude_array[5] = new Array("extrafield15", "Earned Bachelor's Degree", "Doctoral");

function dynamic_exclude(){
  thisForm = document.forms[vFormName];
  programs = thisForm.elements["program_key"];

  getProgram();
   
  for(var i = 0; i < exclude_array.length; i++){
    value = thisForm.elements[exclude_array[i][0]][thisForm.elements[exclude_array[i][0]].selectedIndex].text;
    if(value == exclude_array[i][1]){
      for(var j = programs.length - 1; j >= 0; j--){
        k = 2;
        done = false;
        while(k < exclude_array[i].length && !done){
          reg = new RegExp(exclude_array[i][k]);
          if( reg.test(programs[j].text) ) {
            programs[j] = null;
            done = true;
          }
          k++;
        }
      }
    }
  }
}
select distinct postedresponse, count(postedresponse) from student_client where client_id='272' and requestdate >= '2007-05-01 00:00:00' and requestdate < '2007-05-31 00:00:00' and status='N' group by postedresponse;

*/

function display_hidden(){
    var d=document.mainform;
    if( d.program_key[d.program_key.selectedIndex].value == 'SNC' || d.program_key[d.program_key.selectedIndex].value == 'BSN' || d.program_key[d.program_key.selectedIndex].value == 'MSN' || d.program_key[d.program_key.selectedIndex].value == 'MSN/ED' || d.program_key[d.program_key.selectedIndex].value == 'MSN/FNP' || d.program_key[d.program_key.selectedIndex].value == 'MSN/MBA/HC' || d.program_key[d.program_key.selectedIndex].value == 'MSN/MHA' || d.program_key[d.program_key.selectedIndex].value == 'MSN/NPFT' || d.program_key[d.program_key.selectedIndex].value == 'LPN/BSN' || d.program_key[d.program_key.selectedIndex].value == 'LVN/BSN') {
        document.getElementById("rnquestion").style.display = "block";
        vRequiredFields = '';
        vRequiredFields += 'firstname,First Name,text,';
        vRequiredFields += 'lastname,Last Name,text,';
        vRequiredFields += 'address1,Address,text,';
        vRequiredFields += 'city,City,text,';
        vRequiredFields += 'state,State,select,';
        vRequiredFields += 'zip,Zip,zip,';
        vRequiredFields += 'phone,Preferred Phone,phone,';
        vRequiredFields += 'phone2,Alternate Phone,phoneNR,';
        vRequiredFields += 'email,Email,email,';
        vRequiredFields += 'extrafield15,Highest Level of Education,select,';
        vRequiredFields += 'extrafield1,Online or Campus-based Learning,radio,';
        vRequiredFields += 'extrafield13,Area of Interest,select,';
        vRequiredFields += 'program_key,Program,select,';
        vRequiredFields += 'extrafield5,Registered Nurse License,radio,';
        vRequiredFields += 'extrafield10,US Citizen,radio,';
        vRequiredFields += 'extrafield12,Contact Me,checkbox';
    } else {
        document.getElementById("rnquestion").style.display = "none";
      	var thisForm = document.forms['mainform'];
				for( var c=0;c<thisForm.extrafield5.length;c++ )
				{
					thisForm.extrafield5[c].checked = false;
				}
        vRequiredFields = '';
        vRequiredFields += 'firstname,First Name,text,';
        vRequiredFields += 'lastname,Last Name,text,';
        vRequiredFields += 'address1,Address,text,';
        vRequiredFields += 'city,City,text,';
        vRequiredFields += 'state,State,select,';
        vRequiredFields += 'zip,Zip,zip,';
        vRequiredFields += 'phone,Preferred Phone,phone,';
        vRequiredFields += 'phone2,Alternate Phone,phoneNR,';
        vRequiredFields += 'email,Email,email,';
        vRequiredFields += 'extrafield15,Highest Level of Education,select,';
        vRequiredFields += 'extrafield1,Online or Campus-based Learning,radio,';
        vRequiredFields += 'extrafield13,Area of Interest,select,';
        vRequiredFields += 'program_key,Program,select,';
        vRequiredFields += 'extrafield10,US Citizen,radio,';
        vRequiredFields += 'extrafield12,Contact Me,checkbox';
    }
}

function checkextrafield5()
{
	var thisForm = document.forms['mainform'];

	if( thisForm.elements['extrafield5'][1].checked == true )
	{
		alert( 'Thank you for your interest. This program requires an RN license. Please select another program' );
		thisForm.program_key.value = '';
		display_hidden();
	}
}

function resetExtrafield5()
{
	var thisForm = document.forms['mainform'];
	for( var c=0;c<thisForm.extrafield5.length;c++ )
	{
		thisForm.extrafield5[c].checked = false;
	}
}

Array.prototype.in_array = function(p_val)
{
	for(var i = 0, l = this.length; i < l; i++) 
	{	
		if(this[i] == p_val) {
			return true;
		}
	}
	return false;
}

// Read a page's GET URL variables and return them as an associative array.
function getUrlVars()
{
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++)
	{
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	return vars;
}

function getCookie(NameOfCookie)
{ 
	if (document.cookie.length > 0)
	{
		begin = document.cookie.indexOf(NameOfCookie+"=");
		if (begin != -1)
		{
			begin += NameOfCookie.length+1;
			end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end));
		}
	}
	return null;
}

function delCookie (NameOfCookie)
{
	if (getCookie(NameOfCookie))
	{
		document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function check_school_type()
{
	if( getCookie('school_type') && (getCookie('school_type')=='C' || getCookie('school_type')=='O') )
	{
		var thisForm = document.forms['mainform'];

		if( getCookie('school_type')=='C' )
		{
			//CAMPUS TYPE
			for( var c=0;c<thisForm.extrafield1.length;c++ )
			{
				thisForm.extrafield1[c].checked = false;
			}
			for( var c=0;c<thisForm.extrafield1.length;c++ )
			{
				if(thisForm.extrafield1[c].value=='N')
				{
					thisForm.extrafield1[c].checked = true;
				}
			}
		}
		else
		{
			//ONLINE TYPE
			for( var c=0;c<thisForm.extrafield1.length;c++ )
			{
				thisForm.extrafield1[c].checked = false;
			}
			for( var c=0;c<thisForm.extrafield1.length;c++ )
			{
				if(thisForm.extrafield1[c].value=='Y')
				{
					thisForm.extrafield1[c].checked = true;
				}
			}
		}
	}
}
var oldonload = window.onload;
if (typeof window.onload != 'function')
{
	window.onload = check_school_type;
}
else 
{
	window.onload = function()
	{
		if (oldonload) 
		{
			oldonload();
		}
		check_school_type();
	}
}