/*===========================================================*/

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.01
  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 && d.getElementById) x=d.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 checkKeywordSearch(frm) {
    if(frm.new_keywds.value == "") {			  	
        alert("Please type in a keyword to search for activities.");
       
 	return false;
   
    }
   
    return true;
}

/*===========================================================*/

function checkRate(frm) {
    if(!isRadioButtonChecked(frm.rating)) {			  	
        alert("Please make a selction to rate this activity.");
       
 	return false;
   
    }
   
    return true;
}

/*===========================================================*/

function checkEmailFriend(frm) {
    var msg = "";
    if(frm.yourname.value == "")			
	msg += "    Your Name\n";
    if(frm.friendemail.value == "" || !isValidEmail(frm.friendemail))		
	msg += "    Friend's E-Mail Address\n";
    if(frm.friendname.value == "")				
	msg += "    Friend's Name\n";
    
    // Remove comment size limit 
    // Updated by: LY
    // Updated date: 07/29/2005
    
    // if(frm.comments.value.length > 100)				
	// msg += "    Comments: You may only enter 100 characters.\n";	
	
	// End of update
    
    if (msg != "") {	
        alert("Please enter valid information:  \n\n" + msg);
        return false;
    }
    return true;
}


/*===========================================================*/

function isValidEmail(email) {
    var isValid = 1;
    emailStr = email.value;
    if (emailStr.indexOf("@",1) == -1) isValid = 0;  // need @ symbol
    if (emailStr.indexOf(".",3) == -1) isValid = 0;  // need at least one "."
    if (emailStr.lastIndexOf(".") == (emailStr.length-1)) isValid = 0;  // can't end with a "."
        
    // test to make sure there's at least one character between "at" and "lastDot"
    if (isValid == 1) {
        var at = (emailStr.indexOf("@"))+1;
        var lastDot = (emailStr.lastIndexOf("."))+1;             
        if (lastDot - at == 1) isValid = 0;
    }

    if (isValid == 1) return true;
    else return false;
}

/*===========================================================*/

function isRadioButtonChecked(radio) {
    var isChecked = 0;
    for (i=0; i<radio.length; i++) {
        if (radio[i].checked) isChecked = 1;
    }

    if (isChecked == 1) return true;
	else return false;
}


/*===========================================================*/

function delete_activities() {
	
    var url = "delete.aspx?ids=";

    if (document.delete_form.checkbox.length>0) {
	for(var i=0; i<document.delete_form.checkbox.length; i++) {
	    if (document.delete_form.checkbox[i].checked) { 
	        url = url + document.delete_form.checkbox[i].value + "|";
	    }
        }
    } else if(document.delete_form.checkbox.checked == true) {
	url = url + document.delete_form.checkbox.value + "|";           
    }
 
    self.location.href = url;

}

/*===========================================================*/

function popUpWin(url, winName, width, height) {
    var features = "toolbar=no,menubar=no,scrollbars=yes,resizable=yes,width="+width+",height="+height+",top=200,left=200,screenX=200,screenY=200";
    window.open(url, winName, features);
}

function pop_up(url,name,props) {
    if(props == ""){
    	props='left=0,top=0,width=100,height=50';
    } 
    window.open(url, name, props);
}

/*===========================================================*/

function visibilityToggle(id, position) {
    if(document.getElementById(id)) {
	  document.getElementById(id).style.top = position + "px";
	  document.getElementById(id).style.left = "100px";
      document.getElementById(id).style.display = (document.getElementById(id).style.display == "none" ) ? "" : "none";
    } else {
      parent.document.getElementById(id).style.top = position + "px";
      parent.document.getElementById(id).style.left = "100px";
	  parent.document.getElementById(id).style.display = (parent.document.getElementById(id).style.display == "none" ) ? "" : "none";
    }
}


/*===========================================================*/

function getCheckedRadio(radio) {
    var id = "";
    if( !radio.length){
        if(radio.checked) {
            id = radio.value;
        }
    }else{
        for (i=0; i<radio.length; i++) {
            if (radio[i].checked) {
	            id = radio[i].value;
	        }
        }
    }
    return id;
}

/*===========================================================*/

function goto_page (frm, page) {
    if(getCheckedRadio(frm) == "") {
        alert("Please select an activity.");
    } else {      
        var url = page + "?id=" + getCheckedRadio(frm);
	    if(page == "detail.aspx" || page == "detail_unplugged.aspx") 
	    {
	        if((getCheckedRadio(frm) >=380 && getCheckedRadio(frm) <= 414) ||(getCheckedRadio(frm)==339 || getCheckedRadio(frm)==343 || getCheckedRadio(frm)==344 || getCheckedRadio(frm)==354))
	        {
	            url="detail_unplugged.aspx?id=" + getCheckedRadio(frm);
	        }
	        else
	        {
	            url="detail.aspx?id=" + getCheckedRadio(frm);
	        }
	    parent.location.href = url;
	    } 
	    
	    else
	    {
            self.location.href = url;
	    }
    }
}

