function turnOn(imageName) {
  if (document.images) {
    document[imageName].src = eval(imageName + "on.src");
  }
}
function turnOff(imageName) {
  if (document.images) {
    document[imageName].src = eval(imageName + "off.src");
  }
}

function openResizeWin(url, name) {

  popupWin = window.open(url, name, "menubar=no,toolbar=no,location=no,directories=no,status,scrollbars=yes, resizable,dependent,width=450,height=450,left=25,top=25");
  window.opener = top
}

function openWin(url, name) {

  popupWin = window.open(url, name, "menubar=no,toolbar=no,location=no,directories=no,status,scrollbars=no, resizable=no,dependent,width=450,height=250,left=25,top=25");
  window.opener = top
}
function openeCheckWin(url, name) {

  popupWin = window.open(url, name, "menubar=no,toolbar=no,location=no,directories=no,status,scrollbars=no, resizable=yes,dependent,width=750,height=325,left=150,top=150");
  window.opener = top
}

function SelectRef(url, name) {

  popupWin = window.open(url, name, "menubar=no,toolbar=no,location=no,directories=no,status,scrollbars=yes, resizable=yes,dependent,width=700,height=225,left=400,top=45");
  window.opener = top
}

function SelectVol(url, name) {

  popupWin = window.open(url, name, "menubar=no,toolbar=no,location=no,directories=no,status,scrollbars=yes, resizable=no,dependent,width=600,height=225,left=400,top=45");
  window.opener = top
}
function SelectEvent(url, name) {

  popupWin = window.open(url, name, "menubar=no,toolbar=no,location=no,directories=no,status,scrollbars=yes, resizable=yes,dependent,width=700,height=500,left=400,top=45");
  window.opener = top
}
function SelectVenue(url, name) {

  popupWin = window.open(url, name, "menubar=no,toolbar=no,location=no,directories=no,status,scrollbars=yes, resizable=no,dependent,width=700,height=225,left=400,top=45");
  window.opener = top
}
function Clipboard(url, name) {

  popupWin = window.open(url, name, "menubar=no,toolbar=no,location=no,directories=no,status,scrollbars=yes, resizable=yes,dependent,width=250,height=600,left=400,top=45");
  window.opener = top
}
function BalanceSchedule(url, name) {

  popupWin = window.open(url, name, "menubar=no,toolbar=no,location=no,directories=no,status,scrollbars=yes, resizable=yes,dependent,width=450,height=700,left=400,top=45");
  window.opener = top
}

function SelectGameTime(url, name) {

  popupWin = window.open(url, name, "menubar=no,toolbar=no,location=no,directories=no,status,scrollbars=no, resizable=no,dependent,width=275,height=200,left=400,top=450");
  window.opener = top
}
function SelectGame(url, name) {

  popupWin = window.open(url, name, "menubar=no,toolbar=no,location=no,directories=no,status,scrollbars=no, resizable=no,dependent,width=275,height=200,left=400,top=450");
  window.opener = top
}


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.0
  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 && document.getElementById) x=document.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 isBlank(s){
var len=s.length
var i
for(i=0;i<len;++i){
if(s.charAt(i)!=" ") return false
}
return true
}

function validate(fieldName,fieldValue){
//alert(fieldName+" "+fieldValue);

if(isBlank(fieldValue)){
	alert(fieldName+" is required.")
	return false
	}
return true
}


function isPictureExt(string) {
if (string.search(/\.(jpg|gif)$/i) == -1)	// not valid ext
	return (false);
return(true)
}


function validateNumber(fieldName,fieldValue){
if(!isNumber(fieldValue)){
	alert(fieldName+" must be a number.")
	return false
	}
return true
}

function validateEmail(fieldName,fieldValue){
if(!isEmail(fieldValue)){
	alert(fieldName+" must be a valid email address.")
	return false
	}
return true
}

function validatePhone34(fieldName,fieldValue1,fieldValue2){
if(!isPhone3(fieldValue1) || !isPhone4(fieldValue2)){
	alert(fieldName+" is not a valid phone number.")
	return false
	}
return true
}


function validatePhone7(fieldName,fieldValue){
if(!isPhone7(fieldValue)){
	alert(fieldName+" must be a valid phone number in the form\nxxx-xxxx")
	return false
	}
return true
}



// support functions

function isNumber(string){
	if (string.search(/^\d+$/g) != -1)	// at least one digit
		return (true);
	else
		return(false);
}

function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

function isPhone7(string) {
    if (string.search(/^\d\d\d\-\d\d\d\d$/) != -1) 
         return true; 
     else
         return false;
}

function isPhone3(string) {
    if (string.search(/^\d\d\d$/) != -1) 
         return true; 
     else
         return false;
}

function isPhone4(string) {
    if (string.search(/^\d\d\d\d$/) != -1) 
         return true; 
     else
         return false;
}

function checkTextAreaSize(name,txtarea,maxsize) {
	z =	txtarea.value.length;
	if (z>maxsize) {
		alert("The "+ name +" field is limited to "+ maxsize +" characters, and the current size is "+ z +" characters.");
		return(false);
	}
	return(true);
}


/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
qq = new Date();
var maxYear=y2k(qq.getYear());

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function y2k(number) {
	return (number < 1000) ? number + 1900 : number;
}


function removeAllOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		//selectbox.options.remove(i);
		selectbox.remove(i);
	}
}


function addOption(selectbox, value, text,isSelected )
{
	var optn = document.createElement("OPTION");
	selectbox.options.add(optn);
	optn.text = text;
	optn.value = value;
	optn.selected = isSelected;
	
	
}


function getCheckedValue(radioObj) {
    if (!radioObj)
        return "";
    var radioLength = radioObj.length;
    if (radioLength == undefined)
        if (radioObj.checked)
        return radioObj.value;
    else
        return "";
    for (var i = 0; i < radioLength; i++) {
        if (radioObj[i].checked) {
            return radioObj[i].value;
        }
    }
    return "";
}
