function toggleDetails(formName,id)
{
    var hid = eval("hidden"+formName+id);
    var img = eval("openclose"+formName+id);
    hid.style.display=hid.style.display=="none" ? "" : "none";
    img.style.backgroundPosition=hid.style.display=="none" ? "-71px" : "0";
    if (hid.style.display=="")
        ajaxSendViewCount(id);
}

function ajaxSendViewCount(id)
{
    xmlReq = null;
    if(window.XMLHttpRequest) xmlReq = new XMLHttpRequest();
    else if(window.ActiveXObject) xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
    if(xmlReq==null) return;
    xmlReq.open ('GET', 'http://site4sale.co.il/reportView.php?id='+id, true);
    xmlReq.send (null);
}

function toggleBackground(obj,check)
{
    obj.style.backgroundColor=check?"FFFFCC":"#FFFFFF";
}

function redirect(url)
{
    location.href=url;
}

function newWindow(action)
{
    window.open("","newWindow","width=700,height=500,toolbar=0,scrollbars=yes");
    var a = window.setTimeout(action,500);
}

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 addCat()
{
    cats_names=document.getElementById('catsnames');
    cats_remove=document.getElementById('catsremove');
    arr=postForm.arr;
    id=postForm.cat.value;
    if (id!=-1)
        addCatToList();
    else
        for(i=1; i<postForm.cat.options.length; i++)
        {
            id=postForm.cat.options[i].value;
            addCatToList();
        }
}

function addCatToList()
{
    if (names.indexOf("לא נבחרו קטגוריות.")!=-1)
    {
        names="";
        cats_names.innerHTML=names;
    }
    if (arr.value.indexOf(","+id+",")==-1 && arr.value.indexOf(id+",")!=0 && (arr.value.indexOf(","+id)!=arr.value.length - id.length - 1 || arr.value.length - id.length - 1==-1))
    {
        if (arr.value!="")
            arr.value+=",";
        arr.value+=id;
        option = eval("categories"+id);
        optionName=option.innerHTML;
        names += optionName + "<br>";
        cats_names.innerHTML=names;
        remove += '<a style="cursor: pointer;" onclick="removeCat('+id+');"><u>הסר בחירה</u></a><br>';
        cats_remove.innerHTML=remove;
    }
}

function removeCat(id)
{
    cats_names=document.getElementById('catsnames');
    cats_remove=document.getElementById('catsremove');
    arr=postForm.arr;
    arrSplitted = arr.value.split(",");
    arr.value="";
    first = 1;
    for (i=0; i<arrSplitted.length; i++)
        if (arrSplitted[i]!=id)
        {
            if (first==0)
                arr.value+=",";
            arr.value+=arrSplitted[i];
            first=0;
        }

    option=eval("categories"+id);
    optionName=option.innerHTML;
    names=names.replace(optionName + "<br>", "");
    cats_names.innerHTML=names;
    if (names=="") names="לא נבחרו קטגוריות."; cats_names.innerHTML=names;
    remove=remove.replace('<a style="cursor: pointer;" onclick="removeCat('+id+');"><u>הסר בחירה</u></a><br>','');
    cats_remove.innerHTML=remove;
}

function validateLink(link,msg)
{
    var choice=confirm(msg);
    if (choice)
        location.href=link;
}
