function getObj(objId)
{
	if (document.getElementById)
		return document.getElementById(objId);
	else if (document.all)
	    return document.all[objId];
	else if (document.layers)
	    return document.layers[objId];
	else return false;
}

// AJAX definition........................
function getHTTPObject() 
{
	var httprequest=false;

	if (window.XMLHttpRequest) //  if Mozilla, Safari etc
	{
		httprequest=new XMLHttpRequest()
		if (httprequest.overrideMimeType)
			httprequest.overrideMimeType('text/xml')
	}
	else if (window.ActiveXObject)
	{ // if IE
		try {
			httprequest=new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e)
		{
			try
			{
				httprequest=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){}
		}
	}
	
	return httprequest;
}

var ajax_object=new Object();
//ajax_object.basedomain="http://"+window.location.hostname;
ajax_object.httpreq=getHTTPObject();
ajax_object.addrandomnumber=0; 


function inner_state() 
{
	var _ajax=ajax_object.httpreq;

	if(_ajax.readyState == 1)
	{
		if(ajax_object.tagId != '')
		getObj(ajax_object.tagId).innerHTML = ajax_object.msg;
//		getObj(ajax_object.tagId).innerHTML = '&nbsp;&nbsp;<img src="lifa_emlak/images/spinner.gif">'+ajax_object.msg;
	}
	else if(_ajax.readyState == 4)
	{ 
		var answer = _ajax.responseText;
		
		if(answer.search(/redirect:/) != -1)
		{
			var redirect=answer.split("redirect:")[1];
			top.location.href=redirect;
		}
		else if(ajax_object.tagId != '')
			getObj(ajax_object.tagId).innerHTML = answer;
	}
}

ajax_object.getAjaxRequest=function(url, parameters, callbackfunc,tagId,msg)
{

	ajax_object.httpreq=getHTTPObject();
	ajax_object.tagId=tagId;
	ajax_object.msg=msg;
	
	if (ajax_object.addrandomnumber==1) 
		var parameters=parameters+"&ajaxcachebust="+new Date().getTime();

		if (this.httpreq)
		{
			this.httpreq.onreadystatechange=callbackfunc;
			this.httpreq.open('GET.html', url+"?"+parameters, true);
			this.httpreq.send(null);
		}
}

ajax_object.postAjaxRequest=function(url, parameters, callbackfunc,tagId,msg)
{
	ajax_object.httpreq=getHTTPObject();
	ajax_object.tagId=tagId;
	ajax_object.msg=msg;

	if (this.httpreq)
	{
		this.httpreq.onreadystatechange = callbackfunc;
		this.httpreq.open('POST.html', url, true);
		this.httpreq.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=windows-1254");
		this.httpreq.setRequestHeader("Content-length", parameters.length);
		this.httpreq.setRequestHeader("Connection", "close");
		this.httpreq.send(parameters);
	}
}
// -------------------------
ajax_object.AjaxRequest=function(method,url, parameters, callbackfunc)
{
	ajax_object.httpreq=getHTTPObject();
	ajax_object.tagId='';
	ajax_object.msg='';

	if (this.httpreq)
	{
	if (ajax_object.addrandomnumber==1) 
		var parameters=parameters+"&ajaxcachebust="+new Date().getTime();

		this.httpreq.onreadystatechange = callbackfunc;

		this.httpreq.open(method, url, true);
		
		if(method == 'POST'){
			this.httpreq.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=windows-1254");
			this.httpreq.setRequestHeader("Content-length", parameters.length);
			this.httpreq.setRequestHeader("Connection", "close");
			this.httpreq.send(parameters);
		}
		else
			this.httpreq.send(null);
	}	
}
 
 // =================================== Ajax end ===========================================================================
var error_email_msg='??? e-mail';
var popWindow;

// Mail ===============================================
function isEmail(who) {
	var email=/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;
	return(email.test(who));
}


function check_email(email)
{
	if(isEmail(email.value) == false)
	{
		email.value=error_email_msg;
		email.focus();
		return false;
	}
	return true;
}


function check_requiredinput(frm)
{
	prefix='chk_';

	var input_count=(frm.all.tags("INPUT"))?frm.all.tags("INPUT").length:0;
	input_count+=(frm.all.tags("TEXTAREA"))?frm.all.tags("TEXTAREA").length:0;
	input_count+=(frm.all.tags("SELECT"))?frm.all.tags("SELECT").length:0;

	var re='/'+prefix+'/i';
	var email=/email/;

	var first_input=null;

	this.alertfunc=function(input)
	{
		if(input.name.match(eval(email)))
		{
			if (!check_email(input))
			{
				if(!first_input) first_input=input;
				return false;
			}
			
			return true;
		}
		else if(input.name.match(eval(re)) && ((input.value == '') || (input.value == '???')))
		{
			alert_str='???';

			input.value=alert_str;

			if(!first_input) first_input=input;
			return false;
		}

		return true;
	}

	var retval=true;
	
	for (var i=0; i < input_count;i++)
		if(frm.all.tags("INPUT")[i]) 
			retval =retval && this.alertfunc(frm.all.tags("INPUT")[i]);

	for (var i=0; i < input_count;i++)
		if(frm.all.tags("TEXTAREA")[i])
			retval =retval && this.alertfunc(frm.all.tags("TEXTAREA")[i]);

	if(!retval) first_input.focus();

	return retval;
}

// ============================ Field kontrol end =============================================================

// ============================= chekcklerin hepsinin kontrolu ================================================
function sel_allchk(ischekced,prefix)
{
	if(!prefix) prefix='sel_';

	var input_count=document.all.tags("INPUT").length;

	var re='/'+prefix+'/i';

	for (var i=0; i < input_count;i++)
	{
		window.status='count: '+input_count+ ' / '+i;
		if(document.all.tags("INPUT")[i].type == 'checkbox')
		{
			var new_str=new String(document.all.tags("INPUT")[i].name);

			if(new_str.match(eval(re)))
				document.all.tags("INPUT")[i].checked=ischekced;
		}
	}

	window.status='';
}

// ============================= form daki verilerin düzenlenmesi ================================================


function init_fields(frm,data)
{
	this.text_value=function(obj)
	{
		if(data[obj.name])
		{
			obj.value=data[obj.name];
		}
	}

	this.check_value=function(obj)
	{
		if(data[obj.name])
		{
			obj.checked=true;
		}
	}

	this.radio_value=function(obj)
	{
		if(data[obj.name])
		{
			obj.checked=(obj.value == data[obj.name]);
		}
	}

	this.select_value=function(obj)
	{
		if(data[obj.name])
		{
			for (var i = 0; i < obj.options.length; i++) 
				if(obj.options[i].value == data[obj.name])
					obj.options[i].selected=true;
		}
	}

	this.textarea_value=function(obj)
	{
		if(data[obj.name])
		{
			obj.value=data[obj.name];
		}
	}

	var input_count=(frm.all.tags("INPUT"))?frm.all.tags("INPUT").length:0;
	input_count+=(frm.all.tags("TEXTAREA"))?frm.all.tags("TEXTAREA").length:0;
	input_count+=(frm.all.tags("SELECT"))?frm.all.tags("SELECT").length:0;

	// Dikkat : Bu tür ayrık döngüler bilerek yapılmıştır. !!!!!!!!!!!!!!!!!
	for (var i=0; i < input_count;i++)
	{		
		if(frm.all.tags("INPUT") && frm.all.tags("INPUT")[i])
		{
			if(frm.all.tags("INPUT")[i].type == 'text') 
			{
				this.text_value(frm.all.tags("INPUT")[i]);
			}
			else if(frm.all.tags("INPUT")[i].type == 'checkbox') 
			{
				this.check_value(frm.all.tags("INPUT")[i]);
			}
			else if(frm.all.tags("INPUT")[i].type == 'radio') 
			{
				this.radio_value(frm.all.tags("INPUT")[i]);
			}
		}
	}

	for (var i=0; i < input_count;i++)
	{		
		if(frm.all.tags("SELECT") && frm.all.tags("SELECT")[i])
		{
			this.select_value(frm.all.tags("SELECT")[i]);
		}
	}

	for (var i=0; i < input_count;i++)
	{		
		if(frm.all.tags("TEXTAREA") && frm.all.tags("TEXTAREA")[i])
		{
			this.textarea_value(frm.all.tags("TEXTAREA")[i]);
		}
	}
}

// =======================================
function ctrl_buttons(sender)
{
	var btn=getObj('btnDelete');
	if(btn)
		btn.disabled=true;
	
	var btn=getObj('btnNew');
	if(btn)
		btn.disabled=true;

	var btn=getObj('btnUpdate');
	if(btn)
		btn.disabled=true;

	var btn=getObj('btnRelease');
	btn.value=sender.name;

	sender.form.submit();
}

function openNewWindow(sURL, sName, iWidth, iHeight, titlebar,bResizable, bScrollbars,iLeft,iTop)
{
	if(!iWidth)
		iWidth=screen.height / 2;

	if(!iHeight)
		iHeight=screen.height / 2;

	if(!iTop)
		var iTop  = (screen.height - iHeight) / 2 ;	
	if(!iLeft)
		var iLeft = (screen.width  - iWidth) / 2 ;


	var sOptions = "toolbar=no" ;	
	sOptions += ",width=" + iWidth ; 
	sOptions += ",height=" + iHeight ;	
	sOptions += ",resizable="  + (!bResizable ? "no" : bResizable) ;
	sOptions += ",scrollbars=" + (!bScrollbars ? "no" : bScrollbars) ;
	sOptions += ",left=" + iLeft ;
	sOptions += ",top=" + iTop ;
	sOptions += ",titlebar=" + (!titlebar ? "no" : titlebar) ;


	return  window.open(sURL, sName, sOptions);
}

function show_popup(theURL,features) 
{
	if(popWindow)
		popWindow.close();

	popWindow=window.open(theURL,"popupwin",features);
	popWindow.focus();
}

function popup_returnmsg(sender,title,filename,file)
{
	if(popWindow)
		popWindow.close();

	popWindow = openNewWindow("indexcff0.html?popupfile="+file+"&filename="+filename+"&title="+title+"&"+sender.url, 
		"returnmsg",800, 650) ;

	popWindow.focus();
}

function edit_fotoimgs(sender,id,_class,_classfile) 
{
	if(popWindow)
		popWindow.close();

	popWindow = openNewWindow("indexeeac.html?popupfile=popbrwsimg.php&amp;class="+_class+'&classfile='+_classfile+
		"&func=update_img&id="+id+"&path="+sender.filepath+"&senderid="+sender.id+
		"&title=Resim Duzenleme",
		"UploadWin",760, 560) ;
	popWindow.focus();
}

function cursor_shape(shape)
{
	document.body.style.cursor=shape;
}

function redirect(newpage)
{
	window.location=newpage;
}

function change_reccount(sender,page)
{
	redirect(page+'&'+sender.name+'='+sender.value);
}

// regular expression kullanılıyor param_name de
// /&page=\w+/ gibi
function change_urlparam(values,param_name,param_value)
{
	var str=new String(values);

	if(str.match(param_name)){
		str=str.replace(param_name,param_value);
	}
	else if(param_value != "")
	{
		str+=param_value;
	}

	return str;
}

function ftimage_show(filepath,width,height,top,left,option)
{
	if(popWindow)
		popWindow.close();

	if(!width) width=400;
	if(!height)	height=400;
	if(!top)  top  = (screen.height - height) / 2 ;	
	if(!left) left = (screen.width  - width) / 2 ;

	popWindow=window.open("","ProductImage",option+",toolbar=0,top="+top+",left="+left+",width="+width+",height="+height);
	popWindow.document.write('<head>');
	popWindow.document.write("<title>Resim</title>");
	popWindow.document.write('</head>');
	popWindow.document.write('<body id="popup" style="margin:0;"><center><img src="'+filepath+'" width="100%" height="100%" /></center>');//width="100%" height="100%"
	popWindow.document.write('</body>');
	popWindow.focus();
}

// options elemtinin doldurulması
// options parametresi array[]array[0..1] şeklindedir.0 : value, 1 : text değerleridir.
function selection_elem(_selection,_options,selectedvalue)
{

	this.select=_selection;

		this.add_option=function(value,text){
			var option=document.createElement('OPTION');
			option.value=value;
			option.text=text;
			this.select.options.add(option);
		}

		this.delete_option=function(index){
			this.select.options[index]=null;
		}

		this.clear_options=function(){
			for(var i=this.select.options.length-1; i >=1; i--)
				this.delete_option(i);
		}


	this.clear_options();

	if(_options)
		for(var i=0; i < _options.length;i++)
			this.add_option(_options[i][0],_options[i][1]);

	this.select.value=selectedvalue;
}

var img_window=null;

function close_imagewindow()
{
	if (img_window)
		img_window.close();
}

function image_show(filepath,title,width,height,top,left)
{
	close_imagewindow();
	if(!width)	width=450;
	if(!height) height=400;
	if(!top)  top  = (screen.height - height) / 2 ;	
	if(!left) left = (screen.width  - width) / 2 ;

	img_window=window.open("","ProductImage","top="+top+",left="+left+",toolbar=0, resizable=yes,width="+width+","+"height="+height);
	img_window.document.write('<head>');
	img_window.document.write("<title>"+title+"</title>");
	img_window.document.write('</head>');
	img_window.document.write('<body id="popup" style="margin:0;"><img src="'+filepath+'" width="100%" height="100%" >');
	img_window.document.write('</body>');
}

function image_pop(sender,title,width,height)
{
	image_show(sender.src,title,width,height);
}


// ======================
function tagEvent(currrentElement,data)
{
	if( (currrentElement.tagName == 'INPUT') || (currrentElement.tagName == 'SELECT')
		|| (currrentElement.tagName == 'TEXTAREA'))
	{
		if((currrentElement.type == 'submit') || (currrentElement.type == 'button'))
			currrentElement.parentElement.innerHTML='';
		else if (currrentElement.type == 'checkbox'){// Çok seçmeli ise seçilmeyenler çizilir.
			var parent=currrentElement.parentElement;
			var str=currrentElement.getAdjacentText("afterEnd");
			var data=(data[currrentElement.name])?data[currrentElement.name]:'';
			if(data == ''){
				currrentElement.replaceAdjacentText("afterEnd","");
				currrentElement.insertAdjacentHTML("afterEnd",'<span style="color:gray;text-decoration: line-through;">'+str+'</span>');
			}
			
			 parent.removeChild(currrentElement);
		}
		else // Tek seçmeli ise seçilen
			currrentElement.parentElement.innerHTML=(data[currrentElement.name])?data[currrentElement.name]:'';


	}
}

/*
Node u silme
//text-decoration: line-through
			var parent=currrentElement.parentElement;
			 parent.removeChild(currrentElement);

*/

function traverse_dom(currentElement,onTag,data)
{
	if(currentElement)
	{
		 // Traverse the tree
		var i=0;
		var currentElementChild=currentElement.childNodes[i];
	
		while(currentElementChild)
		{	
			// Event...
			onTag(currentElementChild,data);

			// Recursively traverse the tree structure of the child node
			traverse_dom(currentElementChild,onTag,data);

			i++;
			currentElementChild=currentElement.childNodes[i];
		}
	}
}

function katm_over(sender)
{
  if(sender.style.backgroundColor == 'red')
	sender.style.backgroundColor='';
  else
	sender.style.backgroundColor='red';
}

function katshow_tree(sender)
{
	
	var item=getObj('sub'+sender.id);

	if (item)
	{
		item.style.display=(item.style.display != 'block')?'block':'none';
		if(item.style.display == 'block')
			sender.className='katselected';
		else
			sender.className='';
		sender.style.backgroundImage=(item.style.display == 'block')?'url(UserFiles/Image/diropen.gif)':'url(UserFiles/Image/dirclose.gif)';
	}
}


function change_kur(sender)
{
	var ktipi=getObj('kurtipi');

	if(ktipi)
	switch(ktipi.value){
	 case 'YTL':
			sender.innerText='«« $';
			ktipi.value='USD';
			break;
	 case 'USD':
			sender.innerText='«« €';
			ktipi.value='EURO';
			break;
	 case 'STERLIN':
			sender.innerText='«« £';
			ktipi.value='STERLIN';
			break;
	default:
			sender.innerText='«« TL';
			ktipi.value='YTL';
	}

	return true;
}

function new_productimage(id,menuid)
{
	if(popWindow)
		popWindow.close();

	popWindow = openNewWindow("indexd941.html?popupfile=popproductimg.php&amp;title=Urun Resmi&amp;id="+id+"&menuid="+menuid,
		"UploadWin",500, 110) ;
	popWindow.focus();
}

function new_specialimage(id)
{
	if(popWindow)
		popWindow.close();

	popWindow = openNewWindow("index6090.html?popupfile=popspecialimg.php&amp;title=Special Image&amp;id="+id,
		"UploadWin",500, 110) ;
	popWindow.focus();
}

function poppage(url,option)
{
	if(popWindow)
		popWindow.close();

	if(!option)
		option="scrollbars=1, resizable=yes,width=650, height=600";

	popWindow=window.open(url,"poppage",option);

	popWindow.focus();
}

function add_newsmem(email,filen)
{
	if(check_email(email) == true){
		show_popup('index4b14.html?popupfile=externals/processform.p.php&amp;newsmem=1&amp;chk_email='+email.value+'&filen='+filen+'&frmnewsmem=1',
			'width=515,height=400,top=200,left=200');
	}
}

function close_div(objname)
{
	var obj=getObj(objname);
	if(!obj) return;
	obj.style.display=(obj.style.display == 'block')?'none':'block';
}

