currm = "";
menus = new Array( "about", "activities" , "join" , "awards" , "coe" , "publications" , "resources"  );
hmen = "";
var openID,closeID,mid;

function changeButton( over, b1 , b2 , nomenu )
{
	if( nomenu ) b1.src = "images/buttons/" + b2 + ".gif";
	else b1.src = "images/buttons2/" + b2 + ".gif";
	
	
	if( !nomenu )
	{
		var tmp = b2.substr( 0 , b2.indexOf( "_" ) );

		var bi = document.getElementById( tmp );
		
		
		if( bi ) 
		{
			mid = bi;
			clearInterval( openID );
			clearInterval( closeID );
			if( over ) 
			{
				hideMenus();
				openID = setInterval( doShow , 300 );
			}
			else closeID = setInterval( doHide , 700 );
		}
		//bi.style.display = "block";
	} 
}

function doShow()
{
	clearInterval( openID );
	
//	hmen = "";
//	var m;
//	m = document.getElementById( mid );
//	if( m.style.display == "block" ) return;
	
//	hideMenus();
	
//	m.style.display = "block";
	mid.style.display = "block";
}

function doHide()
{
	clearInterval( closeID );
	hideMenus();
}

function stopHide()
{
	clearInterval( closeID );
}

function resumeHide()
{
	closeID = setInterval( doHide , 700 );
}

function hideMenus()
{
	for( var i = 0; i < menus.length; i++ )
	{
		m = document.getElementById( menus[i] );
		m.style.display= "none"
	}
}


function hideMenuTimeout( men )
{
	hmen = men;
	
	setTimeout( hideM , 300 );
}

function hideM()
{

	if( hmen != "" )
	{
		document.getElementById(hmen).style.display="none";
		hmen = "";
	}
}

function hideSideMenu()
{
	document.getElementById( "sidemenu" ).style.display="none";
	var d = document.getElementById( "dnl_menu" );
	if( d ) d.style.display="none";
	document.getElementById( "showmenu" ).style.display="block";
}

function showSideMenu()
{
	document.getElementById( "sidemenu" ).style.display="block";
	var d = document.getElementById( "dnl_menu" );
	if( d ) d.style.display="block";
	document.getElementById( "showmenu" ).style.display="none";
}


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
function showSurvey()
{
	s = document.getElementById("survey");
	if( window.innerWidth )
	{
		s.style.left = window.innerWidth/2 - 120;
		s.style.top = window.innerHeight/2 - 120;
	}
	else if( document.body.clientWidth )
	{
		s.style.left = document.body.clientWidth /2 - 120;
		s.style.top = document.body.clientHeight /2 - 120;
	}
	else
	{
		s.style.left = 300;
		s.style.top = 200;
	}
	s.style.display = "block";
}
function hideSurvey()
{
	s = document.getElementById("survey");
	s.style.display = "none";
}




var linkdetails = new Array( "about-wango" , "join-wango" , "activities", "awards" , "code-of-ethics" , "resources" , "publications" , "ngo-forum" , "contact-us" , "site-map" );
var lastlink = null;
var lastimage = null;
function homeMenu( image , name , on  )
{
	/*var di;
	if( lastlink && lastlink != name )
	{
		
		di = document.getElementById( lastlink );
		di.style.display= "none";
	}*/
	
	/*for( var i in linkdetails )
	{
		di = document.getElementById( linkdetails[i] );
	//	di.style.display= "none";
	}//*/
	
	//if( on == "on" )
	{
		//if( lastimage ) lastimage.src = "images/home/"+lastlink+"-off.gif";
		//lastlink = name;
		//lastimage = image;
		//di = document.getElementById( name );
		//di.style.display = "block";
		image.src = "images/home/"+name+"-"+on+".gif";
	}
	
	
}

function cpopUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=0,width=700,height=400,left = "+(screen.width/2-350)+",top ="+(screen.height/2-200)+"');");
}

function calcTotalPayment() {
    //return;
    var oForm=document.forms[0];
	var dues = 0;
	
	if( oForm.annualFeeInd )
	{
		if( oForm.annualFeeInd[0].checked ) dues = oForm.annualFeeInd[0].value;
		else if( oForm.annualFeeInd[1].checked ) dues = oForm.annualFeeInd[1].value;
	}
	else
	{
		if( oForm.annualFee[0].checked || oForm.annualFee[3].checked || oForm.annualFee[6].checked  || oForm.annualFee[9].checked )
		{
			dues = (oForm.annualFee[0].checked) ? oForm.annualFee[0].value : (oForm.annualFee[3].checked) ? oForm.annualFee[3].value : ( oForm.annualFee[6].checked ) ? oForm.annualFee[6].value : oForm.annualFee[9].value;
			oForm.years.value = 1;
		}
		if( oForm.annualFee[1].checked || oForm.annualFee[4].checked || oForm.annualFee[7].checked  || oForm.annualFee[10].checked )
		{
			dues = (oForm.annualFee[1].checked) ? oForm.annualFee[1].value : (oForm.annualFee[4].checked) ? oForm.annualFee[4].value : ( oForm.annualFee[7].checked ) ? oForm.annualFee[7].value : oForm.annualFee[10].value;
			oForm.years.value = 2;
		}
		if( oForm.annualFee[2].checked || oForm.annualFee[5].checked || oForm.annualFee[8].checked  || oForm.annualFee[11].checked )
		{
			dues = (oForm.annualFee[2].checked) ? oForm.annualFee[2].value : (oForm.annualFee[5].checked) ? oForm.annualFee[5].value : ( oForm.annualFee[8].checked ) ? oForm.annualFee[8].value : oForm.annualFee[11].value;
			oForm.years.value = 3;
		}
	}
    
    var funds =  parseFloat(parseMoney(oForm.fund1.value)) +
         parseFloat(parseMoney(oForm.fund2.value))+
         parseFloat(parseMoney( oForm.fund3.value));

    var totPayment=dues*1+funds*1;

    layerWrite('duesDIV',formatMoney(dues));
    layerWrite('fundsDIV',formatMoney(funds));
    layerWrite('totalPaymentDIV',formatMoney(totPayment));

    //layerWrite('duesDIV','$'+dues);
    //layerWrite('fundsDIV',(funds==0) ? '-' : '$'+funds);
    //layerWrite('totalPaymentDIV','$'+totPayment);

    oForm.totalPayment.value=totPayment;
}

function layerWrite(id,text) {
     if (document.all) {
        document.all[id].innerHTML = text
     }
     else if (document.layers) {
        var lyr = document.layers[id].document;
        lyr.open();
        lyr.write(text);
        lyr.close();
     }
     else if (!document.all && document.getElementById) {
       document.getElementById(id).innerHTML = text;
     }
}

function calcTotalPaymentInd() {
    //return;
    var oForm=document.forms[0];
    var dues = (oForm.annualFee[0].checked) ? oForm.annualFee[0].value : (oForm.annualFee[1].checked) ? oForm.annualFee[1].value : oForm.annualFee[2].value;
    var funds =  parseFloat(parseMoney(oForm.fund1.value)) +
         parseFloat(parseMoney(oForm.fund2.value))+
         parseFloat(parseMoney( oForm.fund3.value));

    var totPayment=dues*1+funds*1;

    layerWrite('duesDIV',formatMoney(dues));
    layerWrite('fundsDIV',formatMoney(funds));
    layerWrite('totalPaymentDIV',formatMoney(totPayment));

    //layerWrite('duesDIV','$'+dues);
    //layerWrite('fundsDIV',(funds==0) ? '-' : '$'+funds);
    //layerWrite('totalPaymentDIV','$'+totPayment);

    oForm.totalPayment.value=totPayment;
}


function checkSearch()
{
	
	
	if( document.searchform.keyword.value.length < 2  && document.searchform.search_regionID.options[document.searchform.search_regionID.selectedIndex].value == "0" && document.searchform.search_country.options[document.searchform.search_country.selectedIndex].value == "0" && document.searchform.search_state.value == "" && document.searchform.search_city.value == "" && document.searchform.search_mission.value == "" && document.searchform.search_focus.value == "" ) 
	{
		if( document.searchform.keyword.value.length < 2 )
		{
			alert ( "Please enter at least two letters in the Organization field or fill in at least one of the other fields in the search form." );
			
		}
		else alert ( "Please fill in at least one field in the search form." );
		
		return false;
	}
	else
	{
		document.searchform.submit();
	}
	
}

function changeRegion( regID , sel )
{
	if( !regID ) regID = 0;
	if( !sel ) sel = "All Countries";
	var list = ca[regID];
	var box2 = document.searchform.search_country;
	box2.options.length = 0;
	for(i=0;i<list.length;i++)
	{
		box2.options[i] = new Option(list[i],(list[i] == "All Countries" ? "0" : list[i] ));
		if( list[i] == sel ) box2.options[i].selected = true;
	}
}

 function emailCheck(str) {
  		var err = "Please check the Email field, it seems to be invalid.";
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert(err)
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert(err)
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert(err)
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert(err)
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert(err)
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert(err)
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert(err)
		    return false
		 }

 		 return true					
}

function isAlphaNumeric(str){
  var re = /[^a-zA-Z0-9_]/g
    if (re.test(str)) return false;
  return true;
}

function nl2br( str ) 
{
    return (str + '').replace(/([^>])\n/g, '$1<br />\n');
}


function strip_tags(str, allowed_tags) {
    
    var key = '', tag = '', allowed = false;
    var matches = allowed_array = [];
    var allowed_keys = {};
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // Build allowes tags associative array
    if (allowed_tags) {
        allowed_tags  = allowed_tags.replace(/[^a-zA-Z,]+/g, '');;
        allowed_array = allowed_tags.split(',');
    }
    
    // Match tags
    matches = str.match(/(<\/?[^>]+>)/gi);
    
    // Go through all HTML tags 
    for (key in matches) {
        if (isNaN(key)) {
            // IE7 Hack
            continue;
        }
        
        // Save HTML tag
        html = matches[key].toString();
        
        // Is tag not in allowed list? Remove from str!
        allowed = false;
        
        // Go through all allowed tags
        for (k in allowed_array) {
            // Init    
            allowed_tag = allowed_array[k];
            i = -1;
            
            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+'>');}
            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+' ');}
            if (i != 0) { i = html.toLowerCase().indexOf('</'+allowed_tag)   ;}
            
            // Determine
            if (i == 0) {
                allowed = true;
                break;
            }
        }
        
        if (!allowed) {
            str = replacer(html, "", str); // Custom replace. No regexing
        }
    }
    
    return str;
}


function wordwrap( str, int_width, str_break, cut ) {
    
    var m = ((arguments.length >= 2) ? arguments[1] : 75   );
    var b = ((arguments.length >= 3) ? arguments[2] : "\n" );
    var c = ((arguments.length >= 4) ? arguments[3] : false);
    
    var i, j, l, s, r;
    
    if (m < 1) {
        return str;
    }
    
    for (i = -1, l = (r = str.split("\n")).length; ++i < l; r[i] += s) {
        for(s = r[i], r[i] = ""; s.length > m; r[i] += s.slice(0, j) + ((s = s.slice(j)).length ? b : "")){
            j = c == 2 || (j = s.slice(0, m + 1).match(/\S*(\s)?$/))[1] ? m : j.input.length - j[0].length || c == 1 && m || j.input.length + (j = s.slice(m).match(/^\S*/)).input.length;
        }
    }
    
	return r.join("\n");
}

function checkCase( field, err, checkLowercase )
{
	var ucmsg = "Please do not type in all uppercase (capital) letters.";
	var lcmsg = "Please do not type in all lowercase (small) letters.";
	
	var ediv = null;
	if( err ) ediv = document.getElementById( err );
	
	var uc = field.value.replace(/[^A-Z]/g, "").length;
	var lc = field.value.replace(/[^a-z]/g, "").length;
	
	var msg = "";
	//if(  (lc > 0 || uc > 0) && uc - lc > 10 || ( uc > 8 && lc == 0 ) ) msg = ucmsg;
	if(  uc > 8 && lc == 0  ) msg = ucmsg;
	if( (lc > 0 || uc > 0) && checkLowercase && field.value == field.value.toLowerCase() ) msg = lcmsg;
	
	if( msg != "" )
	{
		if( ediv ) 
		{
			ediv.innerHTML = msg;
			ediv.style.display = "block";
		}
		else alert( msg );
	}
	else
	{
		if( ediv ) ediv.style.display = "none";
	}
}

