// pre-load images
var load1=new Image();
load1.src="images/site/minus.gif";
var load2=new Image();
load2.src="images/site/plus.gif";

var lastAjaxTextBox;
// display ajax for the search
function checkAjax(itemID,chrSize)
{
	var strFld = document.getElementById(itemID).value
	var strLen = strFld.length
	//alert("category :"+strFld+" and Length = "+strLen;
	
	var widthD = document.body.clientWidth;
	//var heightD = document.body.clientHeight;
	var leftOffset = (screen.width-765)/2;
	var action;
	//var topOffset = screen.height-heightD;
	
	if (itemID == 'category')
	{
		action = "GetCategories";
		document.getElementById('categoryAJ').style.left = leftOffset+364+'px';
		document.getElementById('cityAJ').style.display = 'none';
	}
	else
	{
		action = "GetCities";
		document.getElementById('cityAJ').style.left = leftOffset+36+'px';
		document.getElementById('categoryAJ').style.display = 'none';
	}

	document.getElementById(itemID+'AJ').style.top = '200px';
	if (strLen >= chrSize) 
	{
		//var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");
		var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		var xmldoc = "";
		xmlhttp.Open("GET", "AjaxActions.aspx?Action="+action+"&Param="+encodeURIComponent(strFld), false);
		xmlhttp.Send(xmldoc);
		document.getElementById(itemID+'AJ').innerHTML = xmlhttp.responseText;
		//document.getElementById(itemID+'AJ').innerHTML= "<a class=""ajaxL"" href=""javascript:inputAjax('ערך 1','category')"">ערך 1</a><br>";
		document.getElementById(itemID+'AJ').style.display = 'inline';
	}
}

// display ajax for the search
function checkAjax2(textBox,itemID,chrSize)
{
	var strFld = textBox.value
	var strLen = strFld.length
	//alert("category :"+strFld+" and Length = "+strLen;
	lastAjaxTextBox = textBox.id;
	var widthD = document.body.clientWidth;
	//var heightD = document.body.clientHeight;
	var leftOffset = (screen.width-765)/2;
	var action;
	//var topOffset = screen.height-heightD;
	
	if (itemID == 'category')
	{
		action = "GetCategories";
		document.getElementById('categoryAJ').style.left = leftOffset+364+'px';
		document.getElementById('cityAJ').style.display = 'none';
	}
	else
	{
		action = "GetCities";
		document.getElementById('cityAJ').style.left = leftOffset+36+'px';
		document.getElementById('categoryAJ').style.display = 'none';
	}

	document.getElementById(itemID+'AJ').style.top = '200px';
	if (strLen >= chrSize) 
	{
		//var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");
		var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		var xmldoc = "";
		xmlhttp.Open("GET", "AjaxActions.aspx?Action="+action+"&Param="+encodeURIComponent(strFld), false);
		xmlhttp.Send(xmldoc);
		//var replacedHtml = xmlhttp.responseText.replace("'"+itemID+"'","'"+textBox.id+"'");
		//alert("Replaced Text: "+replacedHtml);
		
		document.getElementById(itemID+'AJ').innerHTML = xmlhttp.responseText;
		//document.getElementById(itemID+'AJ').innerHTML= "<a class=""ajaxL"" href=""javascript:inputAjax('ערך 1','category')"">ערך 1</a><br>";
		document.getElementById(itemID+'AJ').style.display = 'inline';
	}
}

// insert into ajax
function inputAjax(val,itemID,divID) 
{
 	document.getElementById(lastAjaxTextBox).value = val;
	document.getElementById(itemID+'AJ').style.display = 'none';
}

// hide ajax
function hideAjax() 
{
 	document.getElementById('categoryAJ').style.display = 'none';
	document.getElementById('cityAJ').style.display = 'none';
}

// handle the search
function checkSearch()
{
	var category = document.all.category.value;
	var comapny = document.all.company.value;
	var city = document.all.city.value;
	
	if (category == '' && comapny == '')
	{
		alert('אנא הקלד/י לפחות אחד מהשדות: "תחום" או "חברה" לפני ביצוע החיפוש');
		return;
	}
	else
	{
		document.location.href = 'Results.aspx?Category='+category+'&Company='+comapny+'&City='+city;
	}
}

function checkSearch2(categoryTextBox,companyTextBox)
{
	var category = categoryTextBox.value;
	var comapny = companyTextBox.value;
	
	if (category == '' && comapny == '')
	{
		alert('אנא הקלד/י לפחות אחד מהשדות: "תחום" או "חברה" לפני ביצוע החיפוש');
		return false; // do not post back
	}
	else
	{
	    return true; // post back
		//document.location.href = 'Results.aspx?Category='+category+'&Company='+comapny+'&City='+city;
	}
}

// clear the search fields
function clearSearch()
{
	document.all.category.value = '';
	document.all.company.value = '';
	document.all.city.value = '';
}

// clear the search fields
function clearSearch2(categoryTextBox,companyTextBox,cityTextBox)
{
	categoryTextBox.value = '';
	companyTextBox.value = '';
	cityTextBox.value = '';
}

// display leading subjects
function ShowMenu(objMenu)
{
		if (objMenu.style.display == "none") 
			{
			
            objMenu.style.display = "inline";
			}
        else 
			{
            objMenu.style.display = "none";
			}
}

// hide leading subjects
function HideMenu(objMenu)
{
		if (objMenu.style.display == "none") 
			{
			
            objMenu.style.display = "inline";
			}
        else 
			{
            objMenu.style.display = "none";
			}
}


// display all sics - resualts page
function ShowAllSic(objMenu)
{
		if (objMenu.className == "show_more") 
			{
			
            objMenu.className = "hide_more";
			}
        else 
			{
            objMenu.className = "show_more";
			}
}

// hide all sics - resualts page
function HideAllSic(objMenu)
{
		if (objMenu.className == "show_more") 
			{
			
            objMenu.className = "hide_more";
			}
        else 
			{
            objMenu.className = "show_more";
			}
}


// display or hide details in company page
function displayDtls(itemID)
{
	if (document.getElementById(itemID).style.display == '')
	{
		document.getElementById(itemID).style.display = 'none';
		document.getElementById(itemID+'Img').src = load2.src;
	}
	else
	{
		document.getElementById(itemID).style.display = '';
		document.getElementById(itemID+'Img').src = load1.src;
	}
}

// open big pictures of company in company page
function openBig(folderN,picN)
{
	var source = 'imgBig.aspx?folderN='+folderN+'&picN='+ picN;
	win = window.open(source, "galleryBig", "top=0, left=0, status=no, resizable, scrollbars=yes")
	window.focus;
}


// resize the image page in bigPic page
function changeScreenSize(pic_name)
{
		picture= new Image()
		picture.src=pic_name;
		window.resizeTo(picture.width+50,picture.height+130);
}

// get mouse position
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY ;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }


// open legend div
function openLegend(itemID,secondItem)
{
	
	if (navigator.userAgent.indexOf('MSIE') != -1)
	{
		cX += document.body.scrollLeft
		cY += document.body.scrollTop
	}
	document.getElementById(itemID).style.left = (cX+5) + "px";
	document.getElementById(itemID).style.top = (cY-100) + "px"
	document.getElementById(itemID).style.display = 'inline';
}

// open legend div
function openLegendAdvertise(itemID,secondItem)
{
	
	if (navigator.userAgent.indexOf('MSIE') != -1)
	{
		cX += document.body.scrollLeft
		cY += document.body.scrollTop
	}
	document.getElementById(itemID).style.left = (cX+5) + "px";
	document.getElementById(itemID).style.top = (cY+10) + "px"
	document.getElementById(itemID).style.display = 'inline';
}

// close legend div
function closeLegend(itemID)
{
	document.getElementById(itemID).style.display = 'none';
}

// open popup for banners - all pages
function openAdd(bannerID)
{
    var url = 'Banners/PopUpAd.aspx?'+'BannerId='+bannerID;
	win = window.open(url,'Ad', 'top=5,left=5,height=600,width=400,status=yes,location=no,scrollbars=no,menubars=no,toolbars=no,resizable=no')
	win.focus();
}

function openAddInExternalPage(bannerID)
{
    var url = 'Banners/BannerCount.aspx?'+'BannerId='+bannerID;
	win = window.open(url,'AdInExternal');	
	win.focus();
}

function PrintVerCompany(Duns,CompanyKind)
{
  var url;
  if (CompanyKind == 1)
    url = 'CompanyPagePrint.aspx?Duns='+Duns;
  else
     url = 'CompanyPageNoPrint.aspx?Duns='+Duns;
     win = window.open(url,'PrintVerCompany');	
	 win.focus();
}
