var handle;
window.onload = function() 
{ 
	adjustHeight();
	handle = window.setInterval(replaceButton, 1);
}
function replaceButton()
{
	var objs = getElementsByClass("gsc-search-button");
	if(objs.length > 0)
	{
		for(var i = 0; i < objs.length; i++)
		{
			if(objs[i].tagName == "INPUT")
			{			
				window.clearInterval(handle);
				
				try
				{
					objs[i].setAttribute("type","image");
					objs[i].setAttribute("src","images/search_button.gif");
				}
				catch(e)
				{
					var parent = objs[i].parentNode;
					parent.removeChild(objs[i]);
					var input = document.createElement("INPUT");
					input.setAttribute("type","image");
					input.setAttribute("src","images/search_button.gif");
					input.setAttribute("class","gsc-search-button");
					input.setAttribute("value","Search");
					input.setAttribute("title","search");
					parent.appendChild(input);
				}
								
								
			}
		}
	}
}

var h = window.setInterval(adjustHeight,1000); 

function adjustHeight()
{
	if(document.getElementById('content_container'))
	{
		document.getElementById('content_container').style.height = document.getElementById('s_main_content').offsetHeight + 'px'
	}
}
function InsertFlashMovie1()
{
  document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="904" height="387"><param name="movie" value="flash/NCIRE_2009header_01.swf"><param name="quality" value="high"><EMBED SRC="flash/NCIRE_2009header_01.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"  WIDTH="904" HEIGHT="387" WMODE="TRANSPARENT" MENU="FALSE" BGCOLOR="WHITE"></EMBED></object>');
}
function InsertFlashMovie2()
{
  document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="904" height="387"><param name="movie" value="flash/NCIRE_08header_02_06.swf"><param name="quality" value="high"><EMBED SRC="flash/NCIRE_08header_02_06.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"  WIDTH="904" HEIGHT="387" WMODE="TRANSPARENT" MENU="FALSE" BGCOLOR="WHITE"></EMBED></object>');
}
function InsertFlashMovie3()
{
  document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="904" height="387"><param name="movie" value="flash/NCIRE_08header_03_05.swf"><param name="quality" value="high"><EMBED SRC="flash/NCIRE_08header_03_05.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"  WIDTH="904" HEIGHT="387" WMODE="TRANSPARENT" MENU="FALSE" BGCOLOR="WHITE"></EMBED></object>');
}
function InsertFlashMovieLogo()
{
  document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="187" height="147"><param name="movie" value="flash/ncire_logo.swf"><param name="quality" value="high"><EMBED SRC="flash/ncire_logo.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"  WIDTH="187" HEIGHT="147" WMODE="TRANSPARENT" MENU="FALSE" BGCOLOR="WHITE"></EMBED></object>');
}

/*
function InsertFlashMovie4()
{
  document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="904" height="387"><param name="movie" value="flash/NCIRE_08header_01_03.swf"><param name="quality" value="high"><EMBED SRC="flash/NCIRE_08header_01_03.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"  WIDTH="904" HEIGHT="387" WMODE="TRANSPARENT" MENU="FALSE" BGCOLOR="WHITE"></EMBED></object>');
}
*/

function InsertFlashMovie4()
{
  document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="904" height="387"><param name="movie" value="flash/NCIRE_08header_02_03.swf"><param name="quality" value="high"><EMBED SRC="flash/NCIRE_08header_02_03.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"  WIDTH="904" HEIGHT="387" WMODE="TRANSPARENT" MENU="FALSE" BGCOLOR="WHITE"></EMBED></object>');
}

function InsertFlashMovie5()
{
  document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="904" height="387"><param name="movie" value="flash/NCIRE_08header_02_01.swf"><param name="quality" value="high"><EMBED SRC="flash/NCIRE_08header_02_01.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"  WIDTH="904" HEIGHT="387" WMODE="TRANSPARENT" MENU="FALSE" BGCOLOR="WHITE"></EMBED></object>');
}

function InsertFlashMovie6()
{
  document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="904" height="387"><param name="movie" value="flash/NCIRE_08header_03_02.swf"><param name="quality" value="high"><EMBED SRC="flash/NCIRE_08header_03_02.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"  WIDTH="904" HEIGHT="387" WMODE="TRANSPARENT" MENU="FALSE" BGCOLOR="WHITE"></EMBED></object>');
}

function InsertFlashMovie7()
{
  document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="904" height="387"><param name="movie" value="flash/NCIRE_08header_02_07.swf"><param name="quality" value="high"><EMBED SRC="flash/NCIRE_08header_02_07.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"  WIDTH="904" HEIGHT="387" WMODE="TRANSPARENT" MENU="FALSE" BGCOLOR="WHITE"></EMBED></object>');
}

function insertMovie(src, width, height)
{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+width+'" height="'+height+'"  >');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="'+src+'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="bgcolor" value="#ffffff" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<embed src="'+src+'" wmode="transparent" quality="high" bgcolor="#ffffff" width="'+width+'" height="'+height+'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}
function rollover(img,on)
{		  
	off = img.src;
	offfull = img.src;
	onfull = on;
	path = off.substring(0,off.lastIndexOf('/')+1); 
	onfull = path + onfull;
	//alert(onfull);
	if(off.lastIndexOf('/') != -1) // if there is a path, strip it
		{
			 off = off.substring(off.lastIndexOf('/')+1);
		}
	if(on.lastIndexOf('/') != -1) // if there is a path, strip it
		{
			 on = on.substring(on.lastIndexOf('/')+1);
		}
	if(on != off)
		{		  
      off_ex = off.substring(off.lastIndexOf('.')) // extract extension     
			off = off.substring(0,off.lastIndexOf('.')); //strip extension	       		
      on_ex = on.substring(on.lastIndexOf('.')) // extract extension     
			on = on.substring(0,on.lastIndexOf('.')); //strip extension			      		
			eval(off + " = new Image(); ");						 
			eval(off + ".src = '" + offfull +"'");			
			eval(on + " = new Image(); ");			
			eval(on + ".src = '" + onfull +"'");
			var image_on = eval(on + ".src");
			var image_off = eval(off + ".src");
			img.onmouseover = function() { img.src = image_on;}
			img.onmouseout = function() { img.src = image_off;}
		}
}


function expand(divID){
	img = document.getElementById("expand_" + divID);
	img.src = img.src.substr(img.src.lastIndexOf("/")+1) == "expand_plus.gif" ? "images/expand_minus.gif" : "images/expand_plus.gif";
	box = document.getElementById(divID);
	box.style.display = box.style.display != "block" ? "block" : "none";
	document.getElementById('content_container').style.height = document.getElementById('s_main_content').offsetHeight + "px";
}

function compare_expand(divID){
	img = document.getElementById("expand_" + divID + "1");
	img.src = img.src.substr(img.src.lastIndexOf("/")+1) == "expand_plus.gif" ? "images/expand_minus.gif" : "images/expand_plus.gif";
	box = document.getElementById(divID + "1");
	box.style.display = box.style.display == "none" ? "block" : "none";
	
	img = document.getElementById("expand_" + divID + "2");
	img.src = img.src.substr(img.src.lastIndexOf("/")+1) == "expand_plus.gif" ? "images/expand_minus.gif" : "images/expand_plus.gif";
	box = document.getElementById(divID + "2");
	box.style.display = box.style.display == "none" ? "block" : "none";
	
	img = document.getElementById("expand_" + divID + "3");
	img.src = img.src.substr(img.src.lastIndexOf("/")+1) == "expand_plus.gif" ? "images/expand_minus.gif" : "images/expand_plus.gif";
	box = document.getElementById(divID + "3");
	box.style.display = box.style.display == "none" ? "block" : "none";
	
	img = document.getElementById("expand_" + divID + "4");
	img.src = img.src.substr(img.src.lastIndexOf("/")+1) == "expand_plus.gif" ? "images/expand_minus.gif" : "images/expand_plus.gif";
	box = document.getElementById(divID + "4");
	box.style.display = box.style.display == "none" ? "block" : "none";
}
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function expand2(divID){
	img = document.getElementById("expand_" + divID);
	img.src = img.src.substr(img.src.lastIndexOf("/")+1) == "expand_plus.gif" ? "images/expand_minus.gif" : "images/expand_plus.gif";
	box = document.getElementById(divID);
	box.style.display = box.style.display != "block" ? "block" : "none";
			//document.getElementById('content_container').style.height = document.getElementById('s_main_content').offsetHeight + "px";
}

function check_registration_salutation(elm){
	if(elm.value == 'Other'){
		document.getElementById('salutation_other_div').style.display = "block";
	}else{
		document.getElementById('salutation_other_div').style.display = "none";
	}
}

function check_registration_degree(elm){
	if(elm.value == 'Other'){
		document.getElementById('degree_other_div').style.display = "block";
	}else{
		document.getElementById('degree_other_div').style.display = "none";
	}
}
        
function change_pic(image, content){
	document.getElementById('imageholder').innerHTML = '<img src="' + image + '">';
	document.getElementById('textholder').innerHTML = content;
}

function submit_donate_form(){
	document.donate_form.submit();
}

function hide_billing(){
	if(document.getElementById('billing_info').style.display == "none"){
		document.getElementById('billing_info').style.display = "block";
	}else{
		document.getElementById('billing_info').style.display = "none";
	}
}

function show_other(){
	if(document.getElementById('otherstate').style.display == "none"){
		document.getElementById('otherstate').style.display = "block";
	}else{
		document.getElementById('otherstate').style.display = "none";
	}
}

function show_billing_other(){
	if(document.getElementById('otherbillingstate').style.display == "none"){
		document.getElementById('otherbillingstate').style.display = "block";
	}else{
		document.getElementById('otherbillingstate').style.display = "none";
	}
}

function show_amount_other(){
	document.getElementById('otheramount').style.display = "inline";
	document.donate_form.amount[0].checked = false;
	document.donate_form.amount[1].checked = false;
	document.donate_form.amount[2].checked = false;
	document.donate_form.amount[3].checked = false;
	document.donate_form.amount[4].checked = false;
	document.donate_form.amount[5].checked = false;
}

function hide_amount_other(){
	document.getElementById('otheramount').style.display = "none";
	document.donate_form.amountother.checked = false;
}

function validate_donate_form() {
	
	errors = 0;
	first_name = document.getElementById("first_name").value;
	last_name = document.getElementById("last_name").value;
	address = document.getElementById("address").value;
	city = document.getElementById("city").value;
	selectedstate = document.getElementById('state').selectedIndex;
	state = document.getElementById('state')[selectedstate].value;
	zip = document.getElementById("zip").value;
	selectedcountry = document.getElementById('country').selectedIndex;
	country = document.getElementById('country')[selectedcountry].value;
	email = document.getElementById("email").value;
	phone = document.getElementById("phone").value;
	card_name = document.getElementById("card_name").value;
	card_number = document.getElementById("card_number").value;
	security = document.getElementById("security").value;
	expiration_month = document.getElementById("expiration_month").value;
	expiration_year = document.getElementById("expiration_year").value;
	billing_address = document.getElementById("billing_address").value;
	billing_city = document.getElementById("billing_city").value;
	billing_state = document.getElementById("billing_state").value;
	billing_country = document.getElementById("billing_country").value;
	billing_zip = document.getElementById("billing_zip").value;
	otheramount = document.getElementById("otheramount").value;
	if(document.donate_form.amountother.checked){
		amountother = "true";
	}else{
		amountother = "false";
	}

	amount = "";
	if(document.donate_form.amount[0].checked){
		amount = document.donate_form.amount[0].value;
	}
	if(document.donate_form.amount[1].checked){
		amount = document.donate_form.amount[1].value;
	}
	if(document.donate_form.amount[2].checked){
		amount = document.donate_form.amount[2].value;
	}
	if(document.donate_form.amount[3].checked){
		amount = document.donate_form.amount[3].value;
	}
	if(document.donate_form.amount[4].checked){
		amount = document.donate_form.amount[4].value;
	}
	if(document.donate_form.amount[5].checked){
		amount = document.donate_form.amount[5].value;
	}

	if(document.donate_form.othercheck.checked){
		othercheck = "true";
	}else{
		othercheck = "false";
	}
	other = document.getElementById("other").value;
	
	if(document.donate_form.otherbillingcheck.checked){
		otherbillingcheck = "true";
	}else{
		otherbillingcheck = "false";
	}
	billingother = document.getElementById("billingother").value;
	
	if(document.donate_form.sameinfo.checked){
		sameinfo = "true";
	}else{
		sameinfo = "false";
	}
	
	
	donate_hideAllErrors();
	
	if(amountother == "true"){
    	if(otheramount == ""){
    		document.getElementById("amount_error").style.display = "block";
	        document.getElementById("amountother").focus();
	        errors = 1;
    	}
    }else{
	    if (amount == "") {
	        document.getElementById("amount_error").style.display = "block";
	        errors = 1;
	    }
    }
	
    if (email == "") {    	
        document.getElementById("email_error").style.display = "block";
        document.getElementById("email").focus();
        errors = 1;
    }
    
	if((email != "") && (!IsEmail(email))){					
	  	document.getElementById("email_invalid").style.display = "block";
	  	document.getElementById("email").focus();	  	
	  	errors = 1;				  	  		  	
	}
	
    if (first_name == "") {
        document.getElementById("first_name_error").style.display = "block";
        document.getElementById("first_name").focus();
        errors = 1;
    }

    if (last_name == "") {
        document.getElementById("last_name_error").style.display = "block";
        document.getElementById("last_name").focus();
        errors = 1;
    }
    
    if (address == "") {
        document.getElementById("address_error").style.display = "block";
        document.getElementById("address").focus();
        errors = 1;
    }
    
    if (city == "") {
        document.getElementById("city_error").style.display = "block";
        document.getElementById("city").focus();
        errors = 1;
    }
    
    if(othercheck == "true"){
    	if((other == "") || (other == "Enter State/Province Here")){
    		document.getElementById("state_error").style.display = "block";
	        document.getElementById("state").focus();
	        errors = 1;
    	}
    }else{
	    if (state == "") {
	        document.getElementById("state_error").style.display = "block";
	        document.getElementById("state").focus();
	        errors = 1;
	    }
    }
    
    if (country == "") {
        document.getElementById("country_error").style.display = "block";
        document.getElementById("country").focus();
        errors = 1;
    }
    if (zip == "") {
        document.getElementById("zip_error").style.display = "block";
        document.getElementById("zip").focus();
        errors = 1;
    }
    if (phone == "") {
        document.getElementById("phone_error").style.display = "block";
        document.getElementById("phone").focus();
        errors = 1;
    }
    if (card_name == "") {
        document.getElementById("card_name_error").style.display = "block";
        document.getElementById("card_name").focus();
        errors = 1;
    }
    if (card_number == "") {
        document.getElementById("card_number_error").style.display = "block";
        document.getElementById("card_number").focus();
        errors = 1;
    }
    if (security == "") {
        document.getElementById("security_error").style.display = "block";
        document.getElementById("security").focus();
        errors = 1;
    }
    if (expiration_month == "") {
        document.getElementById("expiration_error").style.display = "block";
        document.getElementById("expiration_month").focus();
        errors = 1;
    }
    if (expiration_year == "") {
        document.getElementById("expiration_error").style.display = "block";
        document.getElementById("expiration_year").focus();
        errors = 1;
    }
    if(sameinfo == "false"){
    	if (billing_address == "") {
	        document.getElementById("billing_address_error").style.display = "block";
	        document.getElementById("billing_address").focus();
	        errors = 1;
	    }
	    if (billing_city == "") {
	        document.getElementById("billing_city_error").style.display = "block";
	        document.getElementById("billing_city").focus();
	        errors = 1;
	    }
	    if(otherbillingcheck == "true"){
	    	if((billingother == "") || (billingother == "Enter State/Province Here")){
	    		document.getElementById("billing_state_error").style.display = "block";
		        document.getElementById("billingother").focus();
		        errors = 1;
	    	}
	    }else{
		    if (billing_state == "") {
		        document.getElementById("billing_state_error").style.display = "block";
		        document.getElementById("billing_state").focus();
		        errors = 1;
		    }
	    }
	    if (billing_country == "") {
	        document.getElementById("billing_country_error").style.display = "block";
	        document.getElementById("billing_country").focus();
	        errors = 1;
	    }
	    if (billing_zip == "") {
	        document.getElementById("billing_zip_error").style.display = "block";
	        document.getElementById("billing_zip").focus();
	        errors = 1;
	    }
    }
	if(errors == 0){
		document.donate_form.submit();
	}
}

function donate_hideAllErrors() {
	
    document.getElementById("first_name_error").style.display = "none";
    document.getElementById("last_name_error").style.display = "none";
    document.getElementById("address_error").style.display = "none";
    document.getElementById("country_error").style.display = "none";
    document.getElementById("state_error").style.display = "none";
    document.getElementById("city_error").style.display = "none";
    document.getElementById("zip_error").style.display = "none";
    document.getElementById("email_error").style.display = "none";
    document.getElementById("email_invalid").style.display = "none";
    document.getElementById("phone_error").style.display = "none";
    document.getElementById("card_name_error").style.display = "none";
    document.getElementById("card_number_error").style.display = "none";
    document.getElementById("security_error").style.display = "none";
    document.getElementById("expiration_error").style.display = "none";
    document.getElementById("billing_address_error").style.display = "none";
    document.getElementById("billing_city_error").style.display = "none";
    document.getElementById("billing_state_error").style.display = "none";
    document.getElementById("billing_country_error").style.display = "none";
    document.getElementById("billing_zip_error").style.display = "none";
    document.getElementById("amount_error").style.display = "none";
}

//Email Validator
function IsEmail(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	
	if (str.indexOf(at)==-1){
	   return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false
	}
	if (str.indexOf(at,(lat+1))!=-1){
	    return false
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false
	}
	if (str.indexOf(dot,(lat+2))==-1){
	    return false
	}
	if (str.indexOf(" ")!=-1){
	    return false
	}
	return true
}