/**
 * @author Tim
 * Script here manages display on the public clan page
 */	
	var bClanHistory; // Bool for Clan History display toggle
	
	// Toggles display of Clan History DIV
	function DisplayClanHistory () {
		if(!bClanHistory)
		{
			new Effect.SlideDown('ClanHistory');
			new Effect.Appear('ClanHistory');
			bClanHistory = true;
		}
		else
		{
			new Effect.SlideUp('ClanHistory');
			new Effect.Fade('ClanHistory');
			bClanHistory = false;
		}
	}
	
    var bAwardDetailsDisplayed; // Bool for Award Detail information popup toggle
	
	// Shows Award Details
	function ShowAwardDetails(newtop, newleft){
		if(!bAwardDetailsDisplayed)
		{
			el = document.getElementById('ClanAwardDetails');
			el.style.top = newtop + 'px';
			el.style.left = newleft + 'px';
			new Effect.Appear('ClanAwardDetails');
			bAwardDetailsDisplayed = true;	
		}
		else
		{
			HideAwardDetails();
			bAwardDetailsDisplayed = false;
		}
		
	}
	
	// Hides Award Details
	function HideAwardDetails()
	{
			new Effect.Fade('ClanAwardDetails');
			bAwardDetailsDisplayed = false;
	}
	
	// Grabs the X position for a given object, used to place popups
	function findPosX(obj) {
		var curleft = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft
			}
		}
		return curleft;
	}
	
	// Grabs the Y position for a given object, used to place popups 
	function findPosY(obj) {
		var curtop = 0;
		if (obj.offsetParent) {
			curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
				curtop += obj.offsetTop
			}
		}
		return curtop;
	}

    var ClanHistoryToggle = false;

    function DisplayClanHistory(){

        
        if (!ClanHistoryToggle){
            new Effect.Appear("ClanHistory")
            ClanHistoryToggle = true;
        }
        else
        {
            new Effect.Fade("ClanHistory")
            ClanHistoryToggle = false;
        }
    }
    
var timeconversionToggle;

function ShowTimeConversion(dt){

    var winl = (screen.width-760)/2;
    var wint = (screen.height-160)/2;    
    settings='height=160,width=380,top=' + wint + ',left=' + winl + ',scrollbars=0,statusbars=0,toolbars=0,resize=1';
    
    now = new Date();
    var offset = (now.getTimezoneOffset() / 60)*-1;
    
    win=window.open('GMTConv.aspx?offset=' + offset + '&dt=' + dt,"",settings)
    
}

function ShowPublicChallengeSelection(id){
                var sel = document.getElementById(id);
                if (sel != null){
                    if (sel.style.display == "none")
                        sel.style.display = "block";
                    else
                        sel.style.display = "none";
                }
            }

function ShowCRecord(hideid,showid){
    if (document.getElementById(showid) != null && document.getElementById(hideid) != null){        
               
        new Effect.Fade(hideid);                  
        setTimeout("new Effect.Appear('" + showid + "')",1000);
    }
    else{
        alert('No record for selected season');
    }
}
function nothing(){}

function CalcTimeZone(matchdate,id){

    if (matchdate == '')
        alert('please enter date')
    else{
    var tmz = document.getElementById(id);
    
    var qstring = 't=' + matchdate + '&utc=' + tmz.value;
    document.getElementById('TimeZoneDisplay').style.display = "none";
    
	var PNCAjax = new TimeZoneAjaxSendRequest(qstring,'TimeZoneDisplay');
	PNCAjax.delSendRequest(); 
    }
    
	
}

function ShowMatchDetails(mid){
    window.location = 'ClanSchedule.aspx?mID=' + mid;
}

function AcceptClanWarChallenge(id){
    
    
    if (document.getElementById(id).checked){
        //AcceptDenyClanWar('acceptwar=1');
        window.location='ScrimSetup.aspx?accept=1&url=' + document.URL.toString();    
    }
    
    else        
    {
        //AcceptDenyClanWar('acceptwar=0');
        window.location='ScrimSetup.aspx?accept=0&url=' + document.URL.toString();    
    }
    
}

function AcceptDenyClanWar(querystring)
{
    this.querystring = querystring;
    var me = this;
    this.delSendRequest = function()
    {
		var xmlHttpReq = false;
        var ajaxcall = new BaseAjaxUpdater();
        // Mozilla/Safari
        if (window.XMLHttpRequest) {
            ajaxcall.xmlHttpReq = new XMLHttpRequest();
        }
        // IE
        else if (window.ActiveXObject) {
            ajaxcall.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
        
        ajaxcall.xmlHttpReq.open('POST', "ShowClan.aspx", true);
        ajaxcall.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        ajaxcall.xmlHttpReq.onreadystatechange = function() {
            if (ajaxcall.xmlHttpReq.readyState == 4) {
                if (ajaxcall.xmlHttpReq.status == 200)
                {
                    alert('thanks');	
                }
            }
        }        
        alert(me.querystring);
        ajaxcall.xmlHttpReq.send(me.querystring);
    }
}

function TimeZoneAjaxSendRequest(querystring,id)
{
    this.querystring = querystring;
    var me = this;
    this.delSendRequest = function()
    {
		var xmlHttpReq = false;
        var ajaxcall = new BaseAjaxUpdater();
        // Mozilla/Safari
        if (window.XMLHttpRequest) {
            ajaxcall.xmlHttpReq = new XMLHttpRequest();
        }
        // IE
        else if (window.ActiveXObject) {
            ajaxcall.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
        
        ajaxcall.xmlHttpReq.open('POST', "TimeZone.aspx", true);
        ajaxcall.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        ajaxcall.xmlHttpReq.onreadystatechange = function() {
            if (ajaxcall.xmlHttpReq.readyState == 4) {
                if (ajaxcall.xmlHttpReq.status == 200)
                {
                    
					if(ajaxcall.xmlHttpReq.responseText != '')
					{
					    document.getElementById(id).innerHTML = "<font color=white>Zone selected: </font><br/>" + ajaxcall.xmlHttpReq.responseText;
					    document.getElementById(id).innerHTML += " <input type=button onclick=\"window.location=location.href\" class='StandardButton' value='Reset'>";
					    new Effect.Appear(id);							    
					    
					}
					
                }
            }
        }        
        ajaxcall.xmlHttpReq.send(me.querystring);
    }
}
