function $(id){ return document.getElementById(id)};

function GenelReloadList()
{
	showProcessingMessage(window, 'Yükleniyor, Lütfen bekleyiniz...');
	GenerateCp();
	cp.call('index.php?mode=ajax', 'DonemChangeReload',RespDonemChangeReload,$('SEL_Terms').value ); 	
	//javascript:location.reload(true);
	
}
function RespDonemChangeReload(resp)
{
	if (resp == '1' || resp == '') {		
		
			window.focus();
			window.location.reload();
	}
	else{
		alert('HATA!!!\n\n' + resp);
		closeProcessingMessage();
	}
	
}


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,menubar=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();
	
	return wnd;
}
var secilenindex;
function Ogrenci_Bilgileri(OgrID,sira)
{
	$SiraNO=sira;
	secilenindex=OgrID;
	//* Yeni pencereyi aç
	var w = 850;
	var h = 580;
	var l = (window.screen.width - w ) / 2;
	var t = (window.screen.height - h) / 2;
	var wnd = window.open(
		'index.php?act=ogrenci_list_islem&OgrID='+OgrID+'&SN='+$SiraNO+'' , 
		'', 
		'width=' + w + ',' + 
		'height=' + h + ',' +
		'left=' + l + ',' +
		'top=' + t + ',' +
		'scrollbars=1,toolbars=0,resizable=1'
	);
	wnd.focus();	

}
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();	
}
function AylikTerapiAyrintisi(id)
{
	var w = 750;
	var h = 550;
	var l = (window.screen.width - w) / 2;
	var t = (window.screen.height - h) / 2;
	var wnd = window.open('index.php?act=aylik_terapi_ayrintisi&OgrID='+id+'',
	 '', 'width=' + w + ',' +
	'height=' +
	h +
	',' +
	'left=' +
	l +
	',' +
	'top=' +
	t +
	',' +
	'scrollbars=1,toolbars=0,resizable=1');
	wnd.focus();
}
function ShowCenteredDiv(divId)
{
	var b = $(window);
	var div=$('#' + divId);
	var bw = b.width();
	var bh = b.height();
	var dw = div.width();
	var dh = div.height();
	
	div.css({
		position: 'fixed',
		left	: (bw-dw) / 2,
		top		: (bh-dh ) / 2 ,
		zIndex  : 200
	}).show(); 	
}

/*==================================================
  Cookie functions
  ==================================================*/
function setCookie(name, value, expires, path, domain, secure) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

function getCookie(check_name) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	var i = '';
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) 
	{
		return null;
	}
}

function deleteCookie(name, path, domain) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

//Para Formatı ayarla..........................................
function IsNumber(obj)
{
     var elementValueLength = obj.value.length;
     var lastChar  = obj.value.toString().substring(elementValueLength-1,elementValueLength);
     var goodChars =  obj.value.toString().substring(0,elementValueLength-1);
         
     if(!isNaN(parseInt(lastChar)) || lastChar==',' || lastChar=='.')
     {
          obj.value = goodChars+lastChar; 
     }
     else
     {
          obj.value = goodChars; 
     }
     
}
function CurrencyFormat(obj)
{
    var elementValue = obj.value;
	if(elementValue=='')
		return;
	var afterSeperator;
    var beforeSeperator;
    var newBefore = '';
    elementValue = elementValue.replace('.','');    
    if(elementValue.toString().indexOf(',')>-1)
    {
        afterSeperator = elementValue.split(',')[1];
        beforeSeperator = elementValue.split(',')[0];
    }
    else
    {
        beforeSeperator = elementValue;
        afterSeperator = '00 TL';
    }
   
    var count = 0;
    for(var i=0;i<beforeSeperator.length;i++)
    {
        count++;
        newBefore = beforeSeperator.substring(beforeSeperator.length-i-1,beforeSeperator.length-i) + newBefore;
        if(count==3)
        {
            if(i!=beforeSeperator.length-1)
            {
                newBefore = '.' + newBefore;
                count = 0;      
            }      
        }
    }
   obj.value = newBefore+','+afterSeperator;
}
//end............................................................

