// JavaScript Document
//SDRM Website


//------------------- Son-Of-Sucker-Fish IE Hack -------------------//

sfHover = function() {
          var sfEls = document.getElementById("nav").getElementsByTagName("li");
          // for each list item in the menu...
          for (var i=0; i < sfEls.length; i++) {
                   // Is this IE7?  If so, use onmouseleave to fix the fact that onmouseout won't fire
                   is_IE7 = navigator.appVersion.indexOf("MSIE 7.0") != -1;
                   sfEls[i].onmouseover = function() {
                             this.className+=" sfHover";
                             // is this a top-level menu item?
                             var child_ul = this.getElementsByTagName('ul')[0];
                             if (child_ul && is_IE7){
                                      // fix for IE7
                                      child_ul.style.position = 'static';
                             }
                   }
                   sfEls[i].onmouseleave = function() {
                             // is this a top-level menu item?
                             var child_ul = this.getElementsByTagName('ul')[0];
                             if (child_ul && is_IE7){
                                      // fix for IE7
                                      child_ul.style.position = 'absolute';
                                      child_ul.style.left = '-9000px';
                             }
                   }
                   sfEls[i].onmouseout = function() {
                             this.className=this.className.replace(new RegExp(" sfHover\\b"), "");
                   }
          }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);





<!-- Gracefully hide from old browsers DATE DISPLAY
var this_weekday_name_array = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")	//predefine weekday names
var this_month_name_array = new Array("January","February","March","April","May","June","July","August","September","October","November","December")	//predefine month names

var this_date_timestamp=new Date()	//get current day-time stamp

var this_weekday = this_date_timestamp.getDay()	//extract weekday
var this_date = this_date_timestamp.getDate()	//extract day of month
var this_month = this_date_timestamp.getMonth()	//extract month
var this_year = this_date_timestamp.getYear()	//extract year

if (this_year < 1000)
	this_year+= 1900;	//fix Y2K problem
if (this_year==101)
	this_year=2001;		//fix Netscape browsers - it displays the year as being the year 101!

var this_date_string = this_weekday_name_array[this_weekday] + ", " + this_month_name_array[this_month] + " " + this_date + ", " + this_year	//concat long date string
// -->






// Hide Email Addresses from Harvesters
function hideaddy(em1, em2) {
if (em1 && em2) {
document.write('<a href=\"mailto:' + em1 + '@' + em2 +'.org\">' + em1 + '@' + em2 + '.org</a>');
} else {
document.write(' -- No email address supplied -- ');
}
}

<!-- The following script is based on the javascript code of Roman Feldblum (web.developer@programmer.net) -->
<!-- Original script : http://javascript.internet.com/forms/format-phone-number.html -->
<!-- Original script is revised by Eralper Yilmaz (http://www.eralper.com) -->
<!-- Revised script : http://www.kodyaz.com -->
<!-- Format : "(123) 456-7890" -->
<!-- added 2/5/2010

var zChar = new Array(' ', '(', ')', '-', '.');
var maxphonelength = 14;
var phonevalue1;
var phonevalue2;
var cursorposition;

function ParseForNumber1(object){
  phonevalue1 = ParseChar(object.value, zChar);
}

function ParseForNumber2(object){
  phonevalue2 = ParseChar(object.value, zChar);
}

function backspacerUP(object,e) { 
  if(e){ 
    e = e 
  } else {
    e = window.event 
  } 
  if(e.which){ 
    var keycode = e.which 
  } else {
    var keycode = e.keyCode 
  }

  ParseForNumber1(object)

  if(keycode >= 48){
    ValidatePhone(object)
  }
}

function backspacerDOWN(object,e) { 
  if(e){ 
    e = e 
  } else {
    e = window.event 
  } 
  if(e.which){ 
    var keycode = e.which 
  } else {
    var keycode = e.keyCode 
  }
  ParseForNumber2(object)
} 

function GetCursorPosition(){

  var t1 = phonevalue1;
  var t2 = phonevalue2;
  var bool = false
  for (i=0; i<t1.length; i++)
  {
    if (t1.substring(i,1) != t2.substring(i,1)) {
      if(!bool) {
        cursorposition=i
        window.status=cursorposition
        bool=true
      }
    }
  }
}

function ValidatePhone(object){

  var p = phonevalue1

  p = p.replace(/[^\d]*/gi,"")

  if (p.length < 3) {
    object.value=p
  } else if(p.length==3){
    pp=p;
    d4=p.indexOf('(')
    d5=p.indexOf(')')
    if(d4==-1){
      pp="("+pp;
    }
    if(d5==-1){
      pp=pp+")";
    }
    object.value = pp;
  } else if(p.length>3 && p.length < 7){
    p ="(" + p; 
    l30=p.length;
    p30=p.substring(0,4);
    p30=p30+") " 

    p31=p.substring(4,l30);
    pp=p30+p31;

    object.value = pp; 

  } else if(p.length >= 7){
    p ="(" + p; 
    l30=p.length;
    p30=p.substring(0,4);
    p30=p30+") " 

    p31=p.substring(4,l30);
    pp=p30+p31;

    l40 = pp.length;
    p40 = pp.substring(0,9);
    p40 = p40 + "-"

    p41 = pp.substring(9,l40);
    ppp = p40 + p41;

    object.value = ppp.substring(0, maxphonelength);
  }

  GetCursorPosition()

  if(cursorposition >= 0){
    if (cursorposition == 0) {
      cursorposition = 2
    } else if (cursorposition <= 2) {
      cursorposition = cursorposition + 1
    } else if (cursorposition <= 4) {
      cursorposition = cursorposition + 3
    } else if (cursorposition == 5) {
      cursorposition = cursorposition + 3
    } else if (cursorposition == 6) { 
      cursorposition = cursorposition + 3 
    } else if (cursorposition == 7) { 
      cursorposition = cursorposition + 4 
    } else if (cursorposition == 8) { 
      cursorposition = cursorposition + 4
      e1=object.value.indexOf(')')
      e2=object.value.indexOf('-')
      if (e1>-1 && e2>-1){
        if (e2-e1 == 4) {
          cursorposition = cursorposition - 1
        }
      }
    } else if (cursorposition == 9) {
      cursorposition = cursorposition + 4
    } else if (cursorposition < 11) {
      cursorposition = cursorposition + 3
    } else if (cursorposition == 11) {
      cursorposition = cursorposition + 1
    } else if (cursorposition == 12) {
      cursorposition = cursorposition + 1
    } else if (cursorposition >= 13) {
      cursorposition = cursorposition
    }

    var txtRange = object.createTextRange();
    txtRange.moveStart( "character", cursorposition);
    txtRange.moveEnd( "character", cursorposition - object.value.length);
    txtRange.select();
  }

}

function ParseChar(sStr, sChar)
{

  if (sChar.length == null) 
  {
    zChar = new Array(sChar);
  }
    else zChar = sChar;

  for (i=0; i<zChar.length; i++)
  {
    sNewStr = "";

    var iStart = 0;
    var iEnd = sStr.indexOf(sChar[i]);

    while (iEnd != -1)
    {
      sNewStr += sStr.substring(iStart, iEnd);
      iStart = iEnd + 1;
      iEnd = sStr.indexOf(sChar[i], iStart);
    }
    sNewStr += sStr.substring(sStr.lastIndexOf(sChar[i]) + 1, sStr.length);

    sStr = sNewStr;
  }

  return sNewStr;
}

<!-- The following script  checks for valid Material Donation form input 
<!-- added 2/6/2010

function checkdonationform (form){
	noblank_fields=true;
	first_name_blank=false;
	last_name_blank=false;
	addr1_blank=false;
	city_state_zip_blank=false;	
	callback_number_blank=false;	
	item_location_blank=false;	
	qty1_blank=false;	
	qty1_type_blank=false;
	description1_blank=false;
	 
	all_fields_blank=false;
	alert_msg="";

   if((form.first_name.value == '') && (form.last_name.value =='') && (form.callback_number.value =='') && (form.qty1.value == '') && (form.qty1_type.value =='NONE') && (form.description1.value =='') && (form.addr1.value == '') && (form.city_state_zip.value =='') && (form.item_location.value =='NOT ENTERED'))
    { alert_msg=" All required items are blank, please correct.";
	  noblank_fields=false;
	  all_fields_blank=true;}	  
   else if(form.first_name.value == '')
      {alert_msg=" No First Name entered, please correct.";
	  noblank_fields=false;
	  first_name_blank=true;}
   else if(form.last_name.value == '')
      {alert_msg=" No Last Name entered, please correct.";
	  noblank_fields=false;
	  last_name_blank=true;}
   else if(form.addr1.value == '')
      {alert_msg=" No Address entered, please correct.";
	  noblank_fields=false;
	  addr1_blank=true;}
   else if(form.city_state_zip.value == '')
      {alert_msg=" No City, State, Zip entered, please correct.";
	  noblank_fields=false;
	  city_state_zip_blank=true;}
   else if(form.callback_number.value == '')
      {alert_msg=" No Call Back Number entered, please correct.";
	  noblank_fields=false; 
	  callback_number_blank=true;}
   else if(form.qty1.value == '')
      {alert_msg=" No Item Quantity entered, please correct.";
	  noblank_fields=false; 
	  qty1_blank=true;}
   else if(form.qty1_type.value == 'NONE')
      {alert_msg=" Item Qty Type not selected, please correct.";
	  noblank_fields=false; 
	  qty1_type_blank=true;}
   else if(form.description1.value == '')
      {alert_msg=" No Item Description entered, please correct.";
	  noblank_fields=false; 
	  description1_blank=true;}
   else if(form.item_location.value == 'NOT ENTERED')
      {alert_msg=" Item Location not selected, please correct.";
	  noblank_fields=false; 
	  item_location_blank=true;}
/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */	  
   if(form.email_address.value != "" )
     {  str = form.email_address.value;
	    bad_email_address=false;
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		
		if (str.indexOf(at)==-1){
		   emalert_msg="Invalid E-mail Address";
		   bad_email_address=true;
		  
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   emalert_msg="Invalid E-mail Address";
		   bad_email_address=true;
		   
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   emalert_msg="Invalid E-mail Address";
		   bad_email_address=true;
		     
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   emalert_msg="Invalid E-mail Address";
		   bad_email_address=true;
		   
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   emalert_msg="Invalid E-mail Address";
		   bad_email_address=true;
		    
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   emalert_msg="Invalid E-mail Address";
		   bad_email_address=true;
		   
		 }
		
		 if (str.indexOf(" ")!=-1){
		   emalert_msg="Invalid E-mail Address";
		   bad_email_address=true;}
		 			
	}
	 
   	  
   if((noblank_fields ==false) || (bad_email_address==true)){
      if(noblank_fields ==false)
         {alert( alert_msg);}
	  else
	     {alert( emalert_msg);}
		 
	  if(all_fields_blank==true)
		   {form.first_name.focus();
		    return false;}
	  else if(first_name_blank==true)
	      {form.first_name.focus();
		    return false;}
	  else if(last_name_blank==true)
	      {form.last_name.focus();
		    return false;}
	  else if(addr1_blank==true)
	      {form.addr1.focus();
		    return false;}
	  else if(city_state_zip_blank==true)
	      {form.city_state_zip.focus();
		    return false;}
	  else if(callback_number_blank==true)
	      {form.callback_number.focus();
		    return false;}
	  else if(qty1_blank==true)
	      {form.qty1.focus();
		    return false;}
	  else if(qty1_type_blank==true)
	      {form.qty1_type.focus();
		    return false;}
	  else if(description1_blank==true)
	      {form.description1.focus();
		    return false;}
	  else if(item_location_blank==true)
	      {form.item_location.focus();
		    return false;}
	  else if(item_location_blank==true)
	      {form.item_location.focus();
		    return false;}
	  else if(bad_email_address==true)
	      {form.email_address.focus();
		    return false;}
			
	  return true;}}
 
	
	
	
	