﻿window.onload = function () {
    //init();
}

/* ULTRA-SIMPLE EVENT ADDING */

function addEventSimple(obj,evt,fn) {
	if (obj.addEventListener)
		obj.addEventListener(evt,fn,false);
	else if (obj.attachEvent)
		obj.attachEvent('on'+evt,fn);
}

function removeEventSimple(obj,evt,fn) {
	if (obj.removeEventListener)
		obj.removeEventListener(evt,fn,false);
	else if (obj.detachEvent)
		obj.detachEvent('on'+evt,fn);
}


/* FUNCTIONS FOR I-GIVE PAGE */

function My_form_Validator(form){

	if (document.aspnetForm.totalamount.value == 0){
		alert("Please enter a donation to at least one fund before submitting.");
		return false;
	}


	if ((document.aspnetForm.GIFT_AMOUNT8.value != 0) && ((document.aspnetForm.fundEntry8.value.length < 2) || (document.aspnetForm.fundEntry8.value == "Other - Indicate where to direct donation here"))){
		alert("Please enter a fund to receive your donation.");
		document.aspnetForm.fundEntry8.focus();
		return false;
	}
	else {
		document.aspnetForm.FUND8.value = "00000000/" + document.aspnetForm.fundEntry8.value;
	}
	//alert("here");
	document.aspnetForm.action="https://www.uif.uillinois.edu/Gifts/payment.aspx";
	document.aspnetForm.submit();
    return;
}

// -----------------------------------------------------------------
// CalcDisplayAmount - convert numeric entry to formatted text value
// -----------------------------------------------------------------
function CalcDisplayAmount(amt)
{
	var displayAmt;
	var amtValue;
	if (isNaN(amt)== true){   //not a valid number
		displayAmt = "0.00";
		return displayAmt;		
	}

      if (amt.length==0) {		// no value at all
		displayAmt = "0.00";
		return displayAmt;	
	}

    //document.aspnetForm.FUND8.value = "00000000/" + document.aspnetForm.fundEntry8.value;
    
    // round to 2 places after the decimal point
	amtValue = parseFloat(amt);
	amtValue = Math.round(amtValue * 100) / 100;
	//	if user enters in value < 0, make it 0
	if (amtValue < 0) 
		amtValue = 0;
	
    //	if it doesn't contain decimal point, add it 
	if (amtValue == Math.round(amtValue)) {
		displayAmt = amtValue + ".00";
	}
    // else if it only contains one place after the decimal, add one more
	else if (amtValue * 10 == Math.round(amtValue * 10)) {
		displayAmt = amtValue + "0";
	}

    // else it contains 2 places after the decimal, just return it
	else {
		displayAmt = amtValue;
	}
	return displayAmt;
}

// -----------------------------------------------------------------
// amountchange() - called when any amount changes
// -----------------------------------------------------------------
function amountchange()    {
	var total;

	/* change display format */

	total = 0;

	document.aspnetForm.GIFT_AMOUNT1.value=CalcDisplayAmount(document.aspnetForm.GIFT_AMOUNT1.value);
	total = total + parseFloat(document.aspnetForm.GIFT_AMOUNT1.value)

	document.aspnetForm.GIFT_AMOUNT2.value=CalcDisplayAmount(document.aspnetForm.GIFT_AMOUNT2.value);
	total = total + parseFloat(document.aspnetForm.GIFT_AMOUNT2.value)

	document.aspnetForm.GIFT_AMOUNT3.value=CalcDisplayAmount(document.aspnetForm.GIFT_AMOUNT3.value);
	total = total + parseFloat(document.aspnetForm.GIFT_AMOUNT3.value)

	document.aspnetForm.GIFT_AMOUNT4.value=CalcDisplayAmount(document.aspnetForm.GIFT_AMOUNT4.value);
	total = total + parseFloat(document.aspnetForm.GIFT_AMOUNT4.value)

	document.aspnetForm.GIFT_AMOUNT5.value=CalcDisplayAmount(document.aspnetForm.GIFT_AMOUNT5.value);
	total = total + parseFloat(document.aspnetForm.GIFT_AMOUNT5.value)

	document.aspnetForm.GIFT_AMOUNT6.value=CalcDisplayAmount(document.aspnetForm.GIFT_AMOUNT6.value);
	total = total + parseFloat(document.aspnetForm.GIFT_AMOUNT6.value)

	document.aspnetForm.GIFT_AMOUNT7.value=CalcDisplayAmount(document.aspnetForm.GIFT_AMOUNT7.value);
	total = total + parseFloat(document.aspnetForm.GIFT_AMOUNT7.value)
	
	document.aspnetForm.GIFT_AMOUNT8.value=CalcDisplayAmount(document.aspnetForm.GIFT_AMOUNT8.value);
	total = total + parseFloat(document.aspnetForm.GIFT_AMOUNT8.value)

	total = Math.round(total * 100) / 100;
	document.aspnetForm.totalamount.value=CalcDisplayAmount(total);
}
/* END FUNCTIONS FOR I-GIVE PAGE */


/* directory info popup */
var xPos;
var yPos;
//if IE
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  //document.Show.MouseX.value = tempX
  //document.Show.MouseY.value = tempY
  xPos = tempX;
  yPos = tempY;
  //alert(tempX);
  return true
}


function showInfo(){
    var elem = document.getElementById("personInfo");
    elem.style.display = "block";
    //subtract height of header plus some
    elem.style.marginTop = (tempY-275) + "px";
    //alert (elem.style.marginTop);
    
}


/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code


var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function getInfo(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}
***********************************************/


/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}

