// JavaScript Document
/*-------------------------------GLOBAL VARIABLES------------------------------------*/

var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

/*-----------------------------------------------------------------------------------------------*/

//Browser detect script origionally created by Peter Paul Koch at http://www.quirksmode.org/

	if (checkIt('konqueror')) {
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (checkIt('safari')) browser 	= "Safari"
	else if (checkIt('omniweb')) browser 	= "OmniWeb"
	else if (checkIt('opera')) browser 		= "Opera"
	else if (checkIt('webtv')) browser 		= "WebTV";
	else if (checkIt('icab')) browser 		= "iCab"
	else if (checkIt('msie')) browser 		= "Internet Explorer"
	else if (!checkIt('compatible')) {
		browser = "Netscape Navigator"
		version = detect.charAt(8);
	}
	else browser = "An unknown browser";

	if (!version) version = detect.charAt(place + thestring.length);

	if (!OS) {
		if (checkIt('linux')) OS 		= "Linux";
		else if (checkIt('x11')) OS 	= "Unix";
		else if (checkIt('mac')) OS 	= "Mac"
		else if (checkIt('win')) OS 	= "Windows"
		else OS 								= "an unknown operating system";
	}

function checkIt(string) {
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

///////////////////////////////////////////////////////////////////////////////////



var id;
//var menukapatan

function checkbox_checker(sender,pid){
	var secili = new Array(5);
	var checkbox_choices = 0;
	var Sonuclar = document.getElementById("Sonuclar");
	var url3 = "karsilastir.aspx";
	if (sender==1) {url3 = "addlist.aspx"}
	if (sender==2) {url3 = "removelist.aspx"}
	if (pid){
		var qrystr="?pid1="+pid;
	}
else
{
   if (Sonuclar.cbPortfoy.length){
		for (counter = 0; counter < Sonuclar.cbPortfoy.length; counter++){
			if (Sonuclar.cbPortfoy[counter].checked){ 
				checkbox_choices = checkbox_choices + 1;
				secili[checkbox_choices]=Sonuclar.cbPortfoy[counter].id;
				//url3=url3+"p"+checkbox_choices+"="+Sonuclar.cbPortfoy[counter].id;
			}
		}
   } else if (Sonuclar.cbPortfoy) {
		if (Sonuclar.cbPortfoy.checked){ 
			checkbox_choices = checkbox_choices + 1;
			secili[checkbox_choices]=Sonuclar.cbPortfoy.id;
			//url3=url3+"p"+checkbox_choices+"="+Sonuclar.cbPortfoy.id;
		}
   }
	
	if (checkbox_choices > 5 ){
		// If there were more than three selections made display an alert box
	    msg="En fazla 5 secim yapabilirsiniz! \n"
	    alert(msg)
	    return (false);
	} else if (checkbox_choices == 0 ){
	    msg="En az 1 secim yapmaniz gerekmektedir! \n"
	    alert(msg)
	    return (false);
	}
	var qrystr="?pid1="+secili[1];
	for (var k=2;k<=checkbox_choices;k++){
		qrystr+="&pid"+k+"="+secili[k];
	}
}
	url3+=qrystr;
	if (sender!=0) {
		if (sender==1) {activate('addfav',url3)};
		if (sender==2) {activate('remfav',url3)};
		//window.open(url3,'mywindow','width=400,height=200')
	} else {
		window.location=url3
	 };
}


function disinda () {id = window.setTimeout('temizle();',1000);	}
function ustunde () {window.clearTimeout(id);}	

function expandAltmenu(hedefmenu, activemenu){
	var submenu = document.getElementById(hedefmenu);
	var actmenu = document.getElementById(activemenu);
	var container = document.getElementById("submenuContainer").getElementsByTagName("ul")
	var HMCount = document.getElementById("nav").getElementsByTagName("a")
		for (var i=0; i<HMCount.length; i++){
				HMCount[i].className = "";
			}
		
		for (var i=0; i<container.length; i++){
				container[i].style.display = "none";
			}
		
		submenu.style.display = "block";
		actmenu.className = "currentSection";
	}

function temizle() {
	var SMcontainer = document.getElementById("submenuContainer").getElementsByTagName("ul")
	for (var i=0; i<SMcontainer.length; i++){
				SMcontainer[i].style.display = "none";
			}
	
	var HMLink = document.getElementById("nav").getElementsByTagName("a")
	for (var i=0; i<HMLink.length; i++){
				HMLink[i].className = "";
			}
	}
 function currencyFormat2(fld, milSep, decSep, e) {
		var sep = 0;
		var key = '';
		var i = j = 0;
		var len = len2 = 0;
		var strCheck = '0123456789';
		var aux = aux2 = '';
		var whichCode = (window.Event) ? e.which : e.keyCode;
		if (whichCode == 13) return true;  // Enter
		if (whichCode == 8) return true;  // Delete (Bug fixed)
		key = String.fromCharCode(whichCode);  // Get key value from key code
		if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
		len = fld.value.length;
		aux = '';
		for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
		aux += key;
		len = aux.length;
		if (len == 0) fld.value = '';
		if (len <= 3) fld.value = aux;
		if (len > 11) return false;
		if (len > 3) {
		aux2 = '';
		for (j = 0, i = len-1; i >= 0; i--) {
		if (j == 3 ) {
		aux2 += milSep;
		j = 0;
		}
		aux2 += aux.charAt(i);
		j++;
		}
		fld.value = '';
		len2 = aux2.length;
		for (i = len2; i >= 0; i--)
		fld.value += aux2.charAt(i);
	}
		return false;
	}
 function currencyFormat(fld, milSep, decSep, e) {
		var sep = 0;
		var key = '';
		var i = j = 0;
		var len = len2 = 0;
		var strCheck = '0123456789';
		var aux = aux2 = '';
		var whichCode = (window.Event) ? e.which : e.keyCode;
		if (whichCode == 13) return true;  // Enter
		if (whichCode == 8) return true;  // Delete (Bug fixed)
		key = String.fromCharCode(whichCode);  // Get key value from key code
		if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
		len = fld.value.length;
		aux = '';
		for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
		aux += key;
		len = aux.length;
		if (len == 0) fld.value = '';
		if (len <= 3) fld.value = aux;
		if (len > 3) {
		aux2 = '';
		for (j = 0, i = len-1; i >= 0; i--) {
		if (j == 3 ) {
		aux2 += milSep;
		j = 0;
		}
		aux2 += aux.charAt(i);
		j++;
		}
		fld.value = '';
		len2 = aux2.length;
		for (i = len2; i >= 0; i--)
		fld.value += aux2.charAt(i);
	}
		return false;
	}
	   

// Login Ekranı Scripti.. LightBox'tan modifiye edilmiştir..
// Modified by lightbox script -- 

	yPos : 0
	xPos : 0
	
	// Ie requires height to 100% and overflow hidden or else you can scroll down past the lightbox
	function prepareIE(height, overflow){
		bod = document.getElementsByTagName('body')[0];
		bod.style.height = height;
		bod.style.overflow = overflow;
  
		htm = document.getElementsByTagName('html')[0];
		htm.style.height = height;
		htm.style.overflow = overflow; 
	}
	
	// In IE, select elements hover on top of the lightbox
	function hideSelects(visibility){
		selects = document.getElementsByTagName('select');
		for(i = 0; i < selects.length; i++) {
			selects[i].style.visibility = visibility;
		}
		var objects = document.getElementsByTagName("OBJECT");
		/*if (objects.length > 0) {
			__flash_unloadHandler = function(){}; // fixes but in fp9
			__flash_savedUnloadHandler = function(){};// fixes but in fp9 see http://blog.deconcept.com/
		}*/
		for (var i=0; i < objects.length; i++) {
			objects[i].style.visibility = visibility;
			for (var x in objects[i]) {
				if (typeof objects[i][x] == 'function') {
					objects[i][x] = function(){};
				}
			}
		}
		
		
	}
	
	// Taken from lightbox implementation found at http://www.huddletogether.com/projects/lightbox/
	function getScroll(){
		if (self.pageYOffset) {
			this.yPos = self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){
			this.yPos = document.documentElement.scrollTop; 
		} else if (document.body) {
			this.yPos = document.body.scrollTop;
		}
	}
	
	function setScroll(x, y){
		window.scrollTo(x, y); 
	}
	
	function displayLightbox(display){
		overlayd = document.getElementById('overlay');
		overlayd.style.display = display;
	}

function activate(target,URL){
		if(target=='signin'){
			var targetURL = "uyegiris.aspx";
		}else if(target=='addfav'){
			var targetURL = URL;
		}else if(target=='remfav'){
			var targetURL = URL;
		}else{
			alert('Fonksiyonda Bir Hata Var \n Lütfen Sistem Yöneticisi ile İrtibat Kurun');
			return false;
		}
			
		
		addLightBox(targetURL);
		if (browser == 'Internet Explorer'){
			getScroll();
			prepareIE('100%', 'hidden');
			setScroll(0,0);
			hideSelects('hidden');
		}
		displayLightbox("block");
	}

function deactivate(){
	var o=document.getElementById('overlay');
	var l=document.getElementById('lightbox');
	l.parentNode.removeChild(l);
	o.parentNode.removeChild(o);		
		if (browser == "Internet Explorer"){
			setScroll(0,this.yPos);
			prepareIE("auto", "auto");
			hideSelects("visible");
		}	
		//displayLightbox("none");
	}
	
function addLightBox(targetURL) {
	bod 				= document.getElementsByTagName('body')[0];
	overlay 			= document.createElement('div');
	overlay.id		= 'overlay';
	lb					= document.createElement('div');
	lb.id				= 'lightbox';
	lb.innerHTML	= '<div id="lbLoadMessage">' +
						  '<div id="closePopBox">' +
						  '<a href="javascript:deactivate()" class="lbAction">Kapat</a>' + 
						  '</div>' + 
						  '<iframe src="' + targetURL + '" frameborder=0 scrolling="no" id="loginFrame">' + 
						  '</iframe>' +
						  '</div>';
	bod.appendChild(overlay);
	bod.appendChild(lb);

}

/* Display bitti */
/* Sayfa Alti Fonksiyonlari */

function addBookmark(title,url) {
	var title = "Ev Arıyorum.com";
	var url = "http://www.evariyorum.com";
	
	if (window.sidebar) { 
		window.sidebar.addPanel(title, url,""); 
	} else if( document.all ) {
		window.external.AddFavorite( url, title);
	} else if( window.opera && window.print ) {
		return true;
	}
} 



