function $(id){ return document.getElementById(id)};

function keyPressed(obj)
{
	key= window.event.keyCode
	key2=String.fromCharCode(key)

	if (isNaN(key2))
	{
		window.event.keyCode = "";
	}
}

function CleanMsWordChars(text)
{
	var swapCodes   = new Array(8211, 8212, 8216, 8217, 8220, 8221, 8226, 8230); // dec codes from char at
	var swapStrings = new Array("--", "--", "'",  "'",  '"',  '"',  "*",  "...");
	for (i = 0; i < swapCodes.length; i++) 
	{
		var swapper = new RegExp("\\u" + swapCodes[i].toString(16), "g"); // hex codes
		text = text.replace(swapper, swapStrings[i]);
	}
	
	return text;
}


function GenerateCp()
{
	cp = new cpaint();
	cp.set_response_type('text');
	cp.set_transfer_mode('post');
}

function getBaseUrl()
{
	var base = document.getElementsByTagName('BASE')[0];
	var url = base.href;
	
	if (url.charAt(url.length - 1 ) != '/')
		url += '/';
	
	return url;
}

function findParent(obj, tag, depth)
{
    obj = obj.parentNode;
    
    if (! depth || depth == null)
        depth = 1;
    var currDepth = 1;
    
    while (obj)
    {
        if (obj.tagName.toUpperCase() == tag.toUpperCase())
        {
            if (currDepth == depth)
                break;  
            else
                currDepth++;
        }   
        obj = obj.parentNode;
    }
    return obj;
}

function findTr(obj)
{
	return findParent(obj, 'TR', 1);
}

var ajaxRequest;
var objectId;
var ajaxLoadedFunction = null;

function getUrlContent(url, objId, functionName)
{
    objectId = objId;
    if (functionName && functionName.length > 0 )
        ajaxLoadedFunction = functionName;
    else
        ajaxLoadedFunction = null;
        
    ajaxRequest = null;
    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
        ajaxRequest = new XMLHttpRequest();
        if (ajaxRequest.overrideMimeType)            
            ajaxRequest.overrideMimeType('text/xml; charset=iso-8859-9');
    } 
    else if (window.ActiveXObject) 
    { // IE
        try {
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }        
    
    if (ajaxRequest)
    {
        ajaxRequest.onreadystatechange= function(){            
            if (ajaxRequest.readyState==4 && ajaxRequest.status==200)
            {    
                var index = ajaxRequest.responseText.indexOf('<!--CONTENT-->');
                var index2= ajaxRequest.responseText.indexOf('<!--CONTENT-END-->');
                if (index > 0 && index2 > 0 )
                {
                    var object = document.getElementById(objectId);
                    object.innerHTML = ajaxRequest.responseText.substring(index, index2);
                    if (ajaxLoadedFunction)
                        eval(ajaxLoadedFunction);                    
                }                  
            }        
        }
        
        ajaxRequest.open('GET',url,true);
        ajaxRequest.send(null);
    }
}


function getWindowDimensions() 
{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth, myHeight];
}

function getDocumentDimensions()
{
	var dims = getWindowDimensions();
	var width = dims[0];
	var height= dims[1];	
	
	if (document.body.clientHeight && document.body.clientHeight > dims[1])
		height= document.body.clientHeight;
	else if (document.body.scrollHeight > dims[1])
		height= document.body.scrollHeight;
	
	return [width, height];
}

function makeDisabled(obj, isDisabled, isParentDisabled)
{
	if (typeof isParentDisabled == "undefined" || isParentDisabled)
		obj.disabled = isDisabled;

	var bgColor		 = isDisabled ? 'lightgrey' : 'transparent';
	var inputs   = obj.getElementsByTagName('INPUT');
	var i=0;

	for(; i<inputs.length; i++)
	{
		inputs[i].disabled = isDisabled;
		if (inputs[i].type.toUpperCase() != 'BUTTON' )
			inputs[i].style.backgroundColor = bgColor;
	}

	inputs   = obj.getElementsByTagName('SELECT');
	i=0;
	for(; i<inputs.length; i++)
	{
		inputs[i].disabled = isDisabled;
		inputs[i].style.backgroundColor = bgColor;
	}

	inputs   = obj.getElementsByTagName('BUTTON');
	i=0;
	for(; i<inputs.length; i++)
	{
		inputs[i].disabled = isDisabled;
	}

}

function doVisible(isVisible)
{
		
	var firefox = (navigator.appName == 'Netscape' && /Firefox/.test(navigator.userAgent));
	
	var ie7orBetter = false;		
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
	{ 
		var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
		if (ieversion >= 7)
			ie7orBetter = true;
	}
	
	if (firefox || ie7orBetter)
		return false;
				
 	var tagNames = ['select', 'object', 'embed'];
	for (var k = 0; k < tagNames.length; k++) 
	{
		var sels = document.getElementsByTagName(tagNames[k]);
		for (var i = 0; i < sels.length; i++) 
			if (sels[i].getAttribute('dont_hide') != '1') 
				sels[i].style.visibility = (isVisible ? 'visible' : 'hidden');
	} 
}


function getParameter(param)
{
	param += "=";
	var str	  = window.location.search;
	var ind1  = str.indexOf(param);
	var ind2  = -1;
	var retVal;

	if (ind1 >= 0)
	{
		if ((ind2 = str.indexOf('&', ind1)) >= 0 )
			retVal = unescape(str.substring(ind1 + param.length, ind2  ));
		else
			retVal = unescape(str.substring(ind1 + param.length));
	}
	else
		retVal = "";

	retVal = retVal.replace(/\+/g, ' ');

	return retVal;
}

function openCv(cvId, tabIndex, adsId)
{
	var w = 900;
	var h = 600;
	var l = (window.screen.width-w)/2;
	var t = (window.screen.height-h)/2;

	var url = 'cv.php?id=' + cvId ;
	if (adsId)
		url += '&ads_id=' + adsId;
	if (tabIndex)
		url += '&tab=' + tabIndex;
			
	var wnd = window.open(getBaseUrl() + url, '', 'scrollbars=1,resizable=1,' +
		'width=' + w + ',' +
		'height=' + h + ',' +
		'left=' + l + ',' +
		'top=' + t );
}

function in_array(el, array)
{
	for(var i=0; i<array.length; i++)
	{
		if (el + "" == array[i] + "")
			return i;
	}

	return -1;
}

function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

 function openNewWindow(page, wname, wi, he, extra)
 {
 	l = (window.screen.width - wi) / 2;
	t = (window.screen.height- he) / 2;

	if (page.indexOf(getBaseUrl()) < 0 )
		page = getBaseUrl() + page;

	window.open(page, wname,
		'width=' + wi + ',' +
		'height=' + he + ',' +
		'left=' + l + ',' +
		'top=' + t + ',' +
		(extra ? extra : "scrollbars=1,resizable=1")
	);
	
	if( hideTheMenu)
		hideTheMenu();
 }

function loadScript(url)
{
   var e = document.createElement("script");
   e.src = url;
   e.type="text/javascript";
   document.getElementsByTagName("head")[0].appendChild(e);
}

function number_format(a, b, c, d) 
{
	if (! b)
		b= 2;
	if (! c)
		c = ',';
	if (! d)
		d = '.';
	
	a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
	e = a + '';
	f = e.split('.');
	if(!f[0]) f[0] = '0';
	if(!f[1]) f[1] = '';
	if(f[1].length < b)
	{
		g = f[1];
		for(i = f[1].length + 1; i <= b; i++) {
			g += '0';
		}
		f[1] = g;
	}
	
	if(d != '' && f[0].length > 3) 
	{
		h = f[0];
		f[0] = '';
		for(j = 3; j < h.length; j += 3) {
			i = h.slice(h.length - j, h.length - j + 3);
			f[0] = d + i +  f[0] + '';
		}
		j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
		f[0] = j + f[0];
	}
	c = (b <= 0) ? '': c;
	return f[0] + c + f[1];
}

function GotoInPage(anch)
{
	var u = window.location.href;
	if (u.indexOf('#') > 0)
		u = u.substring(0, u.indexOf('#'));
	return u + anch;
}

function getScrollTop()
{
    if (document.documentElement && document.documentElement.scrollTop )
        return document.documentElement.scrollTop;
    else if (document.body && document.body.scrollTop)
        return document.body.scrollTop;
    else
        return 0;
}

function showProcessingMessage(jqSelector, message, onlyShowMessage)
{
	if (typeof onlyShowMessage == "undefined" )
		onlyShowMessage = false;
	
	var obj = $(jqSelector);
	if (obj.get(0) != window)
	{
		var l   = obj.offset()['left'];
		var t   = obj.offset()['top'];
	}
	else
	{
		var l = 0;
		var t = 0;
	}
	
	var h   = obj.height();
	var w   = obj.width();
	
	if (onlyShowMessage == false)
	{		
		var div = $('#DIV_ProcessingMessage');
		if (div.length == 0)
		{
			var div = $('<div id=DIV_ProcessingMessage style="display:none;"></div>');
			div.appendTo(document.body);
		}
		
		div.css({  
			backgroundColor : 'black', 
			position : 'absolute', 
			zIndex : 100, 
			width: w, height: h, left : l, top : t, 
			opacity : 0.15,
			textAlign : 'center'
		});	
		div.show();
	}

	// Ortalanmış bir mesaj göster
	if (message != null && message != '')
	{		
		var div2 = $('#DIV_ProcessingMessageSub');
		if (div2.length == 0)
		{
			var div2 = $('<div id=DIV_ProcessingMessageSub style="display:none;"></div>');
			div2.appendTo(document.body);
		}
			
		div2.css({
			display: 'block',
			position: 'fixed',
			zIndex : 101,
			left : l + w/2 - 150,
			top : t + h /2.0  - 20, 
			width : 300,
			height: 20,		
			textAlign: 'center',
			backgroundColor : '#EFE14A',
			border: '1px solid',
			padding : 3,
			//opacity : 0.8,
			color: 'black',
			fontWeight: 'bold'
		});
	
		div2.get(0).innerHTML = '<img src="images/loading.gif" align=absmiddle> ' + message;
		div2.show();
	}
}

function closeProcessingMessage()
{
	$('#DIV_ProcessingMessage').hide();
	$('#DIV_ProcessingMessageSub').hide();
}


function PrintThis(obj, cssFile)
{
	if (typeof obj.width != "function")	
		obj = $(obj);
	var w = window.screen.width;
	var h = window.screen.height;
	var l = (window.screen.width - w ) / 2;
	var t = (window.screen.height- h) / 2;
	
	var wnd = window.open('', 'print_window', 
		'left=' + l + ',' +
		'top=' + t + ',' + 
		'width=' + w + ',' + 
		'height=' + h + ',scrollbars=1,resizable=1,toolbars=1' 
	);
		
	wnd.document.open();
	if (typeof cssFile != "undefined" && cssFile != '')
		wnd.document.write("<link href=\"" + cssFile + "\" type=\"text/css\" rel=\"stylesheet\"/>");
	wnd.document.write('<style>.print-command {visibility:hidden;}</style>');
	wnd.document.write(obj.get(0).innerHTML);
	wnd.document.close();
	wnd.print();
}

function OgrenciYillikBep(ogrId)
{
	// Yeni pencereyi aç
	var w = 1000;
	var h = 610;
	var l = (window.screen.width - w ) / 2;
	var t = (window.screen.height - h) / 2;
	var wnd = window.open(
		'index.php?act=ogr_yillik_bep&o=' + ogrId , 
		'', 
		'width=' + w + ',' + 
		'height=' + h + ',' +
		'left=' + l + ',' +
		'top=' + t + ',' +
		'scrollbars=1,toolbars=0,resizable=1'
	);
	wnd.focus();	
}
