// service routines
// *****************************************************************************
brIE = "Microsoft Internet Explorer"; brNS = "Netscape"; brOP = "Opera"; brN = "undefined"; brM = 1 ; brV=0;
if (navigator.appName == brIE) {brN = "IE"; brV = parseFloat(navigator.appVersion.substr (navigator.appVersion.lastIndexOf("MSIE") + 4, 4)); brM = 1;}
if (navigator.appName == brNS) {brN = "NS"; brV = parseFloat(navigator.appVersion.substr(0,4)); brM = 2;}
if (navigator.appName == brOP) {brN = "OP"; brV = parseFloat(navigator.appVersion.substr(0,4)); brM = 1;}
if (brN == 'NS' && brV >= 5) {brM = 3;}


var popUpWin=0;
function popUpImage(URLStr)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open("popup.asp?url=" + URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=640,height=480,top=0,left=0,screenX=,screenY=0');
}

function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function setCookie(name,value,hours) {
  var expire = "";
  expire = new Date((new Date()).getTime() + hours * 3600000);
  expire = "; expires=" + expire.toGMTString();
  document.cookie = name + "=" + escape(value) + expire;
  return true;
}


function doBookmark(TheID, TheTitle) {
  bookmarkurl="http://www.ta3km.org/index.asp?id=" + TheID
  if (document.all) window.external.AddFavorite(bookmarkurl,TheTitle)
  else if (window.sidebar) window.sidebar.addPanel(TheTitle, bookmarkurl, "");
}


function GetObj(theObj, theDoc) {  
  var p, i, foundObj;
	foundObj = null;
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  return foundObj;
}

function GetVis(o) {
	tmpGV = false;
	if (o.style) tmpGV = (o.style.visibility=="show" || o.style.visibility=="visible");
	if (o.visibility) tmpGV = (o.visibility=="show" || o.visibility=="visible");
	return tmpGV;
}

function SetVis() { 
  var i,p,v,obj,args=SetVis.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=GetObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}	

function Show(TheID) { SetVis(TheID,'','show') }  
function Hide(TheID) { SetVis(TheID,'','hide') }  

function GetX(o) {
  if(brN == 'NS') {
    if(brV == 5) return(parseInt(o.style.left));
    if(brV == 4) return(o.left);
  } else { return(o.style.pixelLeft); }
}

function GetY(o) {
  if(brN == 'NS') {
		if(brV == 5) return(parseInt(o.style.top));
		if(brV == 4) return(o.top);
  } else { return(o.style.pixelTop); }
}

function GetW(o) {
if(brN == 'NS') {
		if(brV == 5) return(o.offsetWidth);		     
    if(brV == 4) return(o.clip.width);                      
  } else { 
	  if(navigator.appVersion.indexOf('MSIE 4') > 0) return(o.style.pixelWidth);
		else return(o.offsetWidth); 
	}
}

function GetH(o) {
if(brN == 'NS') {
		if(brV == 5) return(o.offsetHeight);		     
    if(brV == 4) return(o.clip.height);                      
  } else { 
	  if(navigator.appVersion.indexOf('MSIE 4') > 0) return(o.style.pixelHeight);
		else return(o.offsetHeight); 
	}
}

function getImageWidth(myImage) {
	var x, obj;
	if (document.layers) {
		var img = getImage(myImage);
		return img.width;
	} else {
		return getElementWidth(myImage);
	}
	return -1;
}

function Move(x, y, o) {
  if(brN == 'NS') {
    if(brV == 5) { o.style.left = x + "px"; o.style.top = y + "px"; }
    if(brV == 4) { o.left = x + "px"; o.top = y + "px";}
  } else {	
    o.style.pixelLeft = x; o.style.pixelTop = y; 
	}
}

function Size(x, y, o) {
  if(brN == 'NS') {
    if(brV == 5) { o.style.width = x + "px"; o.style.height = y + "px";}
    if(brV == 4) { o.width = x + "px"; o.height = y + "px"; }
  } else { o.style.width = x; o.style.height = y; }
}

var winW = 630, winH = 460, posX=10, posY=10, imgH=240, imgW=320;

function GetGeo() {
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    winW = window.innerWidth;
    winH = window.innerHeight;
    posY = document.body.scrollTop;
    posX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    winW = document.documentElement.clientWidth;
    winH = document.documentElement.clientHeight;
    posY = document.body.scrollTop;
    posX = document.body.scrollLeft;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    winW = document.body.clientWidth;
    winH = document.body.clientHeight;
    posY = document.body.scrollTop;
    posX = document.body.scrollLeft;
  }
	imgW = GetW(GetObj("divImage"));
	imgH = GetH(GetObj("divImage"));
}

function RefreshGeo() {
	GetGeo();
	Move(posX+winW/2-imgW/2, posY+winH/2-imgH/2, GetObj("divImage"))
	setTimeout("RefreshGeo()",1000)
}

function init() {
	initClock(); 
	setTimeout("RefreshGeo()",1000)
}

function AlternateImage(TheFile) {
	GetObj("imgSlot").src = TheFile;
}

// menu
// *****************************************************************************

var LastMenu = 0;

function OpenMenu(TheID) {
	document.getElementById("dMenuSlot").innerHTML = document.getElementById("ms" + TheID).innerHTML
	if (LastMenu!=0) {GetObj("imgMenu" + LastMenu).src="/images/api/blt-none.gif"; }
	GetObj("imgMenu" + TheID).src="/images/api/blt-silver.gif";
	LastMenu = TheID;
	setCookie("LastMenu",TheID, 1);
}

function HoverMenu(TheID,TheState) {
	if (TheState) {tmpColor="#666666"} else {tmpColor="#979392"}
	if (LastMenu==TheID) {GetObj("imgMenu" + TheID).src="/images/api/blt-dark.gif";}
	GetObj("trRow" + TheID).style.backgroundColor=tmpColor;
}

var PageArray = new Array()
var PageModes = new Array()
var PageCnt = 0; 
var PageID = 0;
var isBacking = false;

function doBack() {
	if (PageCnt>1) {
		PageCnt=PageCnt-1;
		isBacking = true;
		LinkIt(PageArray[PageCnt], PageModes[PageCnt]);
		isBacking = false;
		} else {document.location.href="/index.asp";}
}

function LinkIt(TheID, TheKind) {
try {
var pageTracker = _gat._getTracker("UA-7278444-1");
pageTracker._trackPageview("id-" + TheID);
} catch(err) {
	}
	document.location.href= "/index.asp?id=" + TheID ;
}

function doZoneCombo(TheSelect) {
	 LinkIt(TheSelect.value, 1);
}

var pCls=new Array();
pCls[0]=true;
pCls[1]=true;
pCls[2]=true;
pCls[3]=true;
pCls[4]=true;
pCls[5]=true;
pCls[6]=true;
pClsCnt=7;

function ListProjects(TheClasses, ThePage, TheKey) {
	if (TheClasses=="ALL") {TheClasses = "99"}
  ajaxpage("/project.asp?cmd=l&c=" + TheClasses + "&pg=" + ThePage + "&key=" + TheKey, "scrollContent");
}

function SearchKey(TheKey) {
	ListProjects("99", 1, TheKey)
}

function NavigateProjects(TheClasses, TheID, TheKey, TheState) {
	if (TheClasses=="ALL") {TheClasses = "99"}
  ajaxpage("/project.asp?cmd=n&c=" + TheClasses + "&id=" + TheID + "&key=" + TheKey + "&state=" + TheState, "scrollContent");
}

function ToogleProClass(TheClass) {
	pCls[TheClass] = !pCls[TheClass]
	oneSelected = false;
	for(var i=1;i < pClsCnt;i++) {
		if (pCls[i]) {oneSelected = true}
	}
	if (!oneSelected) {pCls[TheClass] = true}
	if (pCls[TheClass]) {tmpPimg="/images/api/procons/gry-p" + TheClass + ".jpg"} else {tmpPimg="/images/api/procons/p" + TheClass + ".jpg"}
	GetObj("imgPc" + TheClass).src = tmpPimg;
  doProjectFilter();
}


function doProjectSearchBoxKeyDown(e) {
	if (window.event) {keynum = e.keyCode; } else if (e.which) { keynum = e.which; };
	if (keynum==13) {doProjectFilter();return false;} else return true;
}

function doProjectSearchBoxChange() {
	if (GetObj("fKeys").value=="") {theSbImg="btn-go-dis.jpg"} else  {theSbImg="btn-go.jpg"}
	GetObj("imgSearchButton").src = "/images/api/procons/" + theSbImg;
}

function doProjectFilter() {
  doProjectSearchBoxChange()
	tmpClassList = "99,"
	for(var i=1;i < pClsCnt;i++) {
		if (pCls[i]) {tmpClassList = tmpClassList + i + ","}
	}
	tmpClassList = tmpClassList + "99"
	ListProjects(tmpClassList, 0, GetObj("fKeys").value)
}
	
function ShowProject(TheID) {
	tmpClassList = "99,"
	for(var i=1;i < pClsCnt;i++) {
		if (pCls[i]) {tmpClassList = tmpClassList + i + ","}
	}
	tmpClassList = tmpClassList + "99"
	ajaxpage("/project.asp?cmd=v&id=" + TheID + "&c=" + tmpClassList + "&key=" + GetObj("fKeys").value, "scrollContent");
}

function ShowImage(TheUrl) {
	ajaxpage("/inc/showpic.asp?url=" + TheUrl, "divImage");
}

function HideImage() {
	Hide("divImage")
}

function ShowExifBox(TheState) {
	if (TheState) { Show("divExif");} else { Hide("divExif");}
}

function ShowMovie(TheMovieCode) {
		ShowModalPopup("/player.asp?code=" + TheMovieCode, 419, 393)
}

function ToogleExifBox() {
	if (GetVis(GetObj("divExif"))) { Hide("divExif");} else { Show("divExif");}
}

// modal popup
// *****************************************************************************

function ShowModalPopup(TheUrl, TheWidth, TheHeight) {
  popW=TheWidth; popH =TheHeight ; 
  GetGeo();
  Size(winW , winH, GetObj("divDark"));
  Size(popW , popH, GetObj("divPop"));
	Move(winW/2-popW/2 , winH/2-popH/2, GetObj("divPop"));
  Show("divDark");
  Show("divPop");
  ajaxpage(TheUrl, "divPop")	
}

function HideModalPopup() {
   ajaxpage("/modal.asp", "divPop")	
   Hide("divDark");
   Hide("divPop");
}


function ZeroFormat(num,count) {
  var numZeropad = num + '';
  while(numZeropad.length < count) {numZeropad = "0" + numZeropad;}
  return numZeropad;
}


// clock
// *****************************************************************************
var tmUtc = new Date();
var tmLocal = new Date();
var ClockMonthNames = new Array("Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran", "Temmuz", "Ağustos", "Eylül", "Ekim", "Kasım", "Aralık");
var ClockWeekDay = new Array("Pazar","Pazartesi","Salı","Çarşamba","Perşembe","Cuma","Cumartesi")
var ClockFull = false;
var tmpClockStr = ""
var ClockInterval = 60000
var ClockTimerVal = 0

//var ClockWeekDay = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
//var ClockMonthNames = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

function initClock() {
	updateClock()
	ClockTimerVal = setTimeout("timerClock()",ClockInterval)
}

function updateClock() {
	tmpClockStr = ZeroFormat(tmUtc.getHours(),2) +":"+ ZeroFormat(tmUtc.getMinutes(),2)  
	if(ClockFull) {tmpClockStr=tmpClockStr+":"+  ZeroFormat(tmUtc.getSeconds(),2)}
	document.getElementById("ClockUtc").innerHTML =tmpClockStr 
  tmpClockStr =  ZeroFormat(tmLocal.getHours(),2) +":"+ ZeroFormat(tmLocal.getMinutes(),2)  
	if(ClockFull) {tmpClockStr=tmpClockStr+":"+  ZeroFormat(tmLocal.getSeconds(),2)}
	document.getElementById("ClockLocal").innerHTML =tmpClockStr
	document.getElementById("ClockDate").innerHTML = ZeroFormat(tmLocal.getDate(),2) + " " + ClockMonthNames[tmLocal.getMonth()]  + " "+ tmLocal.getFullYear() + ", " + ClockWeekDay[tmLocal.getDay()]
	if(ClockFull) {ClockInterval=1000} else {ClockInterval=60000}
}

function timerClock() {
	if (tmUtc&&tmLocal) {
		tmLocal.setTime(tmLocal.getTime() + ClockInterval)
	  tmUtc.setTime(tmLocal.getTime() - 7200000)
	  updateClock()
	  } 
	ClockTimerVal = setTimeout("timerClock()",ClockInterval)
}

function toogleClock() {
	ClockFull=!ClockFull
	updateClock()
	clearTimeout(ClockTimerVal)
	setTimeout("timerClock()",ClockInterval)
}


// morse
// *****************************************************************************

var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 .,:?'-/()\"ÖÜŞĞİI";
var morse = new Array(
".-","-...","-.-.","-..",".","..-.",
"--.","....","..",".---","-.-",".-..",
"--","-.","---",".--.","--.-",".-.",
"...","-","..-","...-",".--","-..-",
"-.--","--..","-----",".----","..---",
"...--","....-",".....","-....","--...",
"---..","----."," ",".-.-.-","--..--",
"---...","..--..",".----.","-....-","-..-.",
"-.--.-","-.--.-",".-..-.",
"---","..-","...","--.","..",".."
);

function replace(string,text,by) {
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;
    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;
    var newstr = string.substring(0,i) + by;
    if (i+txtLength < strLength) newstr += replace(string.substring(i+txtLength,strLength),text,by);
    return newstr;
}

function EncodeMorse(TheInput) {
	TheOutput = "";
	TheInput = TheInput.toUpperCase();
	for(count = 0; count < TheInput.length; count++) {
	  daChar = TheInput.charAt(count);
		for (i = 0; i < letters.length; i++) {
		  if (daChar == letters.charAt(i)) {
			TheOutput += morse[i] + " ";
			break;
      }
    }
  }
  return TheOutput;
}

function DecodeMorse(TheInput){
	TheOutput = " " + TheInput + "  ";
	TheOutput = replace(TheOutput," ", "~~");
	for (i = 0; i < letters.length; i++){
		if (letters.charAt(i) != " ") {TheOutput = replace(TheOutput, "~" + morse[i] + "~", "~" + letters.charAt(i) + "~");}
	  }
  TheOutput = replace(TheOutput, "~~~~", " ");
  TheOutput = replace(TheOutput, "~", "");
  TheOutput = replace(TheOutput, "~~~~", " ");
  return TheOutput;
}


function getFlashMovieObject(movieName) {
  if (window.document[movieName]) {return window.document[movieName];}
  if (navigator.appName.indexOf("Microsoft Internet")==-1)  {
		if (document.embeds && document.embeds[movieName])
		return document.embeds[movieName]; 
  }  else {
    return document.getElementById(movieName);
  }
}

function PlayMorse(TheMorse) {
  var flashMovie=getFlashMovieObject("MorsePad");
  flashMovie.SetVariable("myVar", " " + TheMorse);
}


// page functions
// *****************************************************************************


function doPagePrint() {
	wndPrint = open("/inc/print.asp?id=" + PageID, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,width=750,height=480,top=0,left=0,screenX=,screenY=0');
}

function doPageSend() {
  Show("divSend");
}

function doPageBookmark() {
  doBookmark(PageID, "TA3KM - " + PageTitle)
}

function doPageRSS() {}

function doPageMorse() {
	if(brN=="IE") {	
	  tmpText = GetObj("cnt"+ PageID).innerText;
	} else {
	  tmpText = GetObj("cnt"+ PageID).textContent;
	}
	tmpText  = tmpText.substring(0,50)
	tmpText  = EncodeMorse(tmpText)
	PlayMorse(tmpText)
}

// ajax
// *****************************************************************************

var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function ajaxpage(url, containerid){
	window.status=url;
  var page_request = false
  if (window.XMLHttpRequest) // if Mozilla, Safari etc
  page_request = new XMLHttpRequest()
  else if (window.ActiveXObject){ // if IE
  try { page_request = new ActiveXObject("Msxml2.XMLHTTP") } 
  catch (e){ try{ page_request = new ActiveXObject("Microsoft.XMLHTTP") }
  catch (e){} } }
  else return false
  page_request.onreadystatechange=function(){ loadpage(page_request, containerid) }
  if (bustcachevar)
  bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
  page_request.open('GET', url+bustcacheparameter, true)
  page_request.send(null)
}

function loadpage(page_request, containerid){
  if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) {
		document.getElementById(containerid).innerHTML=page_request.responseText;
		if (containerid=="scrollContent") {
		  if (GetObj("scrollContent")) {ScrollerMax = GetObj("scrollContent").offsetHeight - 140;}
		  if (ScrollerMax<0) {ScrollerMax=0;}
			scroller.init();
			}
    }
		if (containerid=="divImage") {
			if (page_request.readyState == 4) {Show("divImage")}
		}
}



function doDxSummit(TheCall) {
  alert("lo:" + TheCall);
}

function doQrz(TheCall) {
	wndQrz = open("http://www.qrz.com/" + TheCall , 'wndQrz');
}

