// JavaScript Document



function displayOther(elm) {
    //if 'Other' value is selected then display the 'Other' textArea
    //alert(' elm is '+elm.name);
	
    if (elm.name == 'LangID[]'){
    	//alert('elm name is LangID[]');
        if (elm.value == 21) {
            if (document.getElementById('OtherLanguages').style.display == 'none') {
                document.getElementById('OtherLanguages').style.display = 'block'; 
                document.getElementById('OtherLanguage').value = ' ';
            } else {
                document.getElementById('OtherLanguages').style.display = 'none';
                document.getElementById('OtherLanguage').value = '';
            }
        }
    }
    
    if (elm.name == 'CompID[]') {
        if (elm.value == 33) {
            if (document.getElementById('ComputerSkillOthers').style.display == 'none') { 
            	document.getElementById('ComputerSkillOthers').style.display = 'block'; 
                document.getElementById('ComputerSkillOther').value = ' '; 
            } else {
                document.getElementById('ComputerSkillOthers').style.display = 'none';
                document.getElementById('ComputerSkillOther').value = ''; 
            }
        }
    }
    
    if (elm.name == 'SkillID[]') {
        if (elm.value == 29) {
            if (document.getElementById('OtherSkillss').style.display == 'none') { 
            	document.getElementById('OtherSkillss').style.display = 'block'; 
                document.getElementById('SpecificSkillOther').value = ' '; 
            } else {
                document.getElementById('OtherSkillss').style.display = 'none';
                document.getElementById('SpecificSkillOther').value = ''; 
            }
        }
    }
    
    if (elm.name == 'EventCatID[]') {
        if (elm.value == 13) {
            if (document.getElementById('OtherEvents').style.display == 'none') { 
            	document.getElementById('OtherEvents').style.display = 'block';
                document.getElementById('OtherEvent').value = ' '; 
            } else {
                document.getElementById('OtherEvents').style.display = 'none';
                document.getElementById('OtherEvent').value = '';
            }
        }
    }
    
    if (elm.name == 'OppCatID[]') {
        if (elm.value == 17) {
            if (document.getElementById('OtherPositions').style.display == 'none') { 
            	document.getElementById('OtherPositions').style.display = 'block'; 
                document.getElementById('OtherPosition').value = ' ';
            } else {
                document.getElementById('OtherPositions').style.display = 'none';
                document.getElementById('OtherPosition').value = '';
            }
        }
    }
    
    if (elm.name == 'EthGrp[]') {
    	EthGrpValue=elm.value;
		//if (elm.checked){
    	if (EthGrpValue.search(/other/i)!=-1) {
            if (document.getElementById('EthnicityOthers').style.display == 'none') { 
            	document.getElementById('EthnicityOthers').style.display = 'block'; 
                document.getElementById('EthnicityOther').value = ' ';
            } else {
                document.getElementById('EthnicityOthers').style.display = 'none';
                document.getElementById('EthnicityOther').value = '';
            }
        }
    }    
    
}



var i=0;
id3=null;

function swapImage(id,elm,name1) {
    //if 'Other' value is selected then display the 'Other' textArea
    //alert('swap image: id is '+id+' elm.name is '+elm.name+' name1 is '+name1);
	
    if (elm.name == 'LangID[]'){
    	//alert('elm name is LangID[]');
        if (elm.value == 21) {
            if (document.getElementById('OtherLanguages').style.display == 'none') {
                document.getElementById('OtherLanguages').style.display = 'block'; 
             }
            else {
                document.getElementById('OtherLanguages').style.display = 'none';
                document.getElementById('OtherLanguage').value = '';
            }
        }
    }
    else if (elm.name == 'CompID[]') {
        if (elm.value == 33) {
            if (document.getElementById('ComputerSkillOthers').style.display == 'none') { document.getElementById('ComputerSkillOthers').style.display = ''; }
            else {
                document.getElementById('ComputerSkillOthers').style.display = 'none';
                document.getElementById('ComputerSkillOther').value = ''; 
            }
        }
    }
    else if (elm.name == 'SkillID[]') {
        if (elm.value == 29) {
            if (document.getElementById('OtherSkills').style.display == 'none') { document.getElementById('OtherSkills').style.display = ''; }
            else {
                document.getElementById('OtherSkills').style.display = 'none';
                document.getElementById('otherskillsss').value = ''; 
            }
        }
    }
    else if (elm.name == 'EventCatID[]') {
        if (elm.value == 13) {
            if (document.getElementById('OtherEvent').style.display == 'none') { document.getElementById('OtherEvent').style.display = ''; }
            else {
                document.getElementById('OtherEvent').style.display = 'none';
                document.getElementById('otherevents').value = '';
            }
        }
    }
    else if (elm.name == 'OppCatID[]') {
        if (elm.value == 17) {
            if (document.getElementById('OtherPosition').style.display == 'none') { document.getElementById('OtherPosition').style.display = ''; }
            else {
                document.getElementById('OtherPosition').style.display = 'none';
                document.getElementById('otherpositions').value = '';
            }
        }
    }
   
swp=document.getElementById(id).src;

//alert(swp);

if(id!=id3)
{
i=0;
}
id3=id;

reee=/formJavascript1.jpg/;

	if(reee.test(swp) && i==0)
	{
		j=0;
		k=0;
	
		while(j<name1.length)
		{
	
			if(name1[j].checked)
			{
			++k;		
			}
			++j;
		}
		if(k==0)
		{
			document.getElementById(id).src = "templates/default/images/formJavascript.jpg"
			
		}						
	
	}
	else if(elm.checked == true)
	{
		i++;
		
	}
	else{
		--i;
		
			if(i==0)
				document.getElementById(id).src = "templates/default/images/formJavascript.jpg";
	}


	if(i>0)
	{
		
		   document.getElementById(id).src = "templates/default/images/formJavascript1.jpg";
	   
	}

}


var i=0;
id3=null;

function swapComp(id,elm,name1) {

swp=document.getElementById(id).src;

if(id!=id3)
{
i=0	;
}
id3=id;

re=/formJavascriptComp1.jpg/;

	if(re.test(swp) && i==0)
	{
		
	j=0;
	k=0;
	
		while(j<name1.length)
		{
	
			if(name1[j].checked)
			{
			++k;
			}
			++j;
		}
		if(k==0)
		{
			document.getElementById(id).src = "templates/default/images/formJavascriptComp.jpg";
			
		}						
	
	}
	else if(elm.checked == true)
	{
		i++;
		
	}
	else{
		--i;
		
			if(i==0)
				document.getElementById(id).src = "templates/default/images/formJavascriptComp.jpg";
	}


	if(i>0)
	{
		
		   document.getElementById(id).src = "templates/default/images/formJavascriptComp1.jpg"; 
	   
	}

}

function swapOther(id,elm,name1) {

swp=document.getElementById(id).src;

if(id!=id3)
{
i=0;	
}
id3=id;

re=/formJavascriptOther1.jpg/;

	if(re.test(swp) && i==0)
	{
		
	j=0;
	k=0;
	
		while(j<name1.length)
		{
	
			if(name1[j].checked)
			{
			++k	;	
			}
			++j;
		}
		if(k==0)
		{
			document.getElementById(id).src = "templates/default/images/formJavascriptOther.jpg";
			
		}						
	
	}
	else if(elm.checked == true)
	{
		i++;
		
	}
	else{
		--i;
		
			if(i==0)
				document.getElementById(id).src = "templates/default/images/formJavascriptOther.jpg";
	}


	if(i>0)
	{
		
		   document.getElementById(id).src = "templates/default/images/formJavascriptOther1.jpg"; 
	   
	}

}



function search_swapImage(id,elm,name1) 
{
	
swp=document.getElementById(id).src;
	if(id!=id3)
	{
		i=0;	
	}
id3=id

re=/formJavascriptplease1.jpg/

	if(re.test(swp) && i==0)
	{
		
	j=0;
	k=0;
	
		while(j<name1.length)
		{
	
			if(name1[j].checked)
			{
			++k	;	
			}
			++j;
		}
		if(k==0)
		{
			document.getElementById(id).src = "templates/default/images/formJavascriptplease.jpg";
		}						
	
	}
	else if(elm.checked == true)
	{
		i++;
	}
	else{
		--i;
			if(i==0)
				document.getElementById(id).src = "templates/default/images/formJavascriptplease.jpg";
	}
	

	if(i>0)
	{
		   document.getElementById(id).src = "templates/default/images/formJavascriptplease1.jpg"; 
	   
	}
	
}



function swapImage2(id,elm,name1) {

swp=document.getElementById(id).src;

re=/formJavascript1.jpg/;

if(re.test(swp) && i==0)
{
	
j=0;
k=0;

	while(j<name1.length)
	{

		if(name1.checked)
		{
			k++;		
		}
	}
	if(k==0)
	{
		document.getElementById(id).src = "templates/default/images/formJavascript.jpg";
	}						

}
else if(elm.checked == true)
{
	i++;
}
else{
	--i;
		if(i==0)
			document.getElementById(id).src = "templates/default/images/formJavascript.jpg";
}

if(intImage==2 || i>0)
{
	   document.getElementById(id).src = "templates/default/images/formJavascript1.jpg"; 
   intImage = 1
}

}


/*function swapImage(id,elm) 
{



	swp=document.getElementById(id).src
	re=/formJavascript1.jpg/
	if(re.test(swp) && i==0)
	{
		document.getElementById(id).src = "templates/default/images/formJavascript.jpg"
		
	}
	else if(elm.checked == true)
	{
	i++;
	}
	else{
	--i;
		if(i==0)
			document.getElementById(id).src = "templates/default/images/formJavascript.jpg"
	}
	if(intImage==2 || i>0)
	{
	   document.getElementById(id).src = "templates/default/images/formJavascript1.jpg"
	   intImage = 1
	}

}
*/


/*function swapImageupdate(id,elm) {
	if(elm.checked == true)
	{
	i++;
	}
	else{
	--i;
	
		if(i<0)
			document.getElementById(id).src = "formJavascript.jpg"
	}
	if(i>=0)
	{
	   document.getElementById(id).src = "formJavascript1.jpg" 
	}
}*/
var map = null;
//var geocoder = null;
function initializeGmap(lat,lng) {
	try {
		if (GBrowserIsCompatible()) {
		   map = new GMap2(document.getElementById("map_canvas"));
		   var latlng = new GLatLng(lat,lng);
		   map.setCenter(latlng, 13);
		   //geocoder = new GClientGeocoder();
		   marker = new GMarker(latlng);
		   map.addOverlay(marker);
		}	
	}
	catch(e){}

}

function newInitializeGmap(href) {
  var latlng = null;
  var llIndex = href.indexOf("&ll=");
  if (llIndex==-1){
    llIndex = href.indexOf(";ll=");
  } 
  if (llIndex > -1) {
      llIndex+=4;
      var llEndIndex = href.indexOf("&",llIndex);
      if (llEndIndex==-1) {llEndIndex=href.length;}
      ll=href.substring(llIndex, llEndIndex);
      comma=ll.indexOf(",");
      lat=ll.substring(0,comma)*1;
      lng=ll.substring(comma+1)*1;
      latlng = new GLatLng(lat,lng);
  } else {
      var qIndex = href.indexOf("&q=");
      if (qIndex==-1) {
        qIndex = href.indexOf(";q=");
      }
      if (qIndex>-1) {
        qIndex+=3;
        var qEndIndex=href.indexOf("&",qIndex);
        if (qEndIndex==-1) {qEndIndex=href.length;}
        var q=href.substring(qIndex, qEndIndex);
      
//      alert("q = "+q);
        var geocoder = new GClientGeocoder();
        geocoder.getLatLng(q, function(glatlong) {
          latlng = glatlong;
//        alert("setting latlng to "+latlng);
          if (latlng!=null) {
            showGmap(latlng);
          }
        });
       
      }
  }
  if (latlng!=null) {
//    alert("latlng from ll is "+latlng);
    showGmap(latlng);
  }
}

function showGmap(latlng) {
//alert("showGmap with "+latlng);
  if (latlng!=null) {
    try {
      if (GBrowserIsCompatible()) {
         map = new GMap2(document.getElementById("map_canvas"));
         map.setCenter(latlng, 13);
         marker = new GMarker(latlng);
         map.addOverlay(marker);
      }
    }
    catch(e){}   
  } 
}



function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function showAddress(address) {
   if (geocoder) {
      geocoder.getLatLng(
      address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
              map.setCenter(point, 13);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              //marker.openInfoWindowHtml(address);
            }
          }
        );
      }
    }
function downme(id) {
	//alert(id);
	Effect.SlideDown(id, {duration:1.0}); return false;
	//document.getElementById(id).style.display = "none";
	//alert(id);
	//return false;	
}

function results_per_page(val) {
		
		if(document.getElementById('current_url').value.indexOf('?') > 0 )
			loc = document.getElementById('current_url').value + '&show=' + val.value;
		else
			loc = document.getElementById('current_url').value + '?show=' + val.value;

		document.location.href = loc;
}
function search_event(val) {
	
		var hash = getUrlVars();
		alert(hash['show']);
		if(document.getElementById('current_url').value.indexOf('?') > 0 )
			loc = document.getElementById('current_url').value + '&q=' + document.getElementById('key').value;
		else
			loc = document.getElementById('current_url').value + '?q=' + document.getElementById('key').value;

		document.location.href = loc;

}
function confirmation(id,title) {
	var answer = confirm("Delete entry "+title+" ?")
	if (answer){
		alert("Entry Deleted")
		window.location = "admin_cms_news.php?del="+id;
	}
	else{
		alert("No action taken")
	}
//Added by Brendan on Nov 19 to delete featured volunteers.	
}
function confm(url,id) {
	var answer = confirm("Delete entry ? ")
	if (answer){
		alert("Entry Deleted")
		window.location=url+"&Del="+id;
		//document.form1.submit();
		return true;
	}
	else{
		
		alert("No action taken")
		return false;
	}
//Added by Brendan on Nov 19 to delete featured volunteers.	
}
function confirmationNews(id,title) {
	var answer = confirm("Delete entry "+title+" ?")
	if (answer){
		alert("Entry Deleted")
		window.location = "admin_featuredVolunteers.php?del="+id;
	}
	else{
		alert("No action taken")
	}
}
function getUrlVars()
{    

	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');     
	alert(hashes);
	for(var i = 0; i < hashes.length; i++)   
	{ 
		hash = hashes[i].split('=');
		vars.push(hash[0]); 
		vars[hash[0]] = hash[1];   
	} return vars;
}
function delVol(id,name) {
	var answer = confirm("Delete entry " + name + " ?");
	if (answer){
		alert("Entry Deleted")
		window.location = "admin_manage_volunteers.php?del="+id;
	}
	else{
		alert("No action taken")
	}
}

function confirmation_region(id,title,ProvID) {
	var answer = confirm("Delete "+title+" ?")
	if (answer){
		alert("Region Deleted")
		window.location = "admin_region.php?del="+id+"&ProvID="+ProvID;
	}
	else{
		alert("No action taken")
	}
}

function confirmation_export(confrm,url)
{
	//alert(title)
	
		var answer = confirm(confrm)
	if (answer){
				window.location =url;		
	}
	
}
function confirmation_common(confrm,after,decl,id,title)
{
	//alert(title)
	
		var answer = confirm(confrm+" "+title+" ?")
	if (answer){
		//alert(title+" "+after)
		l=window.location.href;
		if(l.indexOf('?') > 0)
			window.location = window.location.href+"&"+decl+"="+id;
		else
			window.location = window.location.href+"?"+decl+"="+id;
		
	}
	else{
		//alert("No action taken")
		}
}
function sortNewsVar(val,form){
	if (document.getElementById(val).value=='ASC')
		document.getElementById(val).value='DESC';
	else
		document.getElementById(val).value='ASC';
	
	
	document.getElementById(form).submit();
}
function sortVar(val,form){
		
	if (document.getElementById(val).value=='ASC')
		document.getElementById(val).value='DESC';
	else
		document.getElementById(val).value='ASC';
	
	
	document.getElementById(form).submit();
}
//func for sorting
function sortevelist(tit,val1,form1){
		
	if (document.getElementById(val1).value=='ASC')
		document.getElementById(val1).value='DESC';
	else
		document.getElementById(val1).value='ASC';
	
	
	document.getElementById('sorteve').value=tit;

	document.getElementById(form1).submit();
}

function confirm_details(id,id1,stat)
{
	//alert(stat)
	
		var answer = confirm("confirm position deletion ?")
	if (answer){
		alert("Position deleted")
		
		window.location = window.location.href+"&PosID="+id+"&stat="+stat+"&EventID="+id1;
		//alert(window.location)
	}
	else{
		alert("No action taken")
		}
}

// SWAP IMAGE ON ROLOVER
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function hide() {
var browserType;

if (document.layers) {browserType = "nn4"}
if (document.all) {browserType = "ie"}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {
   browserType= "gecko"
}
	
	
  if (browserType == "gecko" )
     document.poppedLayer = 
         eval('document.getElementById("aBox")');
  else if (browserType == "ie")
     document.poppedLayer = 
        eval('document.getElementById("aBox")');
  else
     document.poppedLayer =   
        eval('document.getElementById("aBox")');
  document.poppedLayer.style.visibility = "inline";
}


function HideContent(d) {
	
	document.getElementById(d).style.display = "none";
	document.getElementById('alert').value=1;
	document.form1.submit();
}
function ShowContent(d) {
	
document.getElementById(d).style.display = "block";
}
function reapproval(re,rid)
{
	var1=document.getElementById(rid).value;
	if(re==var1)
	{
		document.getElementById('reapp').value='';
	}
	else
	{
		document.getElementById('reapp').value=1;
	}
}

function opennewsletter(){
	emailwindow=dhtmlmodal.open('EmailBox', 'iframe', 'test.php', 'Newsletter Signup page', 'width=350px,height=200px,center=1,resize=0,scrolling=1')


} //End "opennewsletter" function
function clearSearch(url){
	
	sp=document.location.href.split("?");alert(sp[0]);
window.location= sp[0];	
}
function doGeocode(address, details) {

	// function provided by geoquo.js
	
	xmlhttp=null
  // code for Mozilla, etc.
var request = GeoQuo.createXMLHttpRequest();
	var url = GeoQuo.getURL(address);
 if (request.overrideMimeType) {
                request.overrideMimeType('text/xml');
                // See note below about this line
            }
	

	request.open("GET", url, true);

	request.onreadystatechange = function() {

		if (request.readyState == 4) {
			if (request.status == 200) {

				// GeoQuo helper class. Provided by geoquo.js
				var result = new GeoQuo(request.responseXML);

				if (result.success()) {
					var lat = result.getLat();
					var lon = result.getLon();

					// your additional logic to handle the returned coordinate.
					initializeGmap(lat + ' ' + lon, details);

				} else {

					// do something to handle failure
					if (result.getErrorCode() == 101)
					alert();
				}
			}
		}
	}
	
	request.send(null);
	
}
function showreason(dd,rediv)
{
	if(dd==5)
	{
		document.getElementById(rediv).style.display = "block";		
	}
	else 
	{
		document.getElementById(rediv).style.display = "none";
	}
	if(rediv!='')
	{
		//document.getElementById(dd).style.display = "none";	
		document.getElementById(rediv).style.display = "block";
	}
	if(dd==1)
	{
		document.getElementById(rediv).style.display = "none";
	}
	//document.getElementById(d).style.display = "none";
}

function ScrollToSoon(theElement) {
	  var selectedPosX = 0;
	  var selectedPosY = 0;
	              
	  while(theElement != null){
	    selectedPosX += theElement.offsetLeft;
	    selectedPosY += theElement.offsetTop;
	    theElement = theElement.offsetParent;
	  }
 	 window.scrollTo(selectedPosX,selectedPosY);	
}

function ScrollToElement(theElement){
  setTimeout(function(){ScrollToSoon(theElement)}, 150);
}


function showreasonfocus(dd,rediv,field)
{
	if(dd==5)
	{
		document.getElementById(rediv).style.display = "block";		
	}
	else 
	{
		document.getElementById(rediv).style.display = "none";
	}
	if(rediv!='')
	{
		//document.getElementById(dd).style.display = "none";	
		document.getElementById(rediv).style.display = "block";
	}
	if(dd==1)
	{
		document.getElementById(rediv).style.display = "none";
	}
	//document.getElementById(d).style.display = "none";
	if (field!='') {
		field.focus();
	}	
}

function counterUpdate(opt_countedTextBox,opt_maxSize) {
        var countedTextBox = opt_countedTextBox ;
        
        var maxSize = opt_maxSize;

        var field = document.getElementById(countedTextBox);

        if (field && field.value.length >= maxSize) {
                field.value = field.value.substring(0, maxSize);
        }
       
}
function org_dash(locate,id){
window.location=locate+".php?decline="+id;	
}

function CheckAll(chk){
	for (var i=0;i < document.findvolunteers.elements.length;i++){
		var e = document.findvolunteers.elements[i];
		if (e.type == "checkbox"){
			if(e.getAttribute("class")=="check_input"){
				e.checked = chk.checked;
			}
		}
	}
}
