﻿
/*
----------------------------------------------------
----------------------------------------------------
Methods for controlling popup divs.
----------------------------------------------------
------------------------------------------------------
*/
var Popup; //the control that is popped up

function ShowPopup(DivName, Anchor, XOffset, YOffset){
    //check if this div is already showing. If so, we'll hide it
    var alreadyVisible = false;
    if(document.getElementById(DivName).style.display==''){
        alreadyVisible = true; 
    }
    
    //first hide any existing popups
    HidePopup('');
    
    if(!alreadyVisible){
        //get the item we're popping up
        Popup = document.getElementById(DivName);
        
        //find the anchor point
        var Apoint = document.getElementById(Anchor);
            
        //get it's position 
        var x = Apoint.offsetLeft;
        var y = Apoint.offsetTop;
        
        var parent = Apoint;
	    while ((parent=parent.offsetParent) != null) {
	        x += parent.offsetLeft; 
	        y += parent.offsetTop;
	    }
    	   
        //calculate the popup's position
        x += XOffset;
        y += YOffset;
        
        
        Popup.style.left = x + "px";
        Popup.style.top = y + "px";
        
        //show it
        Popup.style.display='';
    }
}

function HidePopup(SkipDiv){
    //SkipDiv indicates which popup NOT to hide    
    if(Popup != null){
        if(Popup.id != SkipDiv){
            //if it exists, hide it
            Popup.style.display='none';
        }
    }
}

/*
----------------------------------------------------
----------------------------------------------------
Validation methods - used with CustomValidator controls
----------------------------------------------------
------------------------------------------------------
*/
function CheckDropDownSelected(sender, args){
	//this is the value from the control we're validating
    var selectedVal = args.Value;
    
    //do some checking.
    if(selectedVal == '-1'){
		//no selection was made
		args.IsValid = false;
		return;
    }    
      
	//it's valid
    args.IsValid = true;
}
function CheckIfCheckboxTicked(sender, args){
	  
    //do some checking.
    if(sender.checked == false){
		//no selection was made
		args.IsValid = false;
		return;
    }    
      
	//it's valid
    args.IsValid = true;
}
function PreventPastDate(sender, args){
	//this is the value from the control we're validating
    var selectedDate = new Date(args.Value);
    var todayDate = new Date();
    
    //do some checking.
    if(selectedDate < todayDate){
		//no selection was made
		args.IsValid = false;
		return;
    }    
      
	//it's valid
    args.IsValid = true;
}

/*
----------------------------------------------------
----------------------------------------------------
AJAX related methods
----------------------------------------------------
------------------------------------------------------
*/
function Cover(bottom, top, ignoreSize) {
	// Move an element directly on top of another element (and optionally
    // make it the same size)
    var location = Sys.UI.DomElement.getLocation(bottom);
    top.style.position = 'absolute';
    top.style.top = location.y + 'px';
    top.style.left = location.x + 'px';
    if (!ignoreSize) {
        top.style.height = bottom.offsetHeight + 'px';
        top.style.width = bottom.offsetWidth + 'px';
    }
}

/*
----------------------------------------------------
----------------------------------------------------
Misc. methods
---------------------------------------------------
------------------------------------------------------
*/

function popupWindow(url){
	var loc = url	
	newWindow = window.open(loc, "popup", "width=270,height=300,scrollbars=yes,toolbar=no,addressbar=no,resizable=no,menubar=no")
}

//prevent enter key from submitting page
function trapEnter(event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	
	if (keyCode == 13) {
		return false;
	} 
}
