var Drag = {
	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]),
		parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};
function removeElementPrivate(divNum) {
	var d = document.getElementById('user_person_message');
	var olddiv = document.getElementById(divNum);
	d.removeChild(olddiv);
}
function getAllCookies() {
	var cookies_str='';
	var cookies  = document.cookie.replace(/ /g,"").split(";");
	for (var i = 0; i < cookies.length; i++){
		cookiePair = cookies[i].split("=");
		
		var splits = cookiePair[0].split("note_");
        if(splits.length==1){            
	  		cookies_str = cookies_str+'@'+cookiePair[0]+'!'+cookiePair[1];
        }
	}
	return cookies_str;
}
function search_value_back(value){
	if(value==''){
		document.getElementById('search_text').value='טקסט חופשי';
	}
}
function search_value(value){
	document.getElementById('search_text').value='';
}
function show_main_message_panel(){
	document.getElementById('all_result').style.display = '';
	document.getElementById('user_person_message').style.display = 'none';
	if(document.getElementById('other_result_like')){
		removeElementPrivate('other_result_like');
	}
	if(document.getElementById('other_result_decline')){
		removeElementPrivate('other_result_decline');
	}
	if(document.getElementById('other_result_call')){
		removeElementPrivate('other_result_call');
	}
	if(document.getElementById('other_result_see')){
		removeElementPrivate('other_result_see');
	}
	document.getElementById('like_count').style.backgroundImage = "url(images/panels/main/grey_tab.gif)";
	document.getElementById('like_count').style.color = "#000000";
	document.getElementById('decline_count').style.backgroundImage = "url(images/panels/main/grey_tab.gif)";
	document.getElementById('decline_count').style.color = "#000000";
	document.getElementById('call_count').style.backgroundImage = "url(images/panels/main/grey_tab.gif)";
	document.getElementById('call_count').style.color = "#000000";
	document.getElementById('see_count').style.backgroundImage = "url(images/panels/main/grey_tab.gif)";
	document.getElementById('see_count').style.color = "#000000";
}
function show_filter_message_user(type){
	getAllCookies();
	document.getElementById('all_result').style.display = 'none';

	show_filter_message_live(type,getAllCookies());
	document.getElementById('user_person_message').style.display = '';

	if(type=='like'){
		if(document.getElementById('other_result_decline')){
			removeElementPrivate('other_result_decline');
		}
		if(document.getElementById('other_result_call')){
			removeElementPrivate('other_result_call');
		}
		if(document.getElementById('other_result_see')){
			removeElementPrivate('other_result_see');
		}
				
		document.getElementById('like_count').style.backgroundImage = "url(images/panels/main/blue_tab_down.gif)";
		document.getElementById('like_count').style.color = "#FFFFFF";
		document.getElementById('decline_count').style.backgroundImage = "url(images/panels/main/grey_tab.gif)";
		document.getElementById('decline_count').style.color = "#000000";
		document.getElementById('call_count').style.backgroundImage = "url(images/panels/main/grey_tab.gif)";
		document.getElementById('call_count').style.color = "#000000";
		document.getElementById('see_count').style.backgroundImage = "url(images/panels/main/grey_tab.gif)";
		document.getElementById('see_count').style.color = "#000000";
	}
	else if(type=='decline'){
		if(document.getElementById('other_result_like')){
			removeElementPrivate('other_result_like');
		}
		if(document.getElementById('other_result_call')){
			removeElementPrivate('other_result_call');
		}
		if(document.getElementById('other_result_see')){
			removeElementPrivate('other_result_see');
		}
		
		document.getElementById('like_count').style.backgroundImage = "url(images/panels/main/grey_tab.gif)";
		document.getElementById('like_count').style.color = "#000000";
		document.getElementById('decline_count').style.backgroundImage = "url(images/panels/main/blue_tab_down.gif)";
		document.getElementById('decline_count').style.color = "#FFFFFF";
		document.getElementById('call_count').style.backgroundImage = "url(images/panels/main/grey_tab.gif)";
		document.getElementById('call_count').style.color = "#000000";
		document.getElementById('see_count').style.backgroundImage = "url(images/panels/main/grey_tab.gif)";
		document.getElementById('see_count').style.color = "#000000";
	}
	else if(type=='see'){
		if(document.getElementById('other_result_decline')){
			removeElementPrivate('other_result_decline');
		}
		if(document.getElementById('other_result_like')){
			removeElementPrivate('other_result_like');
		}
		if(document.getElementById('other_result_call')){
			removeElementPrivate('other_result_call');
		}
		document.getElementById('like_count').style.backgroundImage = "url(images/panels/main/grey_tab.gif)";
		document.getElementById('like_count').style.color = "#000000";
		document.getElementById('decline_count').style.backgroundImage = "url(images/panels/main/grey_tab.gif)";
		document.getElementById('decline_count').style.color = "#000000";
		document.getElementById('call_count').style.backgroundImage = "url(images/panels/main/grey_tab.gif)";
		document.getElementById('call_count').style.color = "#000000";
		document.getElementById('see_count').style.backgroundImage = "url(images/panels/main/blue_tab_down.gif)";
		document.getElementById('see_count').style.color = "#FFFFFF";
	}
	else if(type=='call'){
		if(document.getElementById('other_result_decline')){
			removeElementPrivate('other_result_decline');
		}
		if(document.getElementById('other_result_like')){
			removeElementPrivate('other_result_like');
		}
		if(document.getElementById('other_result_see')){
			removeElementPrivate('other_result_see');
		}
		document.getElementById('like_count').style.backgroundImage = "url(images/panels/main/grey_tab.gif)";
		document.getElementById('like_count').style.color = "#000000";
		document.getElementById('decline_count').style.backgroundImage = "url(images/panels/main/grey_tab.gif)";
		document.getElementById('decline_count').style.color = "#000000";
		document.getElementById('call_count').style.backgroundImage = "url(images/panels/main/blue_tab_down.gif)";
		document.getElementById('call_count').style.color = "#FFFFFF";
		document.getElementById('see_count').style.backgroundImage = "url(images/panels/main/grey_tab.gif)";
		document.getElementById('see_count').style.color = "#000000";
	}
}

function show_float_note(id){
	document.getElementById('div_float_note_'+id).style.display='';
	var x_px = (findPosX(document.getElementById('td_float_note_'+id))-250)+'px';
	document.getElementById('div_float_note_'+id).style.left=x_px;
}
function hide_float_note(id){
	document.getElementById('div_float_note_'+id).style.display='none';
}
function close_float_message(id){
	document.getElementById('show_advance_message_'+id).style.display='none';
}
function show_advance_message_floatBlank(id){
	window.open('functions/show_advance_message.php?id='+id, '_blank', 'status=no,menubar=no,resizable=no,scrollbars=yes,width=740,height=650','bReplace=false');
}
function adv_professional_view(id){
window.open('professionals/functions/draw_propessional_cube_advance.php?id='+id, '_blank', 'status=no,menubar=no,resizable=no,scrollbars=yes,width=640,height=440','bReplace=false');
}
function getMouseXY(e) {
	if (IE) {
		tempX = event.clientX + document.body.scrollLeft
		tempY = event.clientY + document.body.scrollTop
	} else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX
		tempY = e.pageY
	}

	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0}
	if(document.getElementById('MouseX') && document.getElementById('MouseY')){
		document.getElementById('MouseX').value = tempX
		document.getElementById('MouseY').value = tempY
	}
	return true
}
function undo_edit_picture(num,img_name){
	document.getElementById(img_name).style.display='none';
	document.getElementById('delete_img_'+num).style.display='';
	document.getElementById('edit_img_'+num).style.display='';
	document.getElementById('edit_message_pic_'+num).style.display='';
	document.getElementById('undo_edit_picture_'+num).style.display='none';
}
function edit_image(num,img_name,id){
	document.getElementById(img_name).style.display='';
	document.getElementById('delete_img_'+num).style.display='none';
	document.getElementById('edit_img_'+num).style.display='none';
	document.getElementById('edit_message_pic_'+num).style.display='none';
	document.getElementById('undo_edit_picture_'+num).style.display='';
}
function edit_user_password(){
	var obj = document.getElementById('edit_user_password');
	var obj_image = document.getElementById('arrow_change_password');

	if(obj.style.display=='none'){
		obj.style.display='';
		obj_image.src='images/panels/edit_user_panel/arrow_up.gif';
	}
	else{
		obj.style.display='none';
		obj_image.src='images/panels/edit_user_panel/arrow_down.gif';
	}
}
function draw_info(info_name){
	document.getElementById('logout_info').style.display='none';
	document.getElementById('edit_details_info').style.display='none';
	document.getElementById('new_message_info').style.display='none';
	document.getElementById(info_name).style.display='';
}
function hide_info(){
	document.getElementById('logout_info').style.display='none';
	document.getElementById('edit_details_info').style.display='none';
	document.getElementById('new_message_info').style.display='none';
}
function new_user(){
	document.getElementById('exist_user').style.display = 'none';
	document.getElementById('new_user').style.display = '';
}
function exist_user(){
	document.getElementById('new_user').style.display = 'none';
	document.getElementById('exist_user').style.display = '';
}
function logout(){
	window.location = 'index.php?page=logout';
}
function go_to_index(){
	window.location = 'http://www.Tarazan.co.il';
}
function show_user_panel(){
	document.getElementById('user_panel_login').style.display='';
}
function drawPicturesBlank(id){
	window.open('http://www.tarazan.co.il/functions/show_pictures.php?id='+id, '_blank', 'status=no,menubar=no,resizable=no,scrollbars=yes,width=740,height=650','bReplace=false');
}
function setNavigationBG(image,id){
	document.getElementById('navigation_table').style.backgroundImage = 'url(/images/panels/navigation/'+image+')';
	setNavigationColor(id);
}
function setUserPanelPosition(){
	var winHeight = getPageSize();
	var obj =document.getElementById('user_panel');

	obj.style.top=""+(winHeight-37)+"px";
}
function getPageSizeY(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {  // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return windowHeight;
}
function getPageSizeX(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {  // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return windowWidth;
}
function setNavigationColor(id){
	document.getElementById('link_sell').style.color='#FFFFFF';
	document.getElementById('link_rent').style.color='#FFFFFF';
	document.getElementById('link_find').style.color='#FFFFFF';
	document.getElementById(id).style.color='#017FD8';
}
function go_to_page(value,page,area,order,pn,ot){
	if(page=='search'){
		window.location = window.location.href+'&pn='+value;
	}
	else{
		if(page!=''){
			var page = '?page='+page;
			if(area!=''){
				var area = '&area='+area;
			}
			if(order!=''){
				var order = '&order='+order;
			}
			if(ot!=''){
				if(ot==1){
					ot==0;
				}
				else if(ot==0){
					ot==1;
				}
				var ot = '&ot='+ot;
			}
			window.location = page+'&pn='+value+area+order+ot;
		}
		else if(area!=''){
			var area = '?area='+area;
			if(order!=''){
				var order = '&order='+order;
			}
			if(ot!=''){
				if(ot==1){
					ot==0;
				}
				else if(ot==0){
					ot==1;
				}
				var ot = '&ot='+ot;
			}
			window.location = area+'&pn='+value+order+ot;
		}
		else if(order!=''){
			var order = '?order='+order;
			if(ot!=''){
				if(ot==1){
					ot==0;
				}
				else if(ot==0){
					ot==1;
				}
				var ot = '&ot='+ot;
			}
			window.location = order+ot+'&pn='+value+ot;
		}
		else{
			window.location = '?pn='+value;
		}
	}
}
function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
	while(1)
	{
		curleft += obj.offsetLeft;
		if(!obj.offsetParent)
		break;
		obj = obj.offsetParent;
	}
	else if(obj.x)
	curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
	while(1)
	{
		curtop += obj.offsetTop;
		if(!obj.offsetParent)
		break;
		obj = obj.offsetParent;
	}
	else if(obj.y)
	curtop += obj.y;
	return curtop;
}

function closeReportError(elemId){
	document.getElementById(elemId).style.display='none';
}
function closeContactOwner(elemId){
	document.getElementById(elemId).style.display='none';
}
function viewProgerssBar()
{
	var obj = document.getElementById("loadingcontainer");
	var obj2 = document.getElementById("loading");
	obj2.style.display='';
	obj.style.display='';
	document.getElementById("open_message").style.display='none';
	document.getElementById("open_message_2").style.display='none';

	var so = new SWFObject("/images/flash/loading.swf", "sotester", "240", "230", "9", "#ffffff");
	so.write("loading");
}
function display_picture(id,picture,note){
	document.getElementById('big_picture1_'+id).style.display='none';
	document.getElementById('big_picture2_'+id).style.display='none';
	document.getElementById('big_picture3_'+id).style.display='none';
	document.getElementById('big_picture4_'+id).style.display='none';
	document.getElementById('big_picture5_'+id).style.display='none';
	if(note==''){
		note = '&nbsp;';
	}
	document.getElementById('what_in_the_picture_'+id).innerHTML=note;
	document.getElementById(picture).style.display='';
}
function display_area(){
	document.getElementById('more_area').style.display='';
	document.getElementById('more_area2').style.display='';
	document.getElementById('area_0').style.display='';
	document.getElementById('area_1').style.display='';
	document.getElementById('area_2').style.display='none';
	document.getElementById('close_adv_area').style.display='';
}
function close_area(){
	document.getElementById('more_area').style.display='none';
	document.getElementById('more_area2').style.display='none';
	document.getElementById('area_0').style.display='none';
	document.getElementById('area_1').style.display='none';
	document.getElementById('area_2').style.display='';
	document.getElementById('close_adv_area').style.display='none';
}
function compare_messages(value){
	var str='';
	var splits = value.split("##");

	for(i=1; i<(splits.length); i++)
	{
		var obj = 'checkbox_'+splits[i];

		if(document.getElementById(obj)){
			if(document.getElementById(obj).checked==true)
			{
				str = str+'gui'+splits[i];
			}
		}
	}
	if(str=='')
	{
		alert('לא נבחרו מודעות');
	}
	else
	{
		var tempArr = str.split("gui");
		if(tempArr.length==2)
		{
			alert('יש לבחור לפחות 2 מודעות לצורך ביצוע השוואה');
		}
		else
		{
			window.open('functions/compare_messages.php?val='+str, 'newwin', 'status=no,menubar=no,resizable=yes,scrollbars=yes,width=850,height=800');
		}
	}
}
function printMessage(id){
	window.open('http://www.tarazan.co.il/functions/show_advance_message.php?id='+id+'&type=print', '_blank', 'status=no,menubar=no,resizable=no,scrollbars=yes,width=670,height=570','bReplace=false');
}
