/*function showFullSearch(key,val,dest,ertext)
{
	if (!key && !full_search && dest == "hidden_fields") return;



	if (val <= 0){

		if (!full_search) alert(ertext);

			else closeFullSearch();

		return;



	}

	

	var temp_dir = (base_dir)?base_dir:"";

	var url = temp_dir+"/fullSearchTable.php?dest="+dest+"&item_type="+val;



	if (document.getElementById) {



		document.getElementById('bufferFrame').src = url;



	} else if (document.all) {



		parent.bufferFrame.document.location = url;




	}



	if (dest == "hidden_fields"){

		full_search = 1;

		document.sleep_search.full.value = 1;

	}

}







function closeFullSearch()



{

	if (!full_search) return;

	if (document.all){

		document.all['hidden_fields'].style.display = "none";



	}else if (document.getElementById) {



		document.getElementById('hidden_fields').style.display = "none";

	}



	full_search = 0;



	document.sleep_search.full.value = 0;

	document.getElementById('close_ad').style.display = 'none';

	document.getElementById('open_ad').style.display = 'block';

	document.getElementById('close_ad2').style.display = 'none';

	document.getElementById('open_ad2').style.display = 'block';

}*/



function loadPlaces(scroll,area)
{
	if (!area)
		return;
	var prev = "";
	for(i=0;i<area.length;i++){
		if (prev != area[i][0]){
			scroll.options[scroll.options.length] = new Option(area[i][1],area[i][0]);
			prev = area[i][0];
		}
	}
}


function loadSelect(id,value)
{
	var sID = parseInt(id) ? 'sett' : 'area';
	var extData = parseInt(id) ? as : ta;
	var select = document.getElementById('search_'+sID);
	
	var val0 = select.options[0];
	select.options.length = 0;
	select.options[0] = val0;
	
	loadPlaces(select,extData[parseInt(value)]);
/*	if(!id)
		loadSelect(1,0);*/
}



function showNewScroll(text)

{

	var itype = document.getElementById('item_type').value;



	if (itype <= 0){

		alert(text);

		return;

	}

	var iplace = document.getElementById('item_area').value;

	var url = "genScroll2.php?item_type="+itype+"&item_area="+iplace;

	if (document.getElementById) {

		document.getElementById('bufferFrame').src = url;

	} else if (document.all) {

		parent.bufferFrame.document.location = url;

	}

}







function loadSourceFinish(id) 

{

	if (document.all) {

		document.all[id].innerHTML = parent.bufferFrame.document.body.innerHTML;

		document.all[id].style.display = "block";

	} else if (document.getElementById) {

		document.getElementById(id).innerHTML = document.getElementById('bufferFrame').contentDocument.body.innerHTML;

		document.getElementById(id).style.display = "block";

	}

	if (document.other_search[4]) 

		document.other_search[4].onchange=function() 

					{

						if (this.value > 0) document.other_search.ofull.value=1;

							else document.other_search.ofull.value=0;

					};

}




function loadScroll(to,type,val1,val2)

{

	if (val1 <= 0) val1 = 0;



	var item = document.getElementById(to);

	var val0 = item.options[0];

	item.innerHTML = "";

	item.options[0] = val0;

	

	if (!place_arr[val1]) return;



	var result = Array();

	if (type == "place"){

		if (val1 > 0){

			if (val2 > 0)

				result = place_arr[val1][val2].slice(1);

			else

				for(k=1;k<place_arr[val1].length;k++)

					result = result.concat(place_arr[val1][k].slice(1));

		} else {

			var upto = (val1 == -1)?4:15;

			for(h=1;h<upto;h++)

				if (place_arr[h])

					if (val2 > 0)

						result = result.concat(place_arr[h][val2].slice(1));

					else

						for(k=1;k<place_arr[h].length;k++)

							result = result.concat(place_arr[h][k].slice(1));

		}

		result = result.sort(cmpOption);

		loadPlaces(item,result);

		return;

	}

	if (type == "area"){

		var end = (val1>0)?val1:"3";

		var strt = (val1>0)?val1:"1";

		for(h=strt;h<=end;h++){

			var tmp = place_arr[h];

			if (tmp)

				for(i=1;i<tmp.length;i++)

					if (tmp[i].length > 0)

						result[result.length] = Array(i,tmp[i][0]);

		}

		result = result.sort(cmpOption);

		var prev = -10;

		for(i=0;i<result.length;i++)

			if (result[i][0] != prev){

				item.options[item.options.length] = new Option(result[i][1],result[i][0]);

				prev = result[i][0];

			}

	}

}




function cmpOption(op1,op2)

{

	if (op1[0] == 0) return -1;

	if (op2[0] == 0) return 1;

	if (op1[1] < op2[1]) return -1;

	if (op1[1] > op2[1]) return 1;

	return 0;

}



function showDateSearch(ind)

{

	var obj1=document.getElementById("info_div_"+ind);

	var obj2=document.getElementById("double_div_"+ind);

	if (!obj1 || !obj2 || obj2.innerHTML == "")

		return;

	var temp = obj1.innerHTML;

	obj1.innerHTML = obj2.innerHTML;

	obj2.innerHTML = temp;

}



function addbookmark(finish,text)
{
	var bmurl = "http://www.cuponim.co.il"+finish;
	var bmtitle = text;
	
	if (document.all);
		window.external.AddFavorite(bmurl,bmtitle);
}

function makeHomepage(finish)
{
	document.body.style.behavior='url(#default#homepage)';
	document.body.setHomePage('http://www.cuponim.co.il'+finish);
}


function tourwiseUpdate(type,area)

{

	if (!tourwise.init){

		tourwise.area = new Array();

		tourwise.sett = new Array();

		for(i=0;i<tour_arr.length;i++){

			var tmp = tour_arr[i];

			if (tourwise.sett[tmp[0]] == undefined) tourwise.sett[tmp[0]] = new Array();

			switch(tmp.length){

				case 3: if (tourwise.area[tmp[0]] == undefined)

							tourwise.area[tmp[0]] = new Array();

						tourwise.area[tmp[0]][tourwise.area[tmp[0]].length] = new Array(tmp[1],tmp[2]);

						break;

				case 4: if (tourwise.sett[tmp[0]][tmp[1]] == undefined)

							tourwise.sett[tmp[0]][tmp[1]] = new Array();

						tourwise.sett[tmp[0]][tmp[1]][tourwise.sett[tmp[0]][tmp[1]].length] = new Array(tmp[2],tmp[3]);

						break;

				default: alert('tourwise error !!!');

			}

		}

		tourwise.init = true;

	}

	

	var typer = new Array();

	if (type <= 0)

		for(i=1;i<20;i++)	

			typer[typer.length] = i;

	else

		typer[0] = type;

	

	var item = document.getElementById('tourwise_place');

	var val0 = item.options[0];

	item.innerHTML = "";

	item.options[0] = val0;

	var places = new Array();

	

	for(i=0;i<typer.length;i++){

		type = typer[i];

		if (tourwise.sett[type])

			if (area != 0){

				if (tourwise.sett[type][area])

					places = places.concat(tourwise.sett[type][area]);

			} else {

				for(k=0;k<tourwise.sett[type].length;k++)

					if (tourwise.sett[type][k])

						places = places.concat(tourwise.sett[type][k]);

			}

	}

	places = places.sort(cmpOption);

	loadPlaces(item,places);

	

	if (area != 0) return;



	var item = document.getElementById('tourwise_area');

	var val0 = item.options[0];

	item.innerHTML = "";

	item.options[0] = val0;

	var places = new Array();

	

	for(i=0;i<typer.length;i++){

		type = typer[i];

		if (tourwise.area[type])

			places = places.concat(tourwise.area[type]);

	}

	places = places.sort(cmpOption);

	loadPlaces(item,places);

}

var printerWin = false;
function updateCoupons(id,act)
{
	var t = {'cpid' : id};
	t['act'] = (act) ? 'add' : 'del';
	JsHttpRequest.query(
		'http://www.cuponim.co.il/updCoup.php'
		, t
		, function(res,err) {
			if (res['ok'] && parseInt(res['ok']) == 1) {
				var tmp = document.getElementById('countDivSpan');
				if (tmp)
					tmp.innerHTML = res['num'];
				else {
					var otmp = window.opener.document.getElementById('countDivSpan');
					if (otmp) {
						otmp.innerHTML = res['num'];
						var pc = window.opener.document.getElementById('gcoup'+res['cid']);
						if (pc)
							pc.checked = parseInt(res['cstat']) ? true : false;
					}
				}
				if (printerWin)
					location.reload();
			} else
				alert(err);
		  }	
		, true
	);
}

function updateStats(ids,type)
{
	var t = {'stt' : type};
	t['cpids'] = ids;
	JsHttpRequest.query(
		'http://www.cuponim.co.il/updStatsCoupon.php'
		, t
		, function(res,err) {
			if (res['ok'] && parseInt(res['ok']) == 1) {
				return;
			} else
				alert(err);
		  }	
		, true
	);
}


  var gright=25;
  var gtop=150;
  var n = (document.getElementById&&!document.all) ? 1:0;
  var ie = (document.all) ? 1:0;
  var oTest;

  function makeBannerObj(obj){
        this.css=document.getElementById(obj).style;
        this.shown = true;
        this.moveIt=b_moveIt;
  /*      this.hide = ohide;
        this.show = oshow;*/
  }
  function b_moveIt(x,y){
        this.x=x; this.y=y;
        //this.css.left=this.x; alert(this.x);
        this.css.right = 0;
        this.css.top=this.y;
  }
/*  function ohide(){
  	this.css.display = 'none'; 
  	document.getElementById('side_b').style.backgroundImage = "url(<?=IMG_DIR?>/header/side_b.jpg)";
  	this.shown = false;
  }
  function oshow(){
  	this.css.display = 'block';
  	document.getElementById('side_b').style.backgroundImage = "url(<?=IMG_DIR?>/header/side_b3.jpg)";
  	this.shown = true;
  }*/
  var pageWidth,pageHeight
  function scrlInit(){
        oTest=new makeBannerObj('countDiv')
        resized()
        onresize=resized
        window.onscroll=checkIt;
  }
  function checkIt(){
  		if (!oTest.shown)
  			return;
        if(ie) oTest.moveIt(document.body.scrollLeft +pageWidth-gright, document.body.scrollTop + gtop)
        else if(n){ oTest.moveIt(window.pageXOffset+pageWidth-gright, window.pageYOffset + gtop)}
        //if(ie) oTest.moveIt(document.body.scrollLeft + gright, document.body.scrollTop + gtop)
        //else if(n){ oTest.moveIt(window.pageXOffset+gright, window.pageYOffset + gtop)}
  }
  function resized(){
        pageWidth=(ie)?document.body.offsetWidth:innerWidth;
        pageHeight=(ie)?document.body.offsetHeight:innerHeight;
 /* 		if (oTest.shown && pageWidth < 970)
  			oTest.hide();
  		if (!oTest.shown && pageWidth >= 970)
  			oTest.show();*/
	    checkIt()
  }

