
// IE 6 only - safari, firefox, IE7 handle min/max widths. 
// Split the string into part [0] and part [1]
var temp=navigator.appVersion.split('MSIE');

// Parse the string for the "6" in 6.0
var ieVer=parseInt(temp[1]);

// Is it greater than 6?
var isIE6down=(ieVer <= 6)?1:0;

if (isIE6down) {
    //window.onload   = checkAvailableWidth;
    //window.onresize = checkAvailableWidth;
}

function checkAvailableWidth(){
	//var main = document.getElementById("main");
	//main.style.width = (document.body.clientWidth < 800? "780px" : document.body.clientWidth > 980? "960px" : "auto");		
	
}

var __isFireFox = navigator.userAgent.match(/gecko/i); 
//returns the absolute position of some element within document  
function GetElementAbsolutePos(element) {  
 var res = new Object();  
 res.x = 0; res.y = 0;  
 if (element !== null) {  
     res.x = element.offsetLeft;   
     res.y = element.offsetTop;   
       
     var offsetParent = element.offsetParent;  
     var parentNode = element.parentNode;  

     while (offsetParent !== null) {  
         res.x += offsetParent.offsetLeft;  
         res.y += offsetParent.offsetTop;  

         if (offsetParent != document.body && offsetParent != document.documentElement) {  
             res.x -= offsetParent.scrollLeft;  
             res.y -= offsetParent.scrollTop;  
         }  
         //next lines are necessary to support FireFox problem with offsetParent  
         if (__isFireFox) {  
             while (offsetParent != parentNode && parentNode !== null) {  
                 res.x -= parentNode.scrollLeft;  
                 res.y -= parentNode.scrollTop;  
                   
                 parentNode = parentNode.parentNode;  
             }      
         }  
         parentNode = offsetParent.parentNode;  
         offsetParent = offsetParent.offsetParent;  
     }  
 }  
 return res;  
}  




function spawnPopupWindow(url, nameW, w, h, sb, re, tb, st, x, y) 
{
	var win = window.open(url, nameW, 'width='+w+',height='+h+',scrollbars='+sb+',resizable='+re+',menubar=0,toolbar='+tb+',status='+st+',location=0,directories=0,left=' + x + ',top=' + y + '');
	win.focus();
}

function returnKeyHandler(e, handlerFunc)
{			
	
	if (handlerFunc != null)
	{				
		if (returnKeyPressed(e))
		{			
			handlerFunc();			
		}	
	}	
}

function returnKeyPressed(e)
{			
	if (document.all) 
		{
		e = window.event;
		}	
	
	var key;	
		
	if (document.layers)
		key = e.which;
	if (document.all)
		key = e.keyCode;	
	
	if(key == undefined);
		{
		if (e.which != undefined)
			key = e.which;
		
		if(key == undefined);
			{
				if (e.keyCode != undefined)
					key = e.keyCode;
			}	   
		}
	
	if (key==13)
		{					
			return true;
		}		
	
	return false;
}

function hidePreview(divId)
{
    var div = document.getElementById(divId);
    div.style.display = 'none';     
}

function showPreview(imgId, divId, src)
{
    var img = document.getElementById(imgId);        
    var div = document.getElementById(divId);
            
    if (div != null)
    {               
        var imgPreview = div.firstChild;
        if (imgPreview.src == loading)
        {   
            div.style.height = imgPreview.style.height;
            div.style.width = imgPreview.style.width;
            imgPreview.src = src;
        }
        else if (imgPreview.src == src)
        {   
            if (imgPreview.complete)
            {
                div.style.height = imgPreview.height + 'px';
                div.style.width = imgPreview.width + 'px';
                div.style.display = 'block';
                if (isIE6down)
                {
                    div.style.left =  pos.x + (img.width/2) + 'px';
                    div.style.top = pos.y + (img.height/2) + 'px';
                }
            }
            else
            {
                setTimeout ( "showPreview('" + imgId + "', '" + divId + "', '" + src + "')", 50 );
            }
        }
        else
        {
            imgPreview.src = loading;
            var pos = GetElementAbsolutePos(img);
            div.style.display = 'block';
            setTimeout ( "showPreview('" + imgId + "', '" + divId + "', '" + src + "')", 50 );
        }
    }
}


function ShowHide(id, flagid)
{
		var flagctl = null;
		if (flagid != null)
			flagctl = document.getElementById(flagid);
					
		if (document.getElementById(id).style.display == "none")
		{
			document.getElementById(id).style.display = 'block';
			if (flagctl != null)
				flagctl.value = 1;
		} 
		else 
		{
			document.getElementById(id).style.display = 'none';	
			if (flagctl != null)
				flagctl.value = 0;
		}
		
		return false;
}	

function getXForElement(oElement)
{
    var iReturnValue = 0;
    while(oElement != null) 
    {
        iReturnValue += oElement.offsetLeft;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}

function getYForElement(oElement)
{
    var iReturnValue = 0;
    while(oElement != null) 
    {
        iReturnValue += oElement.offsetTop;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}


 // Function to find all checkboxes in a repeater and select or deselect them
 // this function would be the onclick event handler for the "CheckAll" check box control
 // rptrObj - Repeater name
 // chkAllId - check all checkboxes client id.
 function checkAll(rptrObj,chkAllId)
 {
    var inputs = document.getElementsByTagName('input');
    for(var i=0; i<inputs.length; i++)
    {
        if(inputs[i].type=='checkbox' && inputs[i].name.indexOf(rptrObj) != -1)
        {
            inputs[i].checked=document.getElementById(chkAllId).checked;
        }
    }
}
 
// function to revert the check all checkbox value depending on the
// individual row check box values in the repeater
// this would be the onclick event handler for individual row check boxes.
// chkId - check box client id 
// chkAllId - "Check All" checkbox client id
// rptrobj - name of the repeater.
function revertChkAll(chkId, chkAllId,rptrObj)
{
    if(document.getElementById(chkId).checked)
    {
        var chkCount = 0;
        var inputs = document.getElementsByTagName('input');
        for(var i=0; i<inputs.length; i++)
        {
            if(inputs[i].type=='checkbox' && inputs[i].id != chkAllId && inputs[i].name.indexOf(rptrObj) != -1 && !(inputs[i].checked))
            {
                chkCount++;
                break;
            }
        }
        if(chkCount==0)
        {
            document.getElementById(chkAllId).checked = true;
        }
        else
        {
            document.getElementById(chkAllId).checked = false;
        }
    }
    else
    {
        document.getElementById(chkAllId).checked = false;
    }
}
 

function setlogincalllback()
{   
    document.getElementById('performlogin').value = 1;
}


/*
Javascript functions to run at client - show hide content, explicitly client side.
*/

var maskpanel=function()
{
    this.divobj;
    this.show=function(contentid, focusTarget)
    {
        if(!document.getElementById("mask"))
        {
            var mainform = document.getElementById("aspnetForm");

            var divEle=document.createElement('div');
            divEle.setAttribute("id","mask");
            document.body.insertBefore(divEle, mainform);
        }

        this.divobj=document.getElementById("mask");
        this.divobj.className = "png_bg";

        var dsh=document.documentElement.scrollHeight;
        var dch=document.documentElement.clientHeight;
        var dsw=document.documentElement.scrollWidth;
        var dcw=document.documentElement.clientWidth;

        var bdh=(dsh>dch)?dsh:dch;
        var bdw=(dsw>dcw)?dsw:dcw;

        var cdiv = document.getElementById(contentid);
        this.divobj.style.height=bdh+'px';
        this.divobj.style.width=bdw+'px';
        $('#mask').fadeIn();
        $('#'+contentid).slideDown(function() {
                                                if (focusTarget) {
                                                    $('#'+focusTarget).focus();
                                                }
                                              });

    };
    this.hide=function(contentid)
    {
        var cdiv = document.getElementById(contentid);
        this.divobj.style.display=cdiv.style.display="none";
    };
}

function fixIEzIndex(newParent) {
    
    jQuery('.popupdiv').each(
        function() {
            $.thisItem = jQuery(this);
            jQuery(this).parents().each(
                function() {
                    if (jQuery(this).css('position') == 'relative') {
                        var pTop = jQuery(this).offset().top;
                        var pLeft = jQuery(this).offset().left;
                        $.thisItem.offset(jQuery(this).offset());
                        $.thisItem.appendTo(newParent);
                        return false;
                    }
                }
            );
        }
    );
    
}

function movechild(parentid, itemid) {

    var childitem = document.getElementById(itemid);
    var newparent = document.getElementById(parentid);
    if (newparent) {
        childitem.parentNode.removeChild(childitem);
        newparent.appendChild(childitem);
    }
}

function setupExpanders() {

    $('.expander_trigger').click(
        function(event) {
            event.preventDefault();
            $(this).closest('.expander_div').find('.expander_content').toggle("fast");
            $(this).closest('.expander_div').toggleClass("expander_closed");
            //Toggle expand/collapse all
            var count = 0;
            var numElem = 0;
            $('.expander_div').each(
                function(){
                numElem = numElem + 1;
                if(($(this).hasClass("expander_closed")))
                    {
                        count = count + 1;
                    }
                });
            if(count == 0)
            {
                $('.expand_collapse_all').text("Collapse All");
            }
            else if (count == numElem)
            {
                $('.expand_collapse_all').text("Expand All");
            }
        }
    );
    
    $('.expander_closed').each(
        function() {
            $(this).find('.expander_content').toggle("fast");
        }
    );
    
    $('.expand_collapse_all').click(
        function(){
            if(($(this).text() == "Expand All"))
            {
                $('.expander_div').each
                    (
                        function() 
                        {
                            if(($(this).hasClass("expander_closed")))
                            {
                                $(this).closest('.expander_div').find('.expander_content').toggle("fast");
                                $(this).closest('.expander_div').toggleClass("expander_closed");
                            }
                        }
                );
               $(this).text("Collapse All")
            }
            else if(($(this).text() == "Collapse All"))
            {
                $('.expander_div').each
                (
                    function() 
                    {
                        if(!($(this).hasClass("expander_closed")))
                        {
                            $(this).closest('.expander_div').find('.expander_content').toggle("fast");
                            $(this).closest('.expander_div').toggleClass("expander_closed");
                        }
                    }
                );
               $(this).text("Expand All")
            }
        }
    );
}

function setupPopups() {

    $('.popupdiv').addClass("popupdiv_hidden");
}


function pagesetup() {
    setupExpanders();
    setupPopups();
}


function showdiv(strDiv, strPrefix) {

	if ((document.getElementById(strPrefix + strDiv).style.visibility == 'hidden') || (document.getElementById(strPrefix + strDiv).style.visibility == '')) {
		
		hideallcontentdivs(strPrefix);	
		
		document.getElementById(strPrefix + strDiv).style.visibility    = 'visible';
		document.getElementById(strPrefix + strDiv).style.display       = 'block';				
		
	}		
}	

function hideallcontentdivs(strPrefix) {

	var el, i;
	i = 1;
	
	while (el = document.getElementById(strPrefix + i)) {
	
		document.getElementById(strPrefix + i).style.visibility = 'hidden';
		document.getElementById(strPrefix + i).style.display = 'none';
		
		i++;
	}	
}


function getElementByClass(oldClass, newClass) 
{
    var allHTMLTags = new Array();

    var allHTMLTags=document.getElementsByTagName("*");

    for (i=0; i<allHTMLTags.length; i++) 
    {
        if (allHTMLTags[i].className==oldClass) 
        {
            allHTMLTags[i].className=newClass;
        }
    }
}

function getCookie(cookieName) {
    if (0 < document.cookie.length) {
        cookieIndex = document.cookie.indexOf(cookieName + "=");
        if (-1 != cookieIndex) {
            cookieIndex = cookieIndex + cookieName.length + 1;
            cookieEnd = document.cookie.indexOf(";",cookieIndex);
            if (-1 == cookieEnd) cookieEnd = document.cookie.length;
            return unescape(document.cookie.substring(cookieIndex,cookieEnd));
        }
        return "";
    }
    return "";
}


function fillFilePath(url, targetID) {
    var targetField = opener.document.getElementById(targetID);
    targetField.value = url;
    self.close();
}