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 open_new_window(site){
	window.open(site, '_blank', 'status=yes,menubar=yes,resizable=yes,scrollbars=yes,width=740,height=650','bReplace=false');
}
function show_advance_message_floatBlank(id,type){
	window.open('functions/show_advance_message.php?id='+id+'&type='+type, '_blank', 'status=no,menubar=no,resizable=no,scrollbars=yes,width=740,height=650','bReplace=false');
}
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 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 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_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 show_user_panel(){
    document.getElementById('user_panel_login').style.display='';
}
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 close_float_message(id){
    document.getElementById('show_advance_message_'+id).style.display='none';
}
function printMessage(id){
	window.open('http://www.visher.co.il/messages/advance_message_print_view.php?id='+id, '_blank', 'status=no,menubar=no,resizable=no,scrollbars=yes,width=670,height=570','bReplace=false');
}
function drawPicturesBlank(id){
    window.open('http://www.visher.co.il/functions/show_pictures.php?id='+id, '_blank', 'status=no,menubar=no,resizable=no,scrollbars=yes,width=700,height=500','bReplace=false');
}
function compare_messages(value,type){
    if(type==8){
        var height=480;
    }
    else{
        var height=750;
    }
    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 if(tempArr.length>5){
            alert('יש לבחור עד 4 מודעות לצורך ביצוע השוואה');
        }
        else
        {
            window.open('functions/compare_messages.php?val='+str+'&type='+type, 'newwin', 'status=no,menubar=no,resizable=yes,scrollbars=yes,width=750,height='+height);
        }
    }
}
function go_to_page(value,link){
	if(link=='/'){
		window.location = link+'?pn='+value;
	}
	else{
		window.location = link+'&pn='+value;	
	}    
}
function display_picture(id,picture){
	if(document.getElementById('big_picture1_'+id)){
    document.getElementById('big_picture1_'+id).style.display='none';
	}
	if(document.getElementById('big_picture2_'+id)){
    document.getElementById('big_picture2_'+id).style.display='none';
	}
    if(document.getElementById('big_picture3_'+id)){
    document.getElementById('big_picture3_'+id).style.display='none';
	}    
    document.getElementById(picture).style.display='';
}
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 setHomePage(){
    this.style.behavior='url(#default#homepage)';
    this.setHomePage('http://www.codelifter.com');
}
function bookmarksite(){
    if (document.all){
        window.external.AddFavorite('http://www.Visher.co.il', 'Visher - לוח הרכב הגדול במדינה');
    }
    else if (window.sidebar){
        window.sidebar.addPanel('Visher - לוח הרכב הגדול במדינה', 'http://www.Visher.co.il', "Visher - לוח הרכב הגדול במדינה")
    }
}
function display_area(){
    document.getElementById('more_area').style.display='';
    document.getElementById('more_area1').style.display='';
    document.getElementById('more_area2').style.display='';
    document.getElementById('more_area3').style.display='';
    document.getElementById('area_0').style.display='';
    document.getElementById('area_1').style.display='';
    document.getElementById('area_2').style.display='none';
}
function close_area(){
    document.getElementById('more_area').style.display='none';
    document.getElementById('more_area1').style.display='none';
    document.getElementById('more_area2').style.display='none';
    document.getElementById('more_area3').style.display='none';
    document.getElementById('area_0').style.display='none';
    document.getElementById('area_1').style.display='none';
    document.getElementById('area_2').style.display='';
}
function adv_search(){
    document.getElementById('search_table').style.backgroundImage = 'url(images/panels/search_panel/search_advanced_bg.gif)';
    document.getElementById('search_table').style.height = '102px';
    document.getElementById('adv_search_1').style.display ='';
    document.getElementById('adv_search_2').style.display ='';
    document.getElementById('normal_search_button').src='images/panels/search_panel/search_regular_2_btn.gif';
    document.getElementById('adv_search_button').src='images/panels/search_panel/search_advanced_1_btn.gif';
}
function normal_search(){
    document.getElementById('search_table').style.backgroundImage = 'url(images/panels/search_panel/search_regular_bg.gif)';
    document.getElementById('search_table').style.height = '60px';
    document.getElementById('adv_search_1').style.display ='none';
    document.getElementById('adv_search_2').style.display ='none';
    document.getElementById('normal_search_button').src='images/panels/search_panel/search_regular_1_btn.gif';
    document.getElementById('adv_search_button').src='images/panels/search_panel/search_advanced_2_btn.gif';
}
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 go_to_index(){
    window.location = 'http://www.Visher.co.il';
}
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 = '';
}