// check if the browser is Navigator 3 or higher:
agent = navigator.userAgent;
browserVer = 2;
if (agent.substring(0,7) == "Mozilla")
{
    if (parseInt(agent.substring(8,9)) >= 3) {browserVer = 1;}
}


/************* AUTOLOGIN ****************/
/*
function saveLogin(auto)
{
    if(auto==true) 
    {
        alert("val ON= "+auto);
        
    }
    else alert("val OFF= "+auto);
}
*/

/************* MENU ***************/

function menuClick3(mname1, mname2, mname3)
{
	el1 = document.getElementById(mname1);
	if (el1.style.display == "none")
    {
        el1.style.display="";
        createCookie(mname1,"yes");
    }
	else
    {
        el1.style.display="none";
        createCookie(mname1,"none");
    }

	el2 = document.getElementById(mname2);
	if (el2.style.display == "none")
    {
        el2.style.display="";
        createCookie(mname2,"yes");
    }
	else
    {
        el2.style.display="none";
        createCookie(mname2,"none");
    }

	el3 = document.getElementById(mname3);
	if (el3.style.display == "none")
    {
        el3.style.display="";
        createCookie(mname3,"yes");
    }
	else
    {
        el3.style.display="none";
        createCookie(mname3,"none");
    }
}

function menuClick(mname)
{
	el = document.getElementById(mname);
	if(el)
	{
		if (el.style.display == "none")
		{
			el.style.display="";
			createCookie(mname,"yes");
		}
		else
		{
			el.style.display="none";
			createCookie(mname,"none");
		}    
	}
}

function menuClick(mname, btnname)
{
	el = document.getElementById(mname);
    button = document.getElementById(btnname);
	if(el)
	{
		if (el.style.display == "none")
		{
			if(button) button.src="img/menu-collapse.gif";
			el.style.display="";
			createCookie(mname,"yes");
		}
		else
		{
			if(button) button.src="img/menu-expand.gif";
			el.style.display="none";
			createCookie(mname,"none");
		}
	}
}

function menuRelationClick(mname)
{
	menuClick(mname);
	document.getElementById('relObjectName').value='';
}

function checkdouble(objForCheck)
{
	var elementText=objForCheck.value;
	objForCheck.value=elementText.replace(",",".");
}

function RepEventMenu(mname)
{
	el = document.getElementById(mname);
    for(i=0; i<5;i++)
    {
        el2 = document.getElementById(i);
        if(el != el2)
        {
                el2.style.display="none";
                document.getElementById("b"+i).checked=false;
        }  
    }
    el.style.display="";
    document.getElementById("b"+mname).checked=true;
}


function showAdvanced(mname, btnname, defval)
{
    el = document.getElementById(mname);
    button = document.getElementById(btnname);
    if(el)
    {
        val = getCookieVal(mname);
        if(val==null) 
        {
            if(defval==null) val="none";
            else val=defval;
        }
        if (val == "none")
        {
            if(button) button.src="img/menu-expand.gif";
            el.style.display="none";
        }
        else
        {
            if(button) button.src="img/menu-collapse.gif";
            el.style.display="";
        }
    }
}
/*function showAdvanced(mname)
{
    alert('showAdvanced 1 parametr');
    el = document.getElementById(mname);
    if(el)
    {
        val = getCookieVal(mname);
        if (val == "none" || val==null)
        {
            el.style.display="none";
        }
        else
        {
            el.style.display="";
        }
    }
}*/

function searchMenuShow(nameEla,nameElb,nameElc)
{
	qbeSearch=document.getElementById(nameElb);
	yposy=findPosY(qbeSearch);
	document.getElementById(nameEla).style.top=yposy+4;
	/*if (document.getElementById(nameElc))
	{
		whichSearch=document.getElementById(nameElc);
		xposx=findPosX(whichSearch);	
	}
	else
	{
		xposx=189;
	}*/
    xposx=192;
    document.getElementById(nameEla).style.left=xposx;
    menuShow(nameEla);
    maxwidth = document.getElementById(nameEla).offsetWidth+60;
    totheight = document.getElementById(nameEla).offsetHeight+40;
    var hcode;

if (document.all)
{
	//alert ("maxwidth:"+maxwidth+" totheight:"+totheight+" xposx:"+xposx+" yposy:"+yposy);
    sel=document.all.tags("SELECT"); //:this.win.document.getElementsByTagName("SELECT");
    //CHECKING FOR SELECT BOXES
    for(i=0;i<sel.length;i++)
    {
        selx=0; sely=0; var selp;
        if(this.sel[i].offsetParent){selp=sel[i]; while(selp.offsetParent){selp=selp.offsetParent; selx+=selp.offsetLeft; sely+=selp.offsetTop;}}
        selx+=sel[i].offsetLeft; sely+=sel[i].offsetTop
        selw=sel[i].offsetWidth; selh=sel[i].offsetHeight
        if(((selx+selw)>xposx && selx<(xposx+maxwidth))&&((sely+selh)>yposy && sely<(yposy+totheight)))
        {
            if(sel[i].style.visibility!="hidden"){sel[i].style.visibility="hidden"; hcode+=this.name+".sel["+i+"].style.visibility='visible';"}
        }
    }
}
	menuShow(nameEla);
}
function searchMenuHide(nameEla)
{
	if (document.all)
	{
		maxwidth = document.getElementById(nameEla).offsetWidth+60;
		totheight = document.getElementById(nameEla).offsetHeight+40;
	    var hcode;
	
	    sel=document.all.tags("SELECT"); //:this.win.document.getElementsByTagName("SELECT");
	    //CHECKING FOR SELECT BOXES	
	   		for(i=0;i<sel.length;i++)
	    	{
	        	selx=0; sely=0; var selp;
	        	if(this.sel[i].offsetParent){selp=sel[i]; while(selp.offsetParent){selp=selp.offsetParent; selx+=selp.offsetLeft; sely+=selp.offsetTop;}}
	        	selx+=sel[i].offsetLeft; sely+=sel[i].offsetTop
	        	selw=sel[i].offsetWidth; selh=sel[i].offsetHeight
	        	if(((selx+selw)>xposx && selx<(xposx+maxwidth))&&((sely+selh)>yposy && sely<(yposy+totheight)))
	        	{
	            	if(sel[i].style.visibility!="visible"){sel[i].style.visibility="visible"; hcode+=this.name+".sel["+i+"].style.visibility='hidden';"}
	        	}
	    	}
	}
	document.getElementById(nameEla).style.display="none";

}

function menuShow(mname)
{
	el = document.getElementById(mname);
	if (el && el.style.display == "none") el.style.display="";
}

function menuHide(mname)
{
	el = document.getElementById(mname);
	if (el && el.style.display != "none") el.style.display="none";
}

function uncheck(fname, chname)
{
	el = document.forms[fname].elements[chname];
    if(el) el.checked = false;
}


function GoToURL(menu)
{
	URL = menu.options[menu.selectedIndex].value;
	if (URL.length > 0)
	{
		window.location.href = URL;
	}
}

function getPosition(element)
{
  var elem=element,tagname="",x=0,y=0;

  while ((typeof(elem)=="object")&&(typeof(elem.tagName)!="undefined"))
  {
    y+=elem.offsetTop;
    x+=elem.offsetLeft;
    tagname=elem.tagName.toUpperCase();

    if (tagname=="BODY") elem=0;

    if (typeof(elem)=="object")
      if (typeof(elem.offsetParent)=="object")
        elem=elem.offsetParent;
  }

  position=new Object();
  position.x=x;
  position.y=y;
  return position;
}

var txtFieldForMail = null;
var cancelHideFav = false;
var cancelFavMailSelector=false;

function showFavMails(txtField)
{
    if (cancelFavMailSelector) return;
	el = document.getElementById('favoriteMailsTable');
    txtPos = getPosition(txtField);
    el.style.left=txtPos.x+60;
    el.style.top=txtPos.y+20;
    el.style.display="";
    txtFieldForMail = txtField;
    cancelHideFav = true;
    maxwidth=el.offsetWidth;
    totheight=el.offsetHeight;
    xposx=txtPos.x+60;
    yposy=txtPos.y+20;
    var hcode;
    //alert (maxwidth+" "+totheight+" "+xposx+" "+yposy+" sum:"+(maxwidth+totheight+xposx+yposy));
    if (document.all)
{
    sel=document.all.tags("SELECT"); //:this.win.document.getElementsByTagName("SELECT");
    //CHECKING FOR SELECT BOXES
    for(i=0;i<sel.length;i++)
    {
    	//alert (this.sel[i].offsetParent);
        selx=0; sely=0; var selp;
        if(this.sel[i].offsetParent){selp=sel[i]; while(selp.offsetParent){selp=selp.offsetParent; selx+=selp.offsetLeft; sely+=selp.offsetTop;}}
        selx+=sel[i].offsetLeft; sely+=sel[i].offsetTop;
        selw=sel[i].offsetWidth; selh=sel[i].offsetHeight;
        if(((selx+selw)>xposx && selx<(xposx+maxwidth))&&((sely+selh)>yposy && sely<(yposy+totheight)))
        {
        	//alert (selx+selw+">"+xposx+"&"+selx+"<"+xposx+maxwidth+"]&["+sely+selh+">"+yposy+"&"+sely+"<"+yposy+totheight);
            if(sel[i].style.visibility!="hidden"){sel[i].style.visibility="hidden"; hcode+=this.name+".sel["+i+"].style.visibility='visible';"}
        }
    }
}

}

function hideFavMails(txtField)
{
    if (cancelFavMailSelector) return;
    if (document.all)
    {
	    el = document.getElementById('favoriteMailsTable');
	      maxwidth=el.offsetWidth;
	    totheight=el.offsetHeight;
	    xposx=txtPos.x+60;
	    yposy=txtPos.y+20;
	    var hcode;
	    //alert ('show select');
	    sel=document.all.tags("SELECT"); //:this.win.document.getElementsByTagName("SELECT");
		    //CHECKING FOR SELECT BOXES	
		   		for(i=0;i<sel.length;i++)
		    	{
		        	selx=0; sely=0; var selp;
		        	if(this.sel[i].offsetParent){selp=sel[i]; while(selp.offsetParent){selp=selp.offsetParent; selx+=selp.offsetLeft; sely+=selp.offsetTop;}}
		        	selx+=sel[i].offsetLeft; sely+=sel[i].offsetTop
		        	selw=sel[i].offsetWidth; selh=sel[i].offsetHeight
		        	if(((selx+selw)>xposx && selx<(xposx+maxwidth))&&((sely+selh)>yposy && sely<(yposy+totheight)))
		        	{
		            	if(sel[i].style.visibility!="visible"){sel[i].style.visibility="visible"; hcode+=this.name+".sel["+i+"].style.visibility='hidden';"}
		        	}
		    	}
	}
    cancelHideFav = false;
    setTimeout("realHideFavMails()", 200);

}

function realHideFavMails(txtField)
{
	//alert ('hide'+cancelHideFav);
    if (!cancelHideFav)
    {
    	
        el = document.getElementById('favoriteMailsTable');
        txtPos = getPosition(txtField);
	    	el.style.display="none";
        txtFieldForMail = null;
	}
}

function putFavMail(addr)
{
    cancelHideFav = true;
    currVal = txtFieldForMail.value;
    if (currVal.length > 0)
    {
        txtFieldForMail.value=txtFieldForMail.value + ", " +addr;
    }
    else txtFieldForMail.value=addr;
    txtFieldForMail.focus();
}

/************* PICKER ***************/


function show_picker(entity,
    custValueTarget, custLabelTarget,
    oppValueTarget, oppLabelTarget,
    caseValueTarget, caseLabelTarget,
    constraints, canUnselect)
{
	var pickerWind = window.open(entity+"Pick.do?custValueTarget="+custValueTarget+"&custLabelTarget="+custLabelTarget+
        "&oppValueTarget="+oppValueTarget+"&oppLabelTarget="+oppLabelTarget+
        "&caseValueTarget="+caseValueTarget+"&caseLabelTarget="+caseLabelTarget+
        (canUnselect ? "&unselect=yes":"")+"&constraints="+constraints,
		"Picker", "width=520,height=400,status=yes,resizable=yes,top=200,left=200,scrollbars=yes");
	pickerWind.opener = self;
	pickerWind.focus();
}

/*
function show_person_picker(custValueTarget, custLabelTarget, personValueTarget, branchValueTarget, constraints, canUnselect)
{
	var pickerWind = window.open("customerPick.do?custValueTarget="+custValueTarget+"&custLabelTarget="+custLabelTarget+
        "&personValueTarget="+personValueTarget+"&branchValueTarget="+branchValueTarget+
        (canUnselect ? "&unselect=yes":"")+"&constraints="+constraints,
		"Picker", "width=500,height=400,status=yes,resizable=yes,top=200,left=200,scrollbars=yes");
	pickerWind.opener = self;
	pickerWind.focus();
}
*/
function show_person_picker(custValueTarget, custLabelTarget, personValueTarget, branchValueTarget, constraints, defPerson, defBranch, canUnselect)
{
	show_person_picker(custValueTarget, custLabelTarget, personValueTarget, branchValueTarget, constraints, defPerson, defBranch, canUnselect, false)
}
function show_person_picker(custValueTarget, custLabelTarget, personValueTarget, branchValueTarget, constraints, defPerson, defBranch, canUnselect, disableDefault)
{
    var pickerWind = window.open("customerPick.do?custValueTarget="+custValueTarget+"&custLabelTarget="+custLabelTarget+
        "&personValueTarget="+personValueTarget+"&branchValueTarget="+branchValueTarget+
        "&defPerson="+defPerson+"&defBranch="+defBranch+
        (canUnselect ? "&unselect=yes":"")+"&constraints="+constraints+"&disableDefault="+disableDefault,
		"Picker", "width=500,height=400,status=yes,resizable=yes,top=200,left=200,scrollbars=yes");
	pickerWind.opener = self;
	pickerWind.focus();
}

function show_people_picker(custValueTarget, custLabelTarget, canUnselect)
{
    var pickerWind = window.open("personPick.do?custValueTarget="+custValueTarget+"&custLabelTarget="+custLabelTarget+
		(canUnselect ? "&unselect=yes":""),"Picker",
		"width=500,height=400,status=yes,resizable=yes,top=200,left=200,scrollbars=yes");
	pickerWind.opener = self;
	pickerWind.focus();
}

function show_offer_picker(parentValueTarget, parentLabelTarget, oppValueTarget, oppLabelTarget, custValueTarget, custLabelTarget, personValueTarget, branchValueTarget, constraints, canUnselect)
{
    var pickerWind = window.open("offerPick.do?parentValueTarget="+parentValueTarget+"&parentLabelTarget="+parentLabelTarget+"&oppValueTarget="+oppValueTarget+"&oppLabelTarget="+oppLabelTarget+"&custValueTarget="+custValueTarget+
        "&custLabelTarget="+custLabelTarget+"&personValueTarget="+personValueTarget+"&branchValueTarget="+branchValueTarget+
        (canUnselect ? "&unselect=yes":"")+"&constraints="+constraints,
		"Picker", "width=500,height=400,status=yes,resizable=yes,top=200,left=200,scrollbars=yes");
	pickerWind.opener = self;
	pickerWind.focus();
}

function show_branch_picker(custValueTarget, custLabelTarget, branchValueTarget, constraints, defBranch, canUnselect)
{
	show_person_picker(custValueTarget, custLabelTarget, 'NULL', branchValueTarget, constraints, 0, defBranch, canUnselect);
}

function show_customer_picker(custValueTarget, custLabelTarget, constraints, canUnselect)
{
	var pickerWind = window.open("customerPick.do?custValueTarget="+custValueTarget+"&custLabelTarget="+custLabelTarget+
        (canUnselect ? "&unselect=yes":"")+"&constraints="+constraints,
		"Picker", "width=500,height=400,status=yes,resizable=yes,top=200,left=200,scrollbars=yes");
	pickerWind.opener = self;
	pickerWind.focus();
}

function show_mail_picker(recipTarget, constraints)
{
	var pickerWind = window.open("mailPick.do?recipTarget="+recipTarget+"&constraints="+constraints,
		"Picker", "width=500,height=400,status=no,resizable=yes,top=200,left=200,scrollbars=yes");
	pickerWind.opener = self;
	pickerWind.focus();
}

function show_list_picker(valueTarget, labelTarget, listName, canUnselect)
{
	var pickerWind = window.open("listPick.do?valueTarget="+valueTarget+"&labelTarget="+labelTarget+"&listName="+listName+(canUnselect ? "&unselect=yes":""),
		"Picker", "width=400,height=400,status=no,resizable=yes,top=200,left=200,scrollbars=yes");
	pickerWind.opener = self;
	pickerWind.focus();
}

function show_product_picker(valueTarget, labelTarget, canUnselect)
{
	var pickerWind = window.open("productPick.do?valueTarget="+valueTarget+"&labelTarget="+labelTarget+(canUnselect ? "&unselect=yes":""),
		"Picker", "width=480,height=360,status=no,resizable=yes,top=200,left=200,scrollbars=yes");
	pickerWind.opener = self;
	pickerWind.focus();
}

function show_contact_picker(valueTarget, labelTarget, canUnselect)
{
	var pickerWind = window.open("contactPick.do?valueTarget="+valueTarget+"&labelTarget="+labelTarget+(canUnselect ? "&unselect=yes":""),
		"Picker", "width=480,height=360,status=no,resizable=yes,top=200,left=200,scrollbars=yes");
	pickerWind.opener = self;
	pickerWind.focus();
}

function show_task_picker(valueTarget, labelTarget, canUnselect)
{
	var pickerWind = window.open("taskPick.do?valueTarget="+valueTarget+"&labelTarget="+labelTarget+(canUnselect ? "&unselect=yes":""),
		"Picker", "width=480,height=360,status=no,resizable=yes,top=200,left=200,scrollbars=yes");
	pickerWind.opener = self;
	pickerWind.focus();
}


function show_task_full_picker(custValueTarget, custLabelTarget,
    oppValueTarget, oppLabelTarget,
    caseValueTarget, caseLabelTarget,
    offValueTarget, offLabelTarget,
    entityValueTarget, entityLabelTarget,
    constraints, canUnselect)
{
	var pickerWind = window.open("taskFullPick.do?custValueTarget="+custValueTarget+"&custLabelTarget="+custLabelTarget+
        "&oppValueTarget="+oppValueTarget+"&oppLabelTarget="+oppLabelTarget+
        "&caseValueTarget="+caseValueTarget+"&caseLabelTarget="+caseLabelTarget+
        "&offValueTarget="+offValueTarget+"&offLabelTarget="+offLabelTarget+
        "&entityValueTarget="+entityValueTarget+"&entityLabelTarget="+entityLabelTarget+
        (canUnselect ? "&unselect=yes":"")+"&constraints="+constraints,
		"Picker", "width=520,height=400,status=yes,resizable=yes,top=200,left=200,scrollbars=yes");
	pickerWind.opener = self;
	pickerWind.focus();
}


function show_bcitem_full_picker(custValueTarget, custLabelTarget,
    oppValueTarget, oppLabelTarget,
    caseValueTarget, caseLabelTarget,
    offValueTarget, offLabelTarget,
    entityValueTarget, entityLabelTarget,
    constraints, canUnselect)
{
	var pickerWind = window.open("busCaseItemFullPick.do?custValueTarget="+custValueTarget+"&custLabelTarget="+custLabelTarget+
        "&oppValueTarget="+oppValueTarget+"&oppLabelTarget="+oppLabelTarget+
        "&caseValueTarget="+caseValueTarget+"&caseLabelTarget="+caseLabelTarget+
        "&offValueTarget="+offValueTarget+"&offLabelTarget="+offLabelTarget+
        "&entityValueTarget="+entityValueTarget+"&entityLabelTarget="+entityLabelTarget+
        (canUnselect ? "&unselect=yes":"")+"&constraints="+constraints,
		"Picker", "width=520,height=400,status=yes,resizable=yes,top=200,left=200,scrollbars=yes");
	pickerWind.opener = self;
	pickerWind.focus();
}

function show_event_picker(valueTarget, labelTarget, canUnselect)
{
	var pickerWind = window.open("eventPick.do?valueTarget="+valueTarget+"&labelTarget="+labelTarget+(canUnselect ? "&unselect=yes":""),
		"Picker", "width=480,height=360,status=no,resizable=yes,top=200,left=200,scrollbars=yes");
	pickerWind.opener = self;
	pickerWind.focus();
}

function show_event_full_picker(custValueTarget, custLabelTarget,
    oppValueTarget, oppLabelTarget,
    caseValueTarget, caseLabelTarget,
    offValueTarget, offLabelTarget,
    entityValueTarget, entityLabelTarget,
    constraints, canUnselect)
{
	var pickerWind = window.open("eventFullPick.do?custValueTarget="+custValueTarget+"&custLabelTarget="+custLabelTarget+
        "&oppValueTarget="+oppValueTarget+"&oppLabelTarget="+oppLabelTarget+
        "&caseValueTarget="+caseValueTarget+"&caseLabelTarget="+caseLabelTarget+
        "&offValueTarget="+offValueTarget+"&offLabelTarget="+offLabelTarget+
        "&entityValueTarget="+entityValueTarget+"&entityLabelTarget="+entityLabelTarget+
        (canUnselect ? "&unselect=yes":"")+"&constraints="+constraints,
		"Picker", "width=520,height=400,status=yes,resizable=yes,top=200,left=200,scrollbars=yes");
	pickerWind.opener = self;
	pickerWind.focus();
}

function show_folder_picker(valueTarget, labelTarget, canUnselect)
{
	var pickerWind = window.open("folderPick.do?valueTarget="+valueTarget+"&labelTarget="+labelTarget+(canUnselect ? "&unselect=yes":""),
		"Picker", "width=480,height=360,status=no,resizable=yes,top=200,left=200,scrollbars=yes");
	pickerWind.opener = self;
	pickerWind.focus();
}

function show_buscaseitem_picker(customer,inv)
{
	var pickerWind = window.open("busCaseItemPick.do?customer="+customer+"&inv="+inv,
		"Picker", "width=480,height=360,status=no,resizable=yes,top=200,left=200,scrollbars=yes");
	pickerWind.opener = self;
	pickerWind.focus();
}


function show_user_picker(valueTarget, form)
{
    show_user_picker_detailed(valueTarget, form, "resTitle", "responsible");
}

function show_user_picker_detailed(valueTarget, form, titleTarget, comboTarget)
{
    if (valueTarget.charAt(0) == "#") 
    {
        valueTarget = valueTarget.substring(1);
        isGroup = true;
    }
    else 
    {
        isGroup=false;
    }
	var pickerWind = window.open("userPick.do?titleTarget="+titleTarget+"&comboTarget="+comboTarget+"&valueTarget="+valueTarget+"&form="+form+(isGroup ? "&isGroup=yes":""),
		"Picker", "width=225,height=325,status=no,resizable=yes,top=200,left=200,scrollbars=yes");
	pickerWind.opener = self;
	pickerWind.focus();
}

function show_image_picker(clazz, srcId, cust, target)
{
    var picker = window.open("../../../picturePick.do?customer="+cust+"&clazz="+clazz+"&srcId="+srcId+"&target="+target,
		"Picker", "width=435,height=355,status=no,resizable=yes,top=200,left=200,scrollbars=yes");
	picker.opener = self;
	picker.focus();
}

function show_document_picker(types, target)
{
    var picker = window.open("../../../documentPick.do?types="+types+"&target="+target,
		"Picker", "width=435,height=355,status=no,resizable=yes,top=200,left=200,scrollbars=yes");
	picker.opener = self;
	picker.focus();
}

function refLink(entity, id)
{
    if (id=='0' || id=='') return;
    var action;
    if (entity == 'customer') action = 'editCustomer.do?id=';
    else if (entity == 'buscase') action = 'editBusCaseLow.do?id=';
    else if (entity == 'opportunity') action = 'editOpportunity.do?id=';
    else if (entity == 'offer') action = 'editOffer.do?id=';
    else if (entity == 'task') action = 'editTask.do?id=';
    else if (entity == 'event') action = 'editEvent.do?id=';
    else if (entity == 'picture') action = 'openPicture.do?id=';
    window.location = action + id;
}

function refLinkBlank(entity, id)
{
    if (id=='0' || id=='') return;
    var action;
    if (entity == 'customer') action = 'editCustomer.do?id=';
    else if (entity == 'buscase') action = 'editBusCaseLow.do?id=';
    else if (entity == 'opportunity') action = 'editOpportunity.do?id=';
    else if (entity == 'offer') action = 'editOffer.do?id=';
    else if (entity == 'task') action = 'editTask.do?id=';
    else if (entity == 'event') action = 'editEvent.do?id=';
    else if (entity == 'picture') action = 'openPicture.do?id=';
    okno = window.top.open(action+id, 'InTouch CRM', 'directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
    if(okno!=null) okno.location.replace(action+id);
}

/************* CONFIRM SELECTOR ***************/

function confirmSelector(msg)
{
    idx = document.selectorForm.what.selectedIndex;
    if (document.selectorForm.what.options[idx].value.indexOf("confirm=yes") > 0)
    {
        return confirm(msg);
    }
    return true;
}

/************* SHOW ADDRESS ***************/

function showAddress()
{
    if (document.all.selector[0].checked)
    {
        document.all.str.style.display = "";
        document.all.strM.style.display = "none";
        if (document.all.str1)
        {
            document.all.str1.style.display = "";
            document.all.str1M.style.display = "none";
        }
        if (document.all.str2)
        {
            document.all.str2.style.display = "";
            document.all.str2M.style.display = "none";
        }
        document.all.cty.style.display = "";
        document.all.ctyM.style.display = "none";
        document.all.zp.style.display = "";
        document.all.zpM.style.display = "none";
		document.all.ctr.style.display = "";
        document.all.ctrM.style.display = "none";
		document.all.ste.style.display = "";
        document.all.steM.style.display = "none";
    }
    if (document.all.selector[1].checked)
    {
        document.all.strM.style.display = "";
        document.all.str.style.display = "none";
        if (document.all.str1M)
        {
            document.all.str1M.style.display = "";
            document.all.str1.style.display = "none";
        }
        if (document.all.str2M)
        {
            document.all.str2M.style.display = "";
            document.all.str2.style.display = "none";
        }
        document.all.ctyM.style.display = "";
        document.all.cty.style.display = "none";
        document.all.zpM.style.display = "";
        document.all.zp.style.display = "none";
		document.all.ctrM.style.display = "";
        document.all.ctr.style.display = "none";
		document.all.steM.style.display = "";
        document.all.ste.style.display = "none";
    }
}

function showState()
{
    if (document.getElementById('countryList').value=='us')
    {
        document.all.stateText.style.display = "";
        document.all.stateValue.style.display = "";
    }
    else
    {
		document.all.stateText.style.display = "none";
        document.all.stateValue.style.display = "none";
    }
}

function savePresence(type, value, word)
{
	window.location = "savePresence.do?type="+type+"&value="+value+"&word="+word+"&newLogin=true";
    /* newLogin is here because of automatical login. */
}

function replanContact(id, reason, days, hours)
{
	window.location = "replanContact.do?id="+id+"&days="+days+"&hours="+hours+"&reason="+reason;
}

function getCookieVal(cookieName)
{
    thisCookie = document.cookie.split("; ");
    for (i=0; i<thisCookie.length; i++)
    {
        if (cookieName == thisCookie[i].split("=")[0])
        {
            return thisCookie[i].split("=")[1];
        }
    }
    return null;
}

function createCookie(cookieName, value)
{
    createCookie(cookieName, value, null);
}

function createCookie(cookieName, value, expireDate)
{

   /* ex = new Date;
    ex.setMonth(ex.getMonth+6);
    document.cookie=cookieName+"="+value+";expires="+ex.toGMTString();*/
    //alert("tvorim = >"+expireDate+"<"+(expireDate==undefined));
    if(expireDate==undefined)
    {
        document.cookie=cookieName+"="+value;
    }
    else
    {
        document.cookie=cookieName+"="+value+";expires="+expireDate;
    }
    //alert("cookies = "+document.cookie);
}


function closeNotifyGroupWindow(after)
{
    var expireDate = new Date();
    expireDate.setDate(365 + expireDate.getDate());
    createCookie("notification_after", after, expireDate);
    window.location = "postGroupedNotification.do?after="+after;
}

function formatZip(zip)
{
    var formated = "";
    for(i=0;i<zip.length;i++)
    {
        if(zip.charAt(i)!=' ') formated = formated + zip.charAt(i);
    }
    return formated;
}

function changeBgColor(ob,back)
{    
    if(back)
    {
        ob.style.backgroundColor = "#E5F2FF";
    }
    else
    {
        ob.style.backgroundColor = "#CCE5FF";
    }
}

function showHideRichText()
{
    
    var type = document.getElementById('contactType');
    var richRow = document.getElementById('richRow');
    var typeValue = type.options[type.selectedIndex].value;
    if (typeValue == 2 || typeValue == 4)
    {
        richRow.style.display = "";
    }
    else
    {
        richRow.style.display = "none";
    }
}

function showContactRichText(form,isnew, multi)
{    
    el = document.getElementById('changedType');
    el.value = 'true';
    //document.getElementById('letterBody').change;
    //alert(document.getElementById('letterBody').value);
    //butt = document.getElementById('save');
    //butt.click();
    form.save.disabled = false; 
    form.submit();
}

function ignoreLastOptions(vyber, pocet)
{
    i = 1;
    if(pocet>vyber.length-1) pocet = vyber.length -1;
    while(i<=pocet && vyber.selectedIndex!=0)
    {
        if(vyber.selectedIndex == vyber.length-i)
        {
            vyber.selectedIndex = 0;
        }
        i++;
    }
}

function changeStyle(elName, className)
{
    for(i=1;i<32;i++)
    {
        el = document.getElementById(elName+'_'+i);
        if(el)
        {
            el.className=className;
        }
    }
}

function CheckAll(f,el)
{
	for (var i=0;i<f.elements.length;i++)
	{
		var e=f.elements[i];
		if (e.name==el) e.checked=!e.checked;
	}
}

/*****Find object position*****/

function findPosX(obj) 

{ 

    var curleft = 0; 

    if (obj.offsetParent) 

    { 

        while (obj.offsetParent) 

        { 

			curleft += obj.offsetLeft;

            obj = obj.offsetParent; 

        } 

    } 

    else if (obj.x) 

	{

        curleft += obj.x;

	} 

    return curleft; 

} 

 

function findPosY(obj) 

{ 

    var curtop = 0; 

    var printstring = ''; 

    if (obj.offsetParent) 

    { 

        while (obj.offsetParent) 

        { 

            printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop; 

            curtop += obj.offsetTop 

            obj = obj.offsetParent; 

        } 

    } 

    else if (obj.y) 

        curtop += obj.y; 

    return curtop+1; //+1 to align under white line - intouch only

}


var oFlag = null;
function openWindow(src) 
{
  if (oFlag) oFlag.close();
  oFlag = window.open(src,"preview",'toolbar=0,location=0,scrollbars=no,width=345,height=361,resizable=1,top=20,left=20,menu=no,status=no,hotkeys=no');
  if (oFlag && oFlag.opener == null) oFlag.opener = window;
}

