﻿function $(id){
    return document.getElementById(id);
}

 
var TEMPTROBJCOLOR ;
var TEMPTROBJ;

function HLon(obj)
{
	if (TEMPTROBJ != null)
	{
		TEMPTROBJ.style.backgroundColor = TEMPTROBJCOLOR; 
	} 
	TEMPTROBJ = obj;
	TEMPTROBJCOLOR = obj.style.backgroundColor;
	obj.style.backgroundColor = '#cfe3ff';
}

function HLoff()
{	
	if (TEMPTROBJ != null)
	{
		TEMPTROBJ.style.backgroundColor = TEMPTROBJCOLOR; 
	}	
}
 function checkImage(A){
        A.style.display="inline";
} 
var DDSPEED = 10;
var DDTIMER = 15;

// main function to handle the mouse events //
function ddMenu(id,d){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearInterval(c.timer);
  if(d == 1){
    clearTimeout(h.timer);
    if(c.maxh && c.maxh <= c.offsetHeight){return}
    else if(!c.maxh){
      c.style.display = 'block';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';
    }
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }else{
    h.timer = setTimeout(function(){ddCollapse(c)},50);
  }
}

// collapse the menu //
function ddCollapse(c){
  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
}

// cancel the collapse if a user rolls over the dropdown //
function cancelHide(id){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(c,d){
  var currh = c.offsetHeight;
  var dist;
  if(d == 1){
    dist = (Math.round((c.maxh - currh) / DDSPEED));
  }else{
    dist = (Math.round(currh / DDSPEED));
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  c.style.height = currh + (dist * d) + 'px';
  c.style.opacity = currh / c.maxh;
  c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
  if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    clearInterval(c.timer);
  window.status = currh+':'+d;
  }
}

function openWin(strURL, arg1, arg2, arg3)
{
		var argLen = arguments.length;
		var intX,intY,strUrl;
		if(argLen < 3){
			intX = '780';
			intY = '550';
		}else{
			intX = arg2;
			intY = arg3;
		}
		if(strURL.indexOf('?') != -1)
			strURL += "&popUp=1";
		else
			strURL += "?popUp=1";

		var oWin = window.open ( strURL, arg1, "toolbar=no, menubar=no, location=no, status=no, width=" + intX + ", height=" + intY + ",left=0, top=0, scrollbars=yes, resizable=yes");
		oWin.focus();
}

function HORSE(horseId)
{
	    openWin(Beygir.appPath+'/Popups/HorsePopups/HorseRace.aspx?refId='+horseId,"",1000,800);
}

function HR(date,city,raceNo,horseId)
{
	    openWin(Beygir.appPath+'/Popups/HorsePopups/HorseRace.aspx?tarih='+date+'&sehir='+city+'&kosuNo='+raceNo+'&atRefId='+horseId,"",800,800);
}
function openVideo(videoId)
{
	    openWin(Beygir.appPath+'/Popups/HorsePopups/HorseRace.aspx?video='+videoId,"",800,800);
}

function HRD(date,city,raceNo,horseId,video)
{
	    openWin(Beygir.appPath+'/Popups/HorsePopups/HorseRaceDetail.aspx?date='+date+'&city='+city+'&no='+raceNo+'&horseId='+horseId+'&video='+video,"",800,800);
}

function HSH(horseId)
{
	    HORSE(horseId);
}

function OWNER(ownerId)
{
	    openWin(Beygir.appPath+'/Popups/OwnerPopups/OwnerPopup.aspx?gender=0&ownerId='+ownerId ,"",1000,800);
}
function RAISER(raiserId)
{
	    openWin(Beygir.appPath+'/Popups/RaiserPopups/RaiserPopup.aspx?gender=0&raiserId='+raiserId,"",1000,800);
}
function JOCKEY(jokId)
{
	    openWin(Beygir.appPath+'/Popups/JockeyPopups/Jockey.aspx?jokId='+jokId,"",1000,800);
}  
function TRAINER(AntId)
{
	    openWin(Beygir.appPath+'/Popups/TrainerPopups/Trainer.aspx?antId='+AntId,"",1000,800);
}
function GO(date,city,raceNo)
{
	    openWin(Beygir.appPath+'/Popups/GalopPopups/GalopSummary.aspx?date='+date + '&city='+city+'&raceNo='+raceNo,"",800,800);
}

function FORUM(forumId)
{
	    openWin(Beygir.appPath+'/Forum/Forum.aspx?forumId='+forumId,"",1000,800);
}

function HC(date,city,raceNo)
{
	    openWin(Beygir.appPath+'/Popups/HorsePopups/HorseComparison.aspx?date='+date + '&city='+city+'&raceNo='+raceNo,"",800,800);
}

function RESULT(date,city,raceNo)
{
	    openWin(Beygir.appPath+'/Bulletin/BulletinRaceResult.aspx?date='+date + '&city='+city+'&raceNo='+raceNo,"",800,800);
}

function JSTAT(date,city,raceNo,gender)
{
	    openWin(Beygir.appPath+'/Popups/JockeyPopups/JockeyStats.aspx?date='+date + '&city='+city+'&raceNo='+raceNo+'&gender='+gender,"",800,800);
}

function HSTAT(date,city,raceNo,gender)
{
	    openWin(Beygir.appPath+'/Popups/HorsePopups/HorseStatsBulletin.aspx?date='+date + '&city='+city+'&raceNo='+raceNo+'&gender='+gender,"",800,800);
}

function TSTAT(date,city,raceNo,gender)
{
	    openWin(Beygir.appPath+'/Popups/TrainerPopups/TrainerStats.aspx?date='+date + '&city='+city+'&raceNo='+raceNo+'&gender='+gender,"",800,800);
}

function OSTAT(date,city,raceNo,gender)
{
	    openWin(Beygir.appPath+'/Popups/OwnerPopups/OwnerStats.aspx?date='+date + '&city='+city+'&raceNo='+raceNo+'&gender='+gender,"",800,800);
}

function HRTIME(date,city,raceNo,gender,distance,track)
{
	    openWin(Beygir.appPath+'/Popups/HorsePopups/HorseRaceTime.aspx?date='+date + '&city='+city+'&raceNo='+raceNo+'&gender='+gender+'&distance='+distance+'&track='+track,"",800,600);
}

function BulletinSTAT(city,group,groupName,track,raceClass)
{
	    openWin(Beygir.appPath+'/Statistics/GroupStatistics.aspx?city='+ city + '&group='+group + '&groupName='+groupName +'&track='+track +'&raceClass='+ raceClass,"",800,800);
}

function CUP(date,city,raceNo) {
    if (!date){
        var now = new Date();
        date = now.toDateString("dd.MM.yyyy");
    }
    if(!city)
        city = 1;
	openWin(Beygir.appPath+'/Bulletin/BulletinCupResults.aspx?date='+date + '&city='+city+'&raceNo='+raceNo ,"",800,800);
}
function NEWS(id)
{
	   location.href =Beygir.appPath+'/News/NewsDetail.aspx?newsId='+id;
}
function SRCH(key)
{
	      location.href =Beygir.appPath+'/Search/SearchResult.aspx?key='+key;
}
function SRCHHORSE(key)
{
	      location.href = Beygir.appPath+'/Search/HorseSearch.aspx?key='+key;
}
function SRCHORIGIN(keya,keyb)
{
	      location.href = Beygir.appPath+'/Search/OriginSearch.aspx?a='+keya+'&b='+keyb;
}
function SRCHOWNER(key)
{
	      location.href = Beygir.appPath+'/Search/OwnerSearch.aspx?key='+key;
}
function SRCHRAISER(key)
{
	      location.href = Beygir.appPath+'/Search/RaiserSearch.aspx?key='+key;
}
function MUHTEMEL(date,city,raceNo,type,game)
{
	    openWin( Beygir.appPath+'/PossibleRatios/LineChart.aspx?date='+date + '&city='+city+'&raceNo='+raceNo+'&type='+type+'&game='+game,"",600,400);
}

function HIPODROM(cityId)
{
	    openWin(Beygir.appPath+'/Bulletin/Hipodrom.aspx?cityId='+cityId,"",900,500);
} 
function SRCHJOCKEY(key)
{
	      location.href = Beygir.appPath+'/Search/JockeySearch.aspx?key='+key;
}
function SRCHTRAINER(key)
{
	      location.href = Beygir.appPath+'/Search/TrainerSearch.aspx?key='+key;
}
function SRCHCUP(key)
{
	      location.href = Beygir.appPath+'/Search/RaceInfoSearch.aspx?key='+key;
}
function SRCHNEWS(key)
{
	   location.href =Beygir.appPath+'/News/NewsList.aspx?key='+key;
}


var StringBuilder=function(){
    this._strings=[];
    this.append=function(s){this._strings.push(s);};
    this.appendFormat=function(f){
        var s=f;
        for (i=1;i<arguments.length;i++) {
            var str = new RegExp("\\{" + (i-1) + "\\}", "g");
            s= s.replace(str,arguments[i]);
        }            
        this._strings.push(s);
    };
    this.toString=function(){return this._strings.join('');};} 