
function validate_donation(i)
{
		var f = document.donate;
		for (x=0;x<document.donate.total.length;x=x+1)
    {
		 		if (document.donate.damount[x].checked == true)
				{
				 	 document.getElementById(amount_other).value = '';
				}
		}
}

function something()
{
alert('here');
}

//clear an element value, set an element value to the caller value
function clearField()
{
		alert('here');
		alert('clear_what_id = ' + clear_what_id + '   called_from = ' + called_from + '   set_what_id = ' + set_what_id);
		document.getElementById(clear_what_id).value = '';
		alert(document.getElementById(set_what_id).value);
		document.getElementById(set_what_id).value = called_from.value;
		alert(document.getElementById(set_what_id).value);
}

//clear the calling element...onClick='doClear(this)'
function doClear(theText) {
     if (theText.value == theText.defaultValue) {
         theText.value = '';
     }
}

//if other amount is selected, we clear the hidden total_amount and set focus to the other amount field
function otherField(set_focus_id,clear_what_id){
		document.getElementById(clear_what_id).value = '';
		alert(document.getElementById(clear_what_id).value);
		document.getElementById(set_focus_id).focus();
}

/*
ShadowValidation
----------------

Generic Form Validation.
To activate this validation, add attributes to your form elements.
Attribute "validate" defines what type of validation you want.
Possible values for "validate" attribute:
	"not_empty" - element can't be empty.
	"integer" - element must have integer value.
	"number" - element must have numeric value.
	"email" - element value must be valid email address.
	"alphabet" - element value must consist only of given alphabet list in allow_only attribute.
			you can give ranges using ".." in the allow_only attribute.
	[function name] - vaidate using your own function. see below for more details.
You can join more than one validation type by using the "|" character.
For example:
	<input type="text" name="myinput" validate="not_empty|number" />
	will force not empty and numeric value.
Example for alphabet validation:
	<input type="text" name="myinput" validate="not_empty|alphabet" allow_only="a..zA..Z0..9" />
	will force not empty value that contains only english letters or digits.
Attribute "msg" defines the message to display when validation fails.
For example:
	<input type="text" name="myinput" validate="not_empty|number" msg="please enter value|invalid value" />
	will show "please enter value" if value is empty and "invalid value" if not numeric.
By default, the message will appear next to the form element.
You can have the message appear as alert dialog by adding show_alert attribute to the form.
For example:
	<form show_alert="1" onsubmit="return Validate(this);">
	will show the messages as alerts.
Attribute "error_container" defines where the message will appear in case of invalid input.
You must have corresponding <span> or <div> tag with that exact ID in the page. If this
attribute is missing, the message will appear after the input element.
For example:
	<input type="radio" name="gender" value="M" validate="not_empty" msg="please select gender" error_container="GenderErrorContainer" />
	and then have such code after the radio buttons:
	<span id="GenderErrorContainer"></span>
Advanced:
	You can use your own function to validate the data.
	For this, write the function name as the value of "validate" attribute.
	For example:
		<input type="text" name="myinput" validate="MyValidate" />
	The function must get the form element as its parameter and return true if valid or false otherwise.


Written by:
	© Shadow Wizard, 2006

*/

function Validate(objForm) {
	var arrValidated=new Array();
	
	for (var i=0; i<objForm.elements.length; i++) {
		var element=objForm.elements[i];
		var elName=element.name;
		if ((!elName)||(elName.length == 0)||(arrValidated[elName]))
			continue;
		arrValidated[elName] = true;
		var validationType = element.getAttribute("validate");
		if ((!validationType)||(validationType.length == 0))
			continue;
		var strMessages=element.getAttribute("msg");
		if (!strMessages)
			strMessages = "";
		var arrMessages = strMessages.split("|");
		var arrValidationTypes = validationType.split("|");		
		for (var j=0; j<arrValidationTypes.length; j++) {
			var curValidationType = arrValidationTypes[j];
			var blnValid=true;
			switch (curValidationType) {
				case "not_empty":
					blnValid = ValidateNotEmpty(element);
					break;
				case "integer":
					blnValid = ValidateInteger(element);
					break;
				case "number":
					blnValid = ValidateNumber(element);
					break;
				case "email":
					blnValid = ValidateEmail(element);
					break;
				case "alphabet":
					blnValid = ValidateAlphaBet(element);
					break;
				default:
					try {
						blnValid = eval(curValidationType+"(element)");
					}
					catch (ex) {
						blnValid = true;
					}
			}
			if (blnValid == false) {
				var message="invalid value for "+element.name;
				if ((j < arrMessages.length)&&(arrMessages[j].length > 0))
					message = arrMessages[j];
				InsertError(element, message);
				if ((typeof element.focus == "function")||(element.focus)) {
					element.focus();
				}
				return false;
			}
			else
				ClearError(element);
		}
		
	}
	
	return true;
}

function ValidateNotEmpty(objElement) {
	var strValue = GetElementValue(objElement);
	return (strValue.length > 0);
}

function ValidateInteger(objElement) {
	var strValue = GetElementValue(objElement);
	return (!isNaN(parseInt(strValue)));
}

function ValidateNumber(objElement) {
	var strValue = GetElementValue(objElement);
	return (!isNaN(parseFloat(strValue)));
}

function ValidateEmail(objElement) {
	var strValue = GetElementValue(objElement);
	if (strValue.length < 5)
		return false;
	var arrTemp=strValue.split("@");
	if (arrTemp.length != 2)
		return false;
	var strLeftPart = arrTemp[0];
	var strRightPart = arrTemp[1];
	if ((strLeftPart.length == 0)||(strRightPart.length == 0))
		return false;
	arrTemp = strRightPart.split(".");
	if (arrTemp.length < 2)
		return false;
	for (var i=0; i<arrTemp.length; i++) {
		if (arrTemp[i].length == 0)
			return false;
	}
	return true;
}

function ValidateAlphaBet(objElement) {
	var strValue = GetElementValue(objElement);
	
	if (strValue.length == 0)
		return true;
	
	var strAllowOnly = objElement.getAttribute("allow_only");
	if (!strAllowOnly)
		strAllowOnly = "";
	
	if (strAllowOnly.length == 0)
		return true;
	
	var i=0;
	var arrAllowedChars=new Array();
	while (i < strAllowOnly.length) {
		if ((i < (strAllowOnly.length-2)) && (strAllowOnly.substr(i+1, 2) == "..")) {
			for (var j=strAllowOnly.charCodeAt(i); j<=strAllowOnly.charCodeAt(i+3); j++) {
				arrAllowedChars[arrAllowedChars.length] = String.fromCharCode(j);
			}
			i += (2*2);
			continue;
		}
		arrAllowedChars[arrAllowedChars.length] = strAllowOnly.charAt(i)+"";
		i++;
	}
	
	for (var i=0; i<strValue.length; i++)
		if (InArray(arrAllowedChars, strValue.substr(i, 1)) < 0)
			return false;
	
	return true;
}

function GetElementValue(objElement) {
	var result="";
	switch (objElement.type) {
		case "text":
		case "hidden":
		case "textarea":
		case "password":
			result = objElement.value;
			break;
		case "select-one":
		case "select":
			if (objElement.selectedIndex >= 0)
				result = objElement.options[objElement.selectedIndex].value;
			break;
		case "radio":
		case "checkbox":
			for (var i=0; i<objElement.form.elements.length; i++) {
				if (objElement.form.elements[i].name == objElement.name) {
					if (objElement.form.elements[i].checked)
						result += objElement.form.elements[i].value+",";
				}
			}
			break;
	}
	return result;
}

function InsertError(element, strMessage) {
	if ((element.form.getAttribute("show_alert")) && (element.form.getAttribute("show_alert") != "0")) {
		alert(strMessage);
		return;
	}
	
	var strSpanID = GetErrorContainerID(element);
	var objSpan = document.getElementById(strSpanID);
	if (!objSpan) {
		if ((element.type == "radio")||(element.type == "checkbox")) {
			for (var i=0; i<element.form.elements.length; i++) {
				if (element.form.elements[i].name == element.name) {
					element = element.form.elements[i];
				}
			}
		}
		objSpan = document.createElement("span");
		objSpan.id = strSpanID;
		var nodeAfter=0;
		var nodeParent = element.parentNode;
		for (var i=0; i<nodeParent.childNodes.length; i++) {
			if (nodeParent.childNodes[i] == element) {
				if (i < (nodeParent.childNodes.length-1))
					nodeAfter = nodeParent.childNodes[i+1];
				break;
			}
		}
		if ((!nodeAfter)&&(nodeParent.parentNode)) {
			nodeParent = nodeParent.parentNode;
			for (var i=0; i<nodeParent.childNodes.length; i++) {
				if (nodeParent.childNodes[i] == element.parentNode) {
					if (i < (nodeParent.childNodes.length-1))
						nodeAfter = nodeParent.childNodes[i+1];
					break;
				}
			}
		}
		if (nodeAfter)
			nodeParent.insertBefore(objSpan, nodeAfter);
		else
			document.body.appendChild(objSpan);
	}
	if (objSpan.className.length == 0)
		objSpan.className = "validation_error";
	objSpan.innerHTML = strMessage;
}

function ClearError(element) {
	var strSpanID = GetErrorContainerID(element);
	var objSpan = document.getElementById(strSpanID);
	if (objSpan) {
		objSpan.innerHTML = "";
	}
}

function GetErrorContainerID(element) {
	var strSpanID = element.getAttribute("error_container");
	if (!strSpanID || strSpanID.length == 0) {
		strSpanID = element.name+"_val_error";
	}
	return strSpanID;
}

function InArray(arr, key) {
	for (var i=0; i<arr.length; i++) {
		if (arr[i] == key) {
			return i;
		}
	}
	return -1;
}
//--------------------------------------------------------------------

// text to show in empty credit card number field
var cardno_msg = 'no dashes or spaces';

// clear card number field if default message is shown
function processCardNoFocus (field) {
  if (field.value == cardno_msg) {
    field.value = '';
    field.style.color = 'black';
  }
}

// insert default message if card number left blank
function processCardNoBlur (field) {
  if (field.value == '') {
    field.value = ' ';
    field.style.color = '#999';
    field.value = cardno_msg;
  }
}

// generic pop up window
var newwindow;
function poptastic(url,hgh,wdth)
{
 	//alert(url,'security_code','height=' + hgh + ',' + 'width=' + wdth );
	newwindow=window.open(url,'security_code','height=' + hgh + ',' + 'width=' + wdth );
	if (window.focus) {newwindow.focus()}
}

// show/hide repeat controls when frequency (e.g. one-time, monthly, etc.) is changed
function processFrequencyChange (menu) {
  // show/hide 'repeat' options (forever or number)
  var i = menu.selectedIndex;
  setVisible('repeat_row', (i != 0));
  document.getElementById('repeat_radio_forever').checked = true;
  clearField('repeat_number');
}

// set the visibility of the given element based on flag
// return true if the visibility was actually changed
function setVisible (id, flag) {
  var obj = document.getElementById(id);
  var chg = false;
  if (obj) {
    var old = obj.style.display;
    var val = flag ? '' : 'none';
    obj.style.display = val;
    chg = (old != val);
  }  
  return chg;
}

/* test stuff

 	 Smooth scrolling
   Changes links that link to other parts of this page to scroll
   smoothly to those links rather than jump to them directly, which
   can be a little disorienting.
   
   sil, http://www.kryogenix.org/
   
   v1.0 2003-11-11
   v1.1 2005-06-16 wrap it up in an object
*/

var ss = {
  fixAllLinks: function() {
    // Get a list of all links in the page
    var allLinks = document.getElementsByTagName('a');
    // Walk through the list
    for (var i=0;i<allLinks.length;i++) {
      var lnk = allLinks[i];
      if ((lnk.href && lnk.href.indexOf('#') != -1) && 
          ( (lnk.pathname == location.pathname) ||
	    ('/'+lnk.pathname == location.pathname) ) && 
          (lnk.search == location.search)) {
        // If the link is internal to the page (begins in #)
        // then attach the smoothScroll function as an onclick
        // event handler
        ss.addEvent(lnk,'click',ss.smoothScroll);
      }
    }
  },

  smoothScroll: function(e) {
    // This is an event handler; get the clicked on element,
    // in a cross-browser fashion
    if (window.event) {
      target = window.event.srcElement;
    } else if (e) {
      target = e.target;
    } else return;

    // Make sure that the target is an element, not a text node
    // within an element
    if (target.nodeName.toLowerCase() != 'a') {
      target = target.parentNode;
    }
  
    // Paranoia; check this is an A tag
    if (target.nodeName.toLowerCase() != 'a') return;
  
    // Find the <a name> tag corresponding to this href
    // First strip off the hash (first character)
    anchor = target.hash.substr(1);
    // Now loop all A tags until we find one with that name
    var allLinks = document.getElementsByTagName('a');
    var destinationLink = null;
    for (var i=0;i<allLinks.length;i++) {
      var lnk = allLinks[i];
      if (lnk.name && (lnk.name == anchor)) {
        destinationLink = lnk;
        break;
      }
    }
    if (!destinationLink) destinationLink = document.getElementById(anchor);

    // If we didn't find a destination, give up and let the browser do
    // its thing
    if (!destinationLink) return true;
  
    // Find the destination's position
    var destx = destinationLink.offsetLeft; 
    var desty = destinationLink.offsetTop;
    var thisNode = destinationLink;
    while (thisNode.offsetParent && 
          (thisNode.offsetParent != document.body)) {
      thisNode = thisNode.offsetParent;
      destx += thisNode.offsetLeft;
      desty += thisNode.offsetTop;
    }
  
    // Stop any current scrolling
    clearInterval(ss.INTERVAL);
  
    cypos = ss.getCurrentYPos();
  
    ss_stepsize = parseInt((desty-cypos)/ss.STEPS);
    ss.INTERVAL =
setInterval('ss.scrollWindow('+ss_stepsize+','+desty+',"'+anchor+'")',10);
  
    // And stop the actual click happening
    if (window.event) {
      window.event.cancelBubble = true;
      window.event.returnValue = false;
    }
    if (e && e.preventDefault && e.stopPropagation) {
      e.preventDefault();
      e.stopPropagation();
    }
  },

  scrollWindow: function(scramount,dest,anchor) {
    wascypos = ss.getCurrentYPos();
    isAbove = (wascypos < dest);
    window.scrollTo(0,wascypos + scramount);
    iscypos = ss.getCurrentYPos();
    isAboveNow = (iscypos < dest);
    if ((isAbove != isAboveNow) || (wascypos == iscypos)) {
      // if we've just scrolled past the destination, or
      // we haven't moved from the last scroll (i.e., we're at the
      // bottom of the page) then scroll exactly to the link
      window.scrollTo(0,dest);
      // cancel the repeating timer
      clearInterval(ss.INTERVAL);
      // and jump to the link directly so the URL's right
      location.hash = anchor;
    }
  },

  getCurrentYPos: function() {
    if (document.body && document.body.scrollTop)
      return document.body.scrollTop;
    if (document.documentElement && document.documentElement.scrollTop)
      return document.documentElement.scrollTop;
    if (window.pageYOffset)
      return window.pageYOffset;
    return 0;
  },

  addEvent: function(elm, evType, fn, useCapture) {
    // addEvent and removeEvent
    // cross-browser event handling for IE5+,  NS6 and Mozilla
    // By Scott Andrew
    if (elm.addEventListener){
      elm.addEventListener(evType, fn, useCapture);
      return true;
    } else if (elm.attachEvent){
      var r = elm.attachEvent("on"+evType, fn);
      return r;
    } else {
      alert("Handler could not be removed");
    }
  } 
}

ss.STEPS = 25;

ss.addEvent(window,"load",ss.fixAllLinks);
