// JavaScript Document

function writeObj(val){
	document.write(val);
}

function loginPanel(){
	var obj = document.getElementById("toploginCont");
	if(obj.style.display == 'none'){
		Effect.SlideDown('toploginCont');
	}else{
		Effect.SlideUp('toploginCont');
	}
}


function openPopupWin(url,height,width) {
	var options = "fullscreen=no,Toolbar = no, status=no,scrollbars=no,resizable=no,menubar=no,width=" + width + ",height=" + height;
	var NewWin = window.open(url,"PopupWindow",options);
}


var registrationStep = 1;
function registration(lang,stepNr){
	if(parseInt(stepNr) > 0){
		registrationStep = parseInt(stepNr);
	}
	var stepTotal=1;
	for(i=1;i<(stepTotal+1);i++){
		var obj = document.getElementById("step"+i+"Content");
		if(obj){
			stepTotal++;
		}
	}
	if(registrationStep<stepTotal){
		for(i=1;i<stepTotal;i++){
			var objCur = document.getElementById("step"+i+"Content");
			if(i==registrationStep){
				objCur.style.display="block";
				document.getElementById("step"+i+"").style.fontWeight="bold";
				document.getElementById("step"+i+"img").src = "img/arrow.gif";
				if(i<(stepTotal-1)){
					if(lang == 'en'){
						document.registerForm.submitBtn.value = "Step "+(i+1)+" >>";
					}else{
						document.registerForm.submitBtn.value = "Adım "+(i+1)+" >>";
					}
				}else{
					if(lang == 'en'){
						document.registerForm.submitBtn.value = "Finish Registration";
					}else{
						document.registerForm.submitBtn.value = "Kaydı Bitir";
					}
				}
			}else{
				objCur.style.display="none";
				document.getElementById("step"+i+"").style.fontWeight="normal";
				document.getElementById("step"+i+"img").src = "img/blank.gif";
			}
		}
		registrationStep++;
	}else{
		document.registerForm.submit();
	}
}


var profileEditMenuCounter = 1;
function profileEdit(menuName){
	var obj = "";
	var lastindex = 1;
	obj = document.getElementById("menu"+lastindex);
	for(i=1; i<=lastindex;i++){
		obj = document.getElementById("menu"+i);
		if(obj){
			lastindex++;
		}
	}
	var leftMenu = document.getElementById(menuName);
	var title = document.getElementById("currentTitle");
	title.innerHTML = "<span class=\"headers\">"+leftMenu.innerHTML+'</span>';
	/*
	var a = [];
	for(i=1; i<lastindex; i++){
		a = menuName.split("m");
		var menuNumber = a[1];
		if(i==menuNumber){
			document.getElementById("menu"+i).style.display="block";
		}else{
			document.getElementById("menu"+i).style.display="none";
		}
	}
	*/
}


/*CommentedBy_WA
var profileEditMenuCounter = 1;
function profileEdit(menuName){
	var obj = "";
	var lastindex = 1;
	obj = document.getElementById("menu"+lastindex);
	for(i=1; i<=lastindex;i++){
		obj = document.getElementById("menu"+i);
		if(obj){
			lastindex++;
		}
	}
	var leftMenu = document.getElementById(menuName);
	var title = document.getElementById("currentTitle");
	title.innerHTML = "<span class=\"headers\">"+leftMenu.innerHTML+'</span>';
	document.getElementById("cecontainer").innerHTML='';
	
//	var a = [];
//	for(i=1; i<lastindex; i++){
//		a = menuName.split("m");
//		var menuNumber = a[1];
//		if(i==menuNumber){
//			document.getElementById("menu"+i).style.display="block";
//		}else{
//			document.getElementById("menu"+i).style.display="none";
//		}
//	}
}
*/

function showFlyers(flyerID, relativeObj){
	var obj = document.getElementById(flyerID);
	if(obj.style.display == 'none'){
		Effect.SlideDown(flyerID);
	}else{
		Effect.SlideUp(flyerID);
		
	}
}

/*var tmpMailField = [];
function AddNewMailField(objid,pFieldName){
	var isCreated = 1;
	var a=[];
	a= pFieldName.split("Mails");
	var numberOfField = parseInt(a[1]) + 1;
	var obj = $(objid);
	for(i=0; i<tmpMailField.length; i++){
		if(tmpMailField[i] == pFieldName){
			isCreated = 0;
		}
	}
	if(isCreated == 1){
		var b=[];
		b = pFieldName.split(String(a[1]));
		var elementField = "<input type=\"text\" class=\"blueinput\" name=\""+b[0]+numberOfField+"\" value=\"E-Mail "+numberOfField+"\" onKeyDown=\"AddNewMailField('"+objid+"',this.name)\">"; 
		obj.innerHTML = obj.innerHTML + "<br>" + elementField;
	}
	tmpMailField.push(pFieldName);
}*/



/*-----------------------------------------------------------
    Toggles element's display value
    Input: any number of element id's
    Output: none 
    ---------------------------------------------------------*/
function toggleDisp() {
    for (var i=0;i<arguments.length;i++){
        var d = $(arguments[i]);
        if (d.style.display == 'none')
            d.style.display = 'block';
        else
            d.style.display = 'none';
    }
}
/*-----------------------------------------------------------
    Toggles tabs - Closes any open tabs, and then opens current tab
    Input:     1.The number of the current tab
                    2.The number of tabs
                    3.(optional)The number of the tab to leave open
                    4.(optional)Pass in true or false whether or not to animate the open/close of the tabs
    Output: none 
    ---------------------------------------------------------*/
function toggleTab(tabsNum,num,numelems,opennum,animate) {
    if ($('tabContent'+tabsNum+''+num).style.display == 'none'){
        for (var i=1;i<=numelems;i++){
            if ((opennum == null) || (opennum != i)){
                var temph = [];
				temph[tabsNum] = 'tabHeader'+tabsNum+''+i;
                var h = $(temph[tabsNum]);
                if (!h){
                    var h = $('tabHeaderActive'+tabsNum);
                    h.id = temph[tabsNum];
                }
                var tempc = []; 
				tempc[tabsNum] = 'tabContent'+tabsNum+''+i;
                var c = $(tempc[tabsNum]);
                if(c.style.display != 'none'){
                    if (animate || typeof animate == 'undefined')
                        Effect.toggle(tempc[tabsNum],'appear',{duration:0.5, queue:{scope:'menus', limit: 3}});
                    else
                        toggleDisp(tempc[tabsNum]);
                }
            }
        }
        var h = $('tabHeader'+tabsNum+''+num);
        if (h)
            h.id = 'tabHeaderActive'+tabsNum;
        h.blur();
        var c = $('tabContent'+tabsNum+''+num);
        c.style.marginTop = '2px';
        if (animate || typeof animate == 'undefined'){
            Effect.toggle('tabContent'+tabsNum+''+num,'appear',{duration:0.5, queue:{scope:'menus', position:'end', limit: 3}});
        }else{
            toggleDisp('tabContent'+tabsNum+''+num);
        }
    }
}


var tmpId = "";
var t=0;
var timer2 = 0;
var timerOpener = 0;
var mouseOut = 0;
var mouseX;
var mouseY;
var usetooltip = false;
function detectMousePos(e){
	if(document.all){
		e = event;
	}
	mouseX=Event.pointerX(e);
	mouseY=Event.pointerY(e);
}

function detectmouse(){
	usetooltip = true;
	document.onmousemove=detectMousePos;
}

window.onload=detectmouse; 

function showTooltip(id, contenttt, contType, methodData){
	clearTimeout(timerOpener);
	/*if(document.all){*/
	if(usetooltip){
		timerOpener = setTimeout(function(){ TimeToolTip(''+id+'', ''+contenttt+'', ''+contType+'', ''+methodData+'') },400);
	}
	/*}else{
		timerOpener = setTimeout(TimeToolTip, 400, ''+id+'', ''+contenttt+'', contType, ''+methodData+'');
	}*/
	//TimeToolTip(''+id+'', ''+contenttt+'', ''+contType+'', ''+methodData+'');
}
function TimeToolTip(id, contenttt, contType, methodData){
	if(!methodData){
		methodData = 'Get';
	}
	var flyobj = $("tooltipCont");
	var contentObject = $("toolTipContent");
	var obj = $(id);
	
	if(flyobj.style.display == "none" || String(tmpId) != String(obj.id)){
		/*var a = String(Position.cumulativeOffset(obj));
		var b = [];
		b = a.split(',');*/
		clearTimeout(t);
		clearTimeout(timer2);
		var posX = mouseX;// parseInt(b[0]); 
		var posY = mouseY;// parseInt(b[1]); 
		//var objW = Element.getWidth(obj);
		//var objH = Element.getWidth(obj);
		var contentObj = '';
		flyobj.style.position = 'absolute';
		flyobj.style.left = ''+posX+'px';
		flyobj.style.top = ''+posY+'px';
		if(contType == 0){
			contentObj = '';
			contentObj = contentObj + contenttt;
			contentObject.innerHTML = contentObj;
		}
		if(contType == 1){
			var cont = new Ajax.Request(''+contenttt+'', {asynchronous: false, method: ''+methodData+''});
			var doHTML = false;
			if(cont.transport)
			{
				contentObj = '';
				contentObj = contentObj + cont.transport.responseText;
				contentObject.innerHTML = contentObj;
			}
			
		}
//	alert(contentObj);
	}
	
	//var hh = document.body.offsetHeight;
	var hh = document.documentElement.clientHeight + document.documentElement.scrollTop;
	if((parseInt(flyobj.style.top)+parseInt(Element.getHeight(flyobj))) > hh){
		$("ttheadcont1").style.display = "none";
		$("ttheadcont2").style.display = "block";		
		var posnewY = parseInt(flyobj.style.top) - parseInt(Element.getHeight(flyobj));
		flyobj.style.top = posnewY+'px';
	}else{
		$("ttheadcont1").style.display = "block";
		$("ttheadcont2").style.display = "none";	
	}
	if(parseInt(flyobj.style.top)<0){
		$("ttheadcont1").style.display = "block";
		$("ttheadcont2").style.display = "none";
		flyobj.style.left = ''+posX+'px';
		flyobj.style.top = ''+posY+'px';	
	}
	var ww = document.documentElement.clientWidth + document.documentElement.scrollLeft;
	//var ww = document.body.offsetWidth;
	if((parseInt(flyobj.style.left)+parseInt(Element.getWidth(flyobj))) > ww){
		var ff = ww - parseInt(flyobj.style.left);
		var fc = Element.getWidth(flyobj) - ff;
		flyobj.style.left = (parseInt(flyobj.style.left) - fc)+'px';
		$("ttheadcont1").style.left = fc+'px';
		$("ttheadcont2").style.left = fc+'px';
	}else{
		$("ttheadcont1").style.left = '0px';
		$("ttheadcont2").style.left = '0px';
	}
	flyobj.style.display="none";
	Effect.Appear(flyobj,{duration:0.2});
	tmpId=String(id);
	mouseOut = 0;
}
function controlMouseTooltip(id){
	if(mouseOut==1){
		var flyobj = $("tooltipCont");
		Effect.Fade(flyobj,{duration:0.2});
		clearTimeout(t);
	}else{
		t = setTimeout(controlMouseTooltip,300,id);
	}
}

function hideTooltip(id){
	mouseOut = 1;
	clearTimeout(timerOpener);
	clearTimeout(timer2);
	timer2 = setTimeout(controlMouseTooltip,300,id);
}

var timerFHOpener = 0;
var tmpFObjStyle = '';
function showFormHelp(obj,contentfh,contType,methodData){
	clearTimeout(timerFHOpener);
	timerFHOpener = setTimeout(function(){ fhOpener(obj, ''+contentfh+'', ''+contType+'', ''+methodData+'') },500);
}

function fhOpener(obj,contentfh,contType,methodData){
	tmpFObjStyle = obj.style.borderColor;
	var pos = String(Position.cumulativeOffset(obj));
	var posXY = pos.split(',');
	var objW = Element.getWidth(obj);
	var objH = Element.getHeight(obj);
	var posX = parseInt(posXY[0])+parseInt(objW);
	var posY = parseInt(posXY[1]);
	var flyobj = $('formHelpBox');
	var objContent = $('formHelpContent');
	if(flyobj.style.display == "none"){
		var contentObj = '';
		if(contType == 0){
			contentObj = '';
			contentObj = contentObj + contentfh;
		}
		if(contType == 1){
			var cont = new Ajax.Request(''+contentfh+'', {asynchronous: false, method: ''+methodData+''});
			var doHTML = false;
			if(cont.transport)
			{
				contentObj = '';
				contentObj = contentObj + cont.transport.responseText;
			}	
		}
		flyobj.style.left = posX +'px';	
		flyobj.style.position = "absolute";
		objContent.innerHTML = contentObj;
		flyobj.style.top = parseInt(posY - (Element.getHeight(flyobj)/2-(objH/2)))+'px';
		$("fhleftarrow").style.top = (Element.getHeight(flyobj)/2-(objH/2))+'px';
		$("fhrightarrow").style.top = (Element.getHeight(flyobj)/2-(objH/2))+'px';
		var hh = document.documentElement.clientHeight + document.documentElement.scrollTop;
		if((parseInt(flyobj.style.top)+parseInt(Element.getHeight(flyobj))) > hh){
			var ff = hh - parseInt(flyobj.style.top);
			var fc = Element.getHeight(flyobj) - ff;
			flyobj.style.top = (parseInt(flyobj.style.top) - fc)+'px';
			$("fhleftarrow").style.top = (fc+parseInt($("fhleftarrow").style.top)) +'px';
			$("fhrightarrow").style.top = (fc+parseInt($("fhleftarrow").style.top))+'px';
		}else{
			$("fhleftarrow").style.top = (Element.getHeight(flyobj)/2-(objH/2))+'px';
			$("fhrightarrow").style.top = (Element.getHeight(flyobj)/2-(objH/2))+'px';
		}
		var ww = document.documentElement.clientWidth + document.documentElement.scrollLeft;
		//var ww = document.body.offsetWidth;
		if((parseInt(flyobj.style.left)+parseInt(Element.getWidth(flyobj))) > ww){
			$("fhleftarrow").style.display = "none";
			$("fhrightarrow").style.display = "block";
			flyobj.style.left = (parseInt(flyobj.style.left)- (parseInt(Element.getWidth(flyobj))+objW))+'px';
		}else{
			$("fhleftarrow").style.display = "block";
			$("fhrightarrow").style.display = "none";
		}
		obj.style.borderColor = "#FFCC33";
		Effect.Appear(flyobj,{duration:0.2});
	}
}
function closeFormHelp(obj){
	obj.style.borderColor = tmpFObjStyle;
	var flyobj = $('formHelpBox');
	flyobj.style.display = 'none';
}

function createPlayer(thePlace, thePlayer, theFile, width, height, dispHeight, urlPlayer) {
	var so = new SWFObject(urlPlayer, thePlayer, width, height,'7');
	so.addParam("allowfullscreen","true");
	so.addVariable("displayheight", dispHeight);
	so.addVariable("file", theFile);
	so.addVariable("frontcolor","0xff890a");
	so.addVariable("lightcolor","0x6685A1");
	so.addVariable('overstretch','false');
	so.addParam('wmode','opaque');
	so.write(thePlace);
}

/*
 * Content-seperated javascript tree widget
 * Copyright (C) 2005 SilverStripe Limited
 * Feel free to use this on your websites, but please leave this message in the fies
 * http://www.silverstripe.com/blog
*/

/*
 * Initialise all trees identified by <ul class="tree">
 */
function autoInit_trees() {
	var candidates = document.getElementsByTagName('ul');
	for(var i=0;i<candidates.length;i++) {
		if(candidates[i].className && candidates[i].className.indexOf('tree') != -1) {
			initTree(candidates[i]);
			candidates[i].className = candidates[i].className.replace(/ ?unformatted ?/, ' ');
		}
	}
}
 
/*
 * Initialise a tree node, converting all its LIs appropriately
 */
function initTree(el) {
	var i,j;
	var spanA, spanB, spanC;
	var startingPoint, stoppingPoint, childUL;
	
	// Find all LIs to process
	for(i=0;i<el.childNodes.length;i++) {
		if(el.childNodes[i].tagName && el.childNodes[i].tagName.toLowerCase() == 'li') {
			var li = el.childNodes[i];

			// Create our extra spans
			spanA = document.createElement('span');
			spanB = document.createElement('span');
			spanC = document.createElement('span');
			spanA.appendChild(spanB);
			spanA.appendChild(spanC);
			spanA.className = 'a ' + li.className.replace('closed','spanClosed');
			spanA.onMouseOver = function() {}
			spanB.className = 'b';
			spanB.innerHTML = '&nbsp;';
			spanB.onclick = treeToggle;
			spanC.className = 'c';
			
			
			// Find the UL within the LI, if it exists
			stoppingPoint = li.childNodes.length;
			startingPoint = 0;
			childUL = null;
			for(j=0;j<li.childNodes.length;j++) {
				if(li.childNodes[j].tagName && li.childNodes[j].tagName.toLowerCase() == 'div') {
					startingPoint = j + 1;
					continue;
				}

				if(li.childNodes[j].tagName && li.childNodes[j].tagName.toLowerCase() == 'ul') {
					childUL = li.childNodes[j];
					stoppingPoint = j;
					break;					
				}
			}
				
			// Move all the nodes up until that point into spanC
			for(j=startingPoint;j<stoppingPoint;j++) {
				spanC.appendChild(li.childNodes[startingPoint]);
			}
			
			// Insert the outermost extra span into the tree
			if(li.childNodes.length > startingPoint) li.insertBefore(spanA, li.childNodes[startingPoint]);
			else li.appendChild(spanA);
			
			// Process the children
			if(childUL != null) {
				if(initTree(childUL)) {
					addClass(li, 'children', 'closed');
					addClass(spanA, 'children', 'spanClosed');
				}
			}
		}
	}
	
	if(li) {
		// li and spanA will still be set to the last item

		addClass(li, 'last', 'closed');
		addClass(spanA, 'last', 'spanClosed');
		return true;
	} else {
		return false;
	}
		
}
 

/*
 * +/- toggle the tree, where el is the <span class="b"> node
 * force, will force it to "open" or "close"
 */
function treeToggle(el, force) {
	el = this;
	
	while(el != null && (!el.tagName || el.tagName.toLowerCase() != "li")) el = el.parentNode;
	
	// Get UL within the LI
	var childSet = findChildWithTag(el, 'ul');
	var topSpan = findChildWithTag(el, 'span');

	if( force != null ){
		
		if( force == "open"){
			treeOpen( topSpan, el )
		}
		else if( force == "close" ){
			treeClose( topSpan, el )
		}
		
	}
	
	else if( childSet != null) {
		// Is open, close it
		if(!el.className.match(/(^| )closed($| )/)) {		
			treeClose( topSpan, el )
		// Is closed, open it
		} else {			
			treeOpen( topSpan, el )
		}
	}
}


function treeOpen( a, b ){
	removeClass(a,'spanClosed');
	removeClass(b,'closed');
}
	
	
function treeClose( a, b ){
	addClass(a,'spanClosed');
	addClass(b,'closed');
}

/*
 * Find the a child of el of type tag
 */
function findChildWithTag(el, tag) {
	for(var i=0;i<el.childNodes.length;i++) {
		if(el.childNodes[i].tagName != null && el.childNodes[i].tagName.toLowerCase() == tag) return el.childNodes[i];
	}
	return null;
}

/*
 * Functions to add and remove class names
 * Mac IE hates unnecessary spaces
 */
function addClass(el, cls, forceBefore) {
	if(forceBefore != null && el.className.match(new RegExp('(^| )' + forceBefore))) {
		el.className = el.className.replace(new RegExp("( |^)" + forceBefore), '$1' + cls + ' ' + forceBefore);

	} else if(!el.className.match(new RegExp('(^| )' + cls + '($| )'))) {
		el.className += ' ' + cls;
		el.className = el.className.replace(/(^ +)|( +$)/g, '');
	}
}
function removeClass(el, cls) {
	var old = el.className;
	var newCls = ' ' + el.className + ' ';
	newCls = newCls.replace(new RegExp(' (' + cls + ' +)+','g'), ' ');
	el.className = newCls.replace(/(^ +)|( +$)/g, '');
} 

/*
 * Handlers for automated loading
 */ 
 _LOADERS = Array();

function callAllLoaders() {
	var i, loaderFunc;
	for(i=0;i<_LOADERS.length;i++) {
		loaderFunc = _LOADERS[i];
		if(loaderFunc != callAllLoaders) loaderFunc();
	}
}

function appendLoader(loaderFunc) {
	if(window.onload && window.onload != callAllLoaders)
		_LOADERS[_LOADERS.length] = window.onload;

	window.onload = callAllLoaders;

	_LOADERS[_LOADERS.length] = loaderFunc;
}

appendLoader(autoInit_trees);

function addSelectedItem(obj,addinto){
	var itemSelected = obj.innerHTML;
	var x=$(addinto);
	var y = document.createElement('option');
	y.value=''+obj.id+'';
	y.text = itemSelected.replace('&amp;', '&');
	var isAddItem = true;
	for(i=0; i<x.length; i++){
		if(x.options[i].text == itemSelected.replace('&amp;', '&')){
			isAddItem = false;
		}
	}
	if(isAddItem){
		try
		{
			x.add(y,null);
		}catch(ex){
			x.add(y);
		}
	}
}

function removeItems(objName){
	var x = $(objName);
	var lentghSelectBox = x.length; 
	var y = [];
	for(i=0; i<lentghSelectBox; i++){
		if(x.options[i].selected){
			y.push(x.options[i].text);
		}
	}
	for(i=0; i<y.length; i++){
		for(j=0; j<x.length; j++){
			if(x.options[j].text == y[i]){
				x.remove(j);
			}
		}
	}
	x.selectedIndex = -1;
}

function submitForm(obj){
	var x = $('mySelectMultiple');
	for(i=0; i<x.length; i++){
		x.options[i].selected = true;
	}
	var formName = obj.form.name;
	document[formName].submit();
}

function toggleSubCategories(obj){
	var objid = String(obj.id);
	var subobj = $(''+objid+'sub');
	if(subobj.style.display == "none"){
		subobj.style.display = "block";
	}else{
		subobj.style.display = "none";
	}
}

function toggleMenus(id){
	var generalMenuId = 1;
	for(i=0;i<generalMenuId;i++){
		var obj = $("menu"+generalMenuId+"content");
		if(obj){
			generalMenuId++;
		}
	}
	for(i=0;i<generalMenuId;i++){
		var obj = $("menu"+i+"content");
		if(i == id){
			obj.style.display = "block";
		}else{
			obj.style.display = "none";
		}
	}
}

function addOnLoad(newFunction) {
    var currentOnLoad = window.onload;
    if (typeof window.onload != "function") {
        window.onload = newFunction;
    }
    else {
        window.onload = function() {
            currentOnLoad();
            newFunction();
        }
    }
}

function CloseDiv(divName){ //<div id="XXX" style="display:none"></div> //div böyle oluşturulmalı.
	toggleSelectVisibility(1);
	$(""+divName+"").innerHTML="";
	$(""+divName+"").style.display="none";
	//$("replymessage").innerHTML="";
	//$("companyreplymessage").style.display="none";
}

function runsifr(){
	if(typeof sIFR == "function"){
		sIFR.replaceElement("span", named({sFlashSrc: "./flash/helveticalightext.swf", sSelector: ".bluelt>div>.headers", sColor:"#7190ac", sWmode: "Transparent", sFlashVars:"textalign=left", nPaddingTop:"0", nPaddingBottom:"0"}));
		sIFR.replaceElement("span", named({sFlashSrc: "./flash/helveticalightext.swf", sSelector: ".orangelt>div>.headers", sColor:"#ff8706", sWmode: "Transparent", sFlashVars:"textalign=left", nPaddingTop:"0", nPaddingBottom:"0"}));
		sIFR.replaceElement("span", named({sFlashSrc: "./flash/helveticalightext.swf", sSelector: ".greenlt>div>.headers", sColor:"#75ac71", sWmode: "Transparent", sFlashVars:"textalign=left", nPaddingTop:"0", nPaddingBottom:"0"}));
		sIFR.replaceElement("span", named({sFlashSrc: "./flash/helveticalightext.swf", sSelector: ".redlt>div>.headers", sColor:"#ff0606", sWmode: "Transparent", sFlashVars:"textalign=left", nPaddingTop:"0", nPaddingBottom:"0"}));
	}
}
