//Copyright 2003-2006 EuroNetting Inc.//

function blockError(){
	return true
}


window.onerror = blockError

parent.banner.resetCounter();


function isEmail (email) {
    invalidChars = " /:,;"
    if (email == "") {return false}
    for (i=0; i<invalidChars.length; i++) {
        badChar = invalidChars.charAt(i)
        if (email.indexOf(badChar,0) > -1) {return false}
    }
    atPos = email.indexOf("@",1)
    if (atPos == -1) {return false}
    if (email.indexOf("@", atPos+1) > -1) {return false}
    periodPos = email.indexOf(".",atPos)
    if (periodPos == -1) {return false}
    if (periodPos+3 > email.length) {return false}
    return true;

}


function send_mail(recipient) {
   popUp = window.open("", "Email", "resizable=no,scrollbars=no,width=540,height=300"); 
   popUp.location.href = "../export/s_mail.asp?mailto=" + recipient; 
   popUp.focus()   
}

function send_message(eMailAddress, userID) {
   popUp = window.open("", "Message", "resizable=no,scrollbars=no,width=540,height=300"); 
   popUp.location.href = "../export/s_message.asp?mailto=" + eMailAddress + "&userid=" + userID; 
   popUp.focus()   
}




function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}


function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}



function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}




function isInteger (s)

{   var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    for (i = 0; i < s.length; i++)
    {   
         var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }
     return true;
}




function roundAmount(n) {
 var s = "" + Math.round(n * 1000) / 1000
 var i = s.indexOf('.')
 if (i < 0) return s + ".000"
 var t = s.substring(0, i + 1) + 
    s.substring(i + 1, i + 3)
 if (i + 3 == s.length) t += "0"
 return t
}


function ChkAmt(fld) 

{
  TheValue = fld.value
  TheLength = TheValue.length
  NumDecimals = 0

  for (i = 0; i <= TheLength-1; i++) {

     if (TheValue.charAt(i) < "0" || TheValue.charAt(i) > "9") {

      if (TheValue.charAt(i) == ".") {
        NumDecimals++
        if (NumDecimals > 1) {
          alert("Too many decimal points in number.")
          return false
        }
      }
      else if (TheValue.charAt(i) == ",") {
	//ignore commas
      }
      else if (TheValue.charAt(i) == "$") {
        alert("Do not include a dollar sign in the number.")
         return false
      }
      else if (TheValue.charAt(i) == "+") {
        if (i != 0) {
          alert("Invalid use of plus (+) sign.")
          return false
        }
      }
      else if (TheValue.charAt(i) == "-") {
        if (i != 0) { 
          alert("Invalid use of minus (-) sign.")
          return false
        }
      }
      else {
        alert("Invalid amount.")
        return false
      }
    }
  }
  return true
}




function hideDiv(hide_it, divName) {
//------------------------------------------------------------------------
//generic function for hiding/displaying <div> element with name 'divName'
// hide_it = 1 to hide, 0 to display
//------------------------------------------------------------------------

  if (hide_it == "") {hide_it = 0}

    if (hide_it == 0) {
	
       if (parseInt(navigator.appVersion) >= 5 || navigator.appVersion.indexOf["MSIE 5"] != -1) {
        obj = eval(document.getElementById(divName))
	    obj.style.display = ""
        }

      if (document.layers) {
        //obj = eval("document." + divName)
        obj = eval("document.layers[" + divName + "]")
        obj.visibility = "show";
        }
      if (document.all) {
        obj = eval("document.all." + divName)
        obj.style.visibility = "visible";
        }
      }
 
    if (hide_it == 1) {
       if (parseInt(navigator.appVersion) >= 5 || navigator.appVersion.indexOf["MSIE 5"] != -1) {
        obj = eval(document.getElementById(divName))
       	obj.style.display = "none"
        }
      if (document.layers) {
        //obj = eval("document." + divName)
        obj = eval("document.layers[" + divName + "]")
        obj.visibility = "hide";
      	}
      if (document.all) {
        obj = eval("document.all." + divName)
        obj.style.visibility = "hidden";
      	}
      }
  }
	


function popcal(vCaption, vField, vDate){ 
    popUp = window.open("", "calendar", 
        "resizable=no,scrollbars=no,width=260,height=190"); 
    popUp.location.href = "../_includes/popcalendar.asp?caption=" + 
        escape(vCaption) + 
        "&field=" + vField + "&date='" + vDate + "'"; 
} 

function closePopupWindow() {
	if(popUp != null){
	popUp.close()
	}
	}

function RowOn(Row) {
	//Row.style.backgroundColor = "#d8d8d8"
	Row.style.backgroundColor = parent.banner.rowColor
	Row.style.cursor = "hand"
	}
	
function RowOff(Row) {
	Row.style.backgroundColor = "#f7f7f7"
	}
	
function RowDown(Row) {
	Row.style.backgroundColor = "salmon"
	Row.style.color = "white"
	}	
	
function changepage(url) {
    window.location= url;
    }

function ChkPct(fld) 

{
  TheValue = fld.value
  TheLength = TheValue.length
  NumDecimals = 0

  for (i = 0; i <= TheLength-1; i++) {

     if (TheValue.charAt(i) < "0" || TheValue.charAt(i) > "9") {

      if (TheValue.charAt(i) == ".") {
        NumDecimals++
        if (NumDecimals > 3) {
          alert("Too many decimal points in number.")
          fld.focus()
          fld.select()
          return false
        }
      }
      else if (TheValue.charAt(i) == ",") {
	//ignore commas
      }
      else if (TheValue.charAt(i) == "$") {
        alert("Do not include a dollar sign in the number.")
          fld.focus()
          fld.select()
         return false
      }
      else if (TheValue.charAt(i) == "+") {
        if (i != 0) {
          alert("Invalid use of plus (+) sign.")
          fld.focus()
          fld.select()
          return false
        }
      }
      else if (TheValue.charAt(i) == "-") {
         fld.focus()
         fld.select()
         return false

      }
      else {
        alert("Invalid amount.")
        fld.focus()
        fld.select()
        return false
      }
    }
  }
  return true
}



function calcEqualShares() {
selPar = 0
for (i=0; i<document.pc.sel.length; i++) {
	if (document.pc.sel[i].checked) {
		selPar++
	}
}
document.pc.sel_count.value = selPar
document.pc.sel_pct.value = Math.round((100/selPar) * 1000) / 1000
}


function previewShares() {
selPar = 0
for (i=0; i<document.pc.sel.length; i++) {
	if (document.pc.sel[i].checked) {
		selPar++
	}
}
if (selPar == 0) {
	alert("You must select one or more participants!")
	return false
}


}




// Global Vars for type-ahead searth function in selection list
         
var tString = '';
var lsf = 0;	// last successful index


function evalKey() {
    // Global Variables
    var i = 0; 
    var success = false;
    var elem = event.srcElement;
alert(elem.name)
    var tLowElemText = '';
    // Get the unicode char of the keypress
    var eCode = event.keyCode;
    // Check if it's a vaid ASCII Character
    if (eCode == 27){
        tString = ''; 
        elem.selectedIndex = 0;
        }
    else if ( (eCode > 31) && (eCode < 122))
        {
        // Convert the Code to the corresponding character and add to searchstring
        tString += String.fromCharCode(eCode);
        // ... and perform the search starting from the top element in the listbox
        while (success == false) 	
            {
                i = 0;
                // Convert everything to lowercase; allows an easy comparison
                var tLowString = tString.toLowerCase();
                // Compose the regexp searchstring ...
                var rExpr = eval("/^" +  tLowString + "/");
                while ((i < elem.length)&& (success == false) )	
                    {
                        tLowElemText = elem.options[i].text.toLowerCase();
                        // success: Position the listbox on the (first) found element
                        if (tLowElemText.search(rExpr) != -1)
                            {
                                elem.selectedIndex = i;
                                success = true;
                            }
                        else {
                                i++; }
                             } // while i < elem.length
                        // if nothing is found in the entire list, the last character of the
                        //searchstring is removed to allow typing the correct 'next' character
                        if (success == false) {
                            tString = tString.substr(0, tString.length-1);
                     }
              } // while success = false
        } 
        // Just for demo use: updates the span displaying the typed
        // characters; remove from code before re-using
        lchr.innerText =String.fromCharCode(eCode);
        tsf.innerText = tString;
         
        window.event.returnValue = false;
        window.event.cancelBubble = true;
}


function getList (targetList, sourceList, selectedID, showAll, showNone) {
// 5/8/05: function not currently used; tested for loading selection lists
// from pre-loaded lists in banner page, but appears to be slower than loading fresh
// list from database
	var extras = 0
	if ((showNone == 1) && (sourceList.options.length != 1)) {
		targetList.options[extras] = new Option("", "");	
		extras++
	}
	if ((showAll == 1) && (sourceList.options.length != 1)) {
		targetList.options[extras] = new Option("All", 0);	
		extras++
	}
	
	for(var i = 0; i < sourceList.options.length; i++) {
			targetList.options[i + extras] = new Option(sourceList.options[i].text, sourceList.options[i].value );
			if (sourceList.options[i].value == selectedID) {targetList.options[i + extras].selected = 1}
 	}  
}


