// *****************************
// CAWIS General JavaScript Code
// *****************************

var cwsWin = null;
var rnk_bgc = null;

if (top.location != self.location) {  // eğer frame içerisinde çağırılmışsa
  top.location = self.location.href;
} else {
  document.domain = "sakarya.edu.tr";  // domain tanımı gereklidir
}

function varsayilanHata() {return false}
function sessizHata()  {return true}
function ozelHata(js_aciklama,js_sayfa,js_satir,js_karakter)  {
 alert(
  'CAWIS tarafından sayfada bir JavaScript hatası algılandı !\n\n'
 +'Oluşan hataya ait bilgiler şunlar:\n'
 +'\nHata açıklaması: \t'+js_aciklama
 +'\nSayfa adresi:    \t'+js_sayfa
 +'\nSatır numarası:  \t'+js_satir
 )
 return true
}

function eposta_dogrula(str){
	var filtrele=/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filtrele.test(str)){
			var bagla=str.split("@");
			bagla=bagla[1].split(".");
	}
	else {
		alert("E-posta adresini eksik ya da yanlış girdiniz!");
		return false;
	}
	return true;
}

function eposta_sakarya(str){
	str_low=str.toLowerCase();
	if (str_low.search(document.domain)>0) {
		alert("@"+document.domain+" e-posta adresli kullanıcılar bu formu ancak sisteme giriş yaptıktan sonra gönderebilirler!");
		return true;
	}
	return false;
}

function Browser() {
	var b=navigator.appName;
	if (b=="Netscape") this.b="ns";
	else if ((b=="Opera") || (navigator.userAgent.indexOf("Opera")>0)) this.b = "opera";
	else if (b=="Microsoft Internet Explorer") this.b="ie";
	if (!b) { alert('HATA [ERROR]\n\nBelirlenemeyen tarayici. Bu tarayıcı desteklenmiyor!\n[Unidentified browser. This browser is not supported!]'); window.location="http://www.netscape.com/download/"; }
	this.version=navigator.appVersion;
	this.v=parseInt(this.version);
	this.ns=(this.b=="ns" && this.v>=4);
	this.ns4=(this.b=="ns" && this.v==4);
	this.ns6=(this.b=="ns" && this.v==5);
	this.nsv=this.ns?this.ns6?6:this.ns4?4:this.v:0;
	this.iev=this.ie6?6:this.ie55?5.5:this.ie5?5:this.v;
	this.ie=(this.b=="ie" && this.v>=4);
	this.ie4=(this.version.indexOf('MSIE 4')>0);
	this.ie5=(this.version.indexOf('MSIE 5')>0);
	this.ie55=(this.version.indexOf('MSIE 5.5')>0);
	this.ie5=(!this.ie55 && this.version.indexOf('MSIE 5')>0);
	this.ie6=(this.version.indexOf('MSIE 6')>0);
	this.iev=this.ie?this.ie6?6:this.ie55?5.5:this.ie5?5:this.v:0;
	this.opera=(this.b=="opera");
	this.dom=document.getElementById?1:0;
	this.def=(this.ie||this.dom); // most used browsers, for faster if loops
	var ua=navigator.userAgent.toLowerCase();
	if (ua.indexOf("win")>-1) this.platform="win32";
	else if (ua.indexOf("linux")>-1) this.platform="linux";
	else if (ua.indexOf("mac")>-1) this.platform="mac";
	else this.platform="other";
}
is = new Browser();

function browsertest(paramx) {
	bw="";
	bw+="-----------------\n";
	bw+="is.b="+is.b+"\n";
	bw+="is.version="+is.version+"\n";
	bw+="is.v="+is.v+"\n";
	bw+="is.platform="+is.platform+"\n";
	bw+="-----------------\n";
	bw+="is.dom="+is.dom+"\n";
	bw+="is.def="+is.def+"\n";
	bw+="-----------------\n";
	bw+="is.ie="+is.ie+"\n";
	bw+="is.iev="+is.iev+"\n";
	bw+="is.ie4="+is.ie4+"\n";
	bw+="is.ie5="+is.ie5+"\n";
	bw+="is.ie55="+is.ie55+"\n";
	bw+="is.ie6="+is.ie6+"\n";
	bw+="-----------------\n";
	bw+="is.ns="+is.ns+"\n";
	bw+="is.nsv="+is.nsv+"\n";
	bw+="is.ns4="+is.ns4+"\n";
	bw+="is.ns6="+is.ns6+"\n";
	bw+="-----------------\n";
	bw+="is.opera="+is.opera+"\n";
	if (paramx==1) return (bw);
	else alert(bw);
}

//browsertest();
if(!is.def) { alert('HATA [ERROR]\n\nBu tarayici desteklenmiyor, Lütfen yenisini kurun!\n[This browser is not supported. Please install a new one!]'); window.location="http://www.netscape.com/download/"; }

function pagetop() {
	window.scroll(0,0);
}

function anasayfa() {
	location.href="/";
}

function cwswinopen(cwn_url,cwn_name,cwn_prop,cwn_reopen) {
	if(cwn_reopen && iscwswin()) cwsWin.close();
	if(iscwswin()) {
		cwsWin.focus();
	} else {
		cwsWin = window.open(cwn_url,cwn_name,cwn_prop);
	}
	event_yakala();

	if(!iscwswin()) alert("LÜTFEN DİKKAT ! Bu bir CAWIS uyarısıdır.\n\nBulunduğunuz sayfa yeni bir pencere açmaya çalıştı, ancak\ntarayıcı ayarlarınız şu anda bu pencerenin açılmasını engelliyor.\n\nCAWIS tarafından açılmak istenen pencereler mutlaka gereklidir.\nSistemin doğru bir şekilde çalışmasını istiyorsanız uyarıyı dikkate\nalmalı ve bu siteden açılan pencerelere izin vermelisiniz.");

	return cwsWin;
}

function cwswinclose() {
	if(iscwswin()) { cwsWin.close(); window.focus(); return true; }
	else return false;
}

function iscwswin() {
	if(cwsWin) {
		if(cwsWin.closed) return false;
		else return cwsWin;
	}
	else return false;
}

function return_true(e) {
	return true;
}

function return_false(e) {
	return false;
}

function event_yakala() {
	if (!(is.mac && is.ie)) {
		if (document.layers) document.captureEvents (Event.CLICK|Event.FOCUS);
		document.onmouseover = event_islem;
		document.onclick = event_islem;
		window.onfocus = event_islem;
	}
}

function event_birak() {
	if (!(is.mac && is.ie)) {
		if (document.layers) document.releaseEvents (Event.CLICK|Event.FOCUS);
		document.onmouseover = return_true;
		document.onclick = return_true;
		window.onfocus = return_true;
	}
}

function event_islem() {
	if (iscwswin()) {
		cwsWin.focus();
		return false;
	}
	else {
		event_birak();
		return true;
	}
}

function help(yrd) {
	w = 350;
	h = 400;
	l = (screen.availWidth-10 - w) / 2;
	t = (screen.availHeight-20 - h) / 2;

	features = "width="+w+",height="+h+",left="+l+",top="+t;
	features += ",screenX="+l+",screenY="+t;
	features += ",scrollbars=0,resizable=0,location=0";
	features += ",menubar=0,toolbar=0,status=0,directories=0";

	cwswinopen("http://www.cawis.sakarya.edu.tr/help.php?hid="+yrd, "win", features);
}

function delay(gap){ /* gap degeri ms cinsinden */
	var then,now;
	then=new Date().getTime();
	now=then;
	while((now-then)<gap) { now=new Date().getTime(); }
}

function getWidth(d) {
	if(document.getElementById) { return document.getElementById(d).offsetWidth; }
	else if(document.all) { return document.all.d.offsetWidth; }
}

function getHeight(d) {
	if(document.getElementById) { return document.getElementById(d).offsetHeight; }
	else if(document.all) { return document.all.d.offsetHeight; }
}

function resizeWin() 
{
	if (document.all) {
		cW=getWidth("oust")
		if(!cW) return false;
		cH=getHeight("oust")
		window.resizeTo(500,290)
		barsW=500-document.body.clientWidth;
		barsH=290-document.body.clientHeight;
		wW=barsW+cW
		wH=barsH+cH
		wX = (self.screen.width/2)-(wW/2);
		wY = (self.screen.height/2)-(wH/2);
		window.resizeTo(wW,wH)
	}
	else  {
		cW=getWidth("oust")
		if(!cW) return false;
		cH=getHeight("oust")
		wX = (self.screen.width/2)-(cW/2);
		wY = (self.screen.height/2)-(cH/2);
	    window.innerWidth=cW;
	   	window.innerHeight=cH;
	}
}

function centerWin() {
	parent.window.moveTo(wX,wY);
}

function GetRule(ruleName,param){
  var styleSheet=null;
  var Rules=new Array();
  var styleCount=0;
  rrn=ruleName.toLowerCase();

  if (!is.ie) return false;

  for (var ssIndex=0; ssIndex<document.styleSheets.length; ssIndex++){
    styleSheet = document.styleSheets[ssIndex];
    rules_length = is.ie ? styleSheet.rules.length : styleSheet.cssRules.length;
//ax="";
    for (var rIndex=0; rIndex<rules_length; rIndex++) {
      ruleget=is.ie?styleSheet.rules[rIndex]:styleSheet.cssRules[rIndex];
      rrt=ruleget.selectorText.toLowerCase();
//if (rIndex>0) ax+=rrt+"\n";
      if (rrt==rrn || rrt=="."+rrn || rrt=="#"+rrn) {
        Rules[styleCount]=ruleget;
        styleCount++;
				if(param==1) break;
      }								
    }
//alert(ax);
  }
  return Rules;
}

function renkal(trenk) {
//  window.onerror = err
	bgr = GetRule(trenk,1);
	if(bgr) return bgr[0].style.backgroundColor; else return "#FFFFFF";
}

function mover(obj) {
	if (!is.ie) obj.className = ilk_kelime(obj.className) + " bgc5";
	else obj.style.backgroundColor = rnk_bgc;
//	obj.style.color = renkal("bgc63"); //"black";
	obj.style.cursor = "hand";
	obj.onmouseout=function(){mout(obj);}
	return true;
}

function mout(obj) {
	if (!is.ie) obj.className = ilk_kelime(obj.className);
	else obj.style.backgroundColor = "";
//	obj.style.color = "";
	obj.style.cursor = "default";
	return true;
}

function ilk_kelime(str) {
	str1="";
	for(i=0;i<str.length;i++) {
		if (str[i]!=" ") str1+=str[i];
		else break;
	}
	return str1;
}

window.onerror=sessizHata;

rnk_bgc = renkal("bgc5");

