﻿

var isIe6=(navigator.appVersion.indexOf("MSIE 6")>-1 || navigator.appVersion.indexOf("MSIE 5")>-1);
var openerWind=window.opener;
var inter=0;
var cur=1;
var pics=[];
var isOver=0;
var wind=0;
var intDr=0;
var intDir=1;
var intAmount=4;
var intSpeed=30;

var inChPics=0;
var inChPics2=0;

function dr(){
	
	var el=document.getElementById("ifr");
	if(el){
		//alert(intAmount*intDir);
		el.contentWindow.scrollBy(intAmount*intDir,0);
	}
}

function chPics(){
	//alert(cur+" "+pics.length);
	//var el=document.getElementById("picsExp_id");
	replacePic("picsExp_id",100,pics[cur].pic,pics[cur].w,pics[cur].h,0,0,1);
	
	//el.src=pics[cur];
	cur++;
	if(cur==pics.length){
		cur=0;
	}
}

function flipSecondPage(){
	var el=document.getElementById("picsDiv");
	if(el.style.display==""){
		el.style.display="none";
		return;
	}
	el.style.top=(document.documentElement.scrollTop+400)+"px";
	//alert(screen.availWidth-parseInt(el.style.width));
	el.style.left=((document.body.offsetWidth-parseInt(el.style.width))/2)+"px";		
	el.style.display="";

	if(isIe6){

		
		rndPngImg("picsDiv_right");
		rndPngImg("picsDiv_left");
		rndPngImg("picsDiv_leftArrow");
		rndPngImg("picsDiv_rightArrow");
		rndPngImg("picsDiv_x");
	}
	
}

function rndPngBg(id){
	var td=document.getElementById(id);
	if(!td){
		return ;
	}
	
	if(td.style.backgroundImage){
		var imgName = td.style.backgroundImage.replace(")","").replace("url(","");
		if(imgName.toUpperCase().substring(imgName.length-3, imgName.length) == "PNG"){
			//alert(imgName);
			td.style.backgroundImage="";
			td.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+imgName+"',sizingMethod='scale')";
			
		}
	}
	
}

function rndPngImg(id){
	var td=document.getElementById(id);
	if(!td){
		return ;
	}
	
	if(td.src && td.src!="images/space.gif"){
		var imgName = td.src;
		if(imgName.toUpperCase().substring(imgName.length-3, imgName.length) == "PNG"){
			//alert(imgName);
			td.src="images/space.gif";
			td.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+imgName+"',sizingMethod='scale')";
			
		}
	}
	
}

function revPic(src,w,h,title){
	var elPic=document.getElementById("mainImgReal");//mainImgReal
	
	
	var elTitle=document.getElementById("mainImgTitle");
	
	var el=document.getElementById("mainImg");//mainImgReal
	
	if(el.style.display=="none"){
		
		el.style.height=(parseInt(h)+20);
		el.style.width=w;
		el.style.top=(document.documentElement.scrollTop+20)+"px";
		//alert(((document.body.offsetWidth-w)/2));
		el.style.left=((document.body.offsetWidth-w)/2)+"px";
		elPic.src=src;
		elPic.width=w;
		elPic.height=h;
		el.style.display="";
		elTitle.innerHTML=title;
	}
	else{
		replacePic("mainImgReal",100,src,w,h,title);
	}
}

function replacePic(id,opacity,newImg,newW,newH,newTitle,isSame,isPrime){		//call: ('id',100,'newPicUrl');
	//var isUnd=(newH==0);
	//alert(isUnd);
	if(isPrime){
		//alert('a');
		clearTimeout(inChPics);
	}
	else{
		clearTimeout(inChPics2);
	}

	
	opacity = (opacity == 100)?99.999:opacity;
	var obj=document.getElementById(id);

	//alert(opacity+" "+newImg+" "+obj.src);
	if(isSame && opacity>=99.999){
		//obj.scrollIntoView();
		return;
	}

	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
  
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
  
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
  
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;

	opacity=parseInt(opacity);

	if(!isSame && opacity<0){
		obj.src=newImg;
		//alert(isUnd);
		//alert(newH.typeOf);
		obj.width=newW;
		obj.height=newH;
		if(!isPrime){
			
			document.getElementById("mainImgTitle").innerHTML=newTitle;
			var el=document.getElementById("mainImg");//mainImgReal
			//alert(newH+20);
			el.style.height=(parseInt(newH)+20);
			el.style.width=newW;
			el.style.top=(document.documentElement.scrollTop+20)+"px";
			el.style.left=((document.body.offsetWidth-newW)/2)+"px";
			//alert(newW);
		}


		isSame=1;
		//alert(opacity);
		//alert(newH);
	}

	if(isPrime){
		inChPics=setTimeout("replacePic('"+id+"',"+(opacity+5*(isSame?1:-1))+",'"+newImg+"','"+newW+"','"+newH+"','"+0+"',"+(isSame?1:0)+","+isPrime+")",50);
	}
	else{
		inChPics2=setTimeout("replacePic('"+id+"',"+(opacity+5*(isSame?1:-1))+",'"+newImg+"','"+newW+"','"+newH+"','"+newTitle+"',"+(isSame?1:0)+")",50);
	}
	

	//inChPics=setTimeout("replacePic('"+id+"',"+(opacity+5*(isSame?1:-1))+",'"+newImg+"','"+newW+"','"+newH+"','"+newTitle+"',"+(isSame?1:0)+")",50);
}

//isEdit=1;

function editOver(event){
	if(isOver && isEdit){
		//alert(document.documentElement.scrollTop);
		var el=document.getElementById("editDiv");
		el.style.top=(document.documentElement.scrollTop+parseInt(event.clientY))+"px";;
		//if(document.body.offsetHeight-document.documentElement.scrollTop-event.clientY<80){
			//el.style.top=(event.clientY+document.documentElement.scrollTop-75)+"px";
			//alert("a");
		//}

		el.style.left=(document.documentElement.scrollLeft+event.clientX-75)+"px";;		
		//if(document.body.offsetWidth-event.clientX<40){
			//alert('a');
			//el.style.left=(event.clientX-75)+"px";;
		//}

		//alert("new pos"+(event.clientY-20));
		//alert("dis: "+(document.body.offsetHeight-document.body.scrollTop-event.clientY));

		
		el.style.display="";
	}
}
function editOut(){
	var el=document.getElementById("editDiv");
	el.style.display="none";
	isOver=0;
}
function editClick(elem,event,landingPageId){
	var el=document.getElementById("qualDiv");
	if(el){
		el.parentNode.removeChild(el);
	}
	//alert(document.body.scrollTop);
	event.cancelBubble=true;
	var id=elem.id.replace("Exp_id2","").replace("Exp_id","");
	//alert(id);
	switch(id){
		case "cuponId":
		case "wantsPicsPage":
		case "links":
		case "logoPic":
			var act="";
			switch(id){
				case "cuponId":
					act="window.open('http://www.ezland.co.il/cupon.php?userId="+lPCoded+"','_blank','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=465, height=254');";
				break;
				case "wantsPicsPage":
					act="flipSecondPage();";
				break;
				case "links":
					act="window.open('"+(event.srcElement?event.srcElement.href:event.target.href)+"','_blank');";
					//alert(event.srcElement.href);
				break;
				case "logoPic":
					//alert(elem.tagName);
					if(elem.tagName=="A"){
					
						act="window.open('"+(elem.href)+"','_blank');";
					}
					else{
						if(isEdit){
							goToEdit(id,landingPageId);
						}
					}
				break;
			}
			if(isEdit==0 && act){
				eval(act);
				return;
			}

			if(act){
				

				var div=document.createElement("DIV");
				div.style.top=(event.clientY+20)+"px";;
				if(document.body.offsetHeight-document.documentElement.scrollTop-event.clientY<80){
					div.style.top=(event.clientY+document.documentElement.scrollTop-80)+"px";;
				}
				div.style.left=event.clientX+"px";;
				if(document.body.offsetWidth-event.clientX<80){
					//alert('a');
					div.style.left=(event.clientX-100)+"px";;
				}
		
				div.id="qualDiv";
				div.style.zIndex="300";
				div.style.position="absolute";
				div.style.width="79px";
				div.style.height="59px";
				//div.style.top=event.clientY+"px";
				//div.style.left=parseInt(event.clientX-230/2)+"px";
				var str="";
				str+="<table cellspacing='0' cellpadding='0'><tr><td colspan=2 align=right valign=bottom  >";
				str+="<table cellspacing='0' cellpadding='0'><tr><td width=16 height=16 align=center valign=middle><img src='images/x.png' width=16 height=16 style='cursor:pointer;' onclick=\"document.getElementById('qualDiv').style.display='none';\"></td><td width=62></td></tr></table></td></tr>";
				str+="<tr><td width=39 height=43 style='background:URL(images/open.png) no-repeat white bottom;border:1px #1f9bc3 solid;font-size:10px;cursor:pointer;' valign=top align=center onclick=\""+act+";document.getElementById('qualDiv').style.display='none';\">פתח</td>";
				str+="<td width=39 height=43 style='background:URL(images/edit2.png) no-repeat white bottom;border:1px #1f9bc3 solid;font-size:10px;border-right-width:0px;cursor:pointer;' valign=top align=center onclick=\"goToEdit('"+id+"','"+landingPageId+"');document.getElementById('qualDiv').style.display='none';\">ערוך</td></tr></table>";

				//str+="<a href='' onclick=\""+act+";document.getElementById('qualDiv').style.display='none';return false;\">המשך עם הלינק</a> | ";
				//str+="<a href='' onclick=\"goToEdit('"+id+"');document.getElementById('qualDiv').style.display='none';return false;\">עבור לעריכה</a> | ";
				//str+="<a href='' onclick=\"document.getElementById('qualDiv').style.display='none';return false;\">סגור</a> ";
				div.innerHTML=str;
				document.body.appendChild(div);
			}
			//...
		break;
		default:
			if(isEdit){
				goToEdit(id,landingPageId);
			}
		break;
	}	
}

function goToEdit(id,landingPageId){
	var menu=3;
	//alert(id);
	var ff=id+"Inp";
	if(id=="logoPic"){
		menu=3;
		ff=0;
	}
	if(id=="pics"){
		menu=5;
		ff=0;
	}
	if(id=="links" || id=="busiPhone" || id=="busiName" || id=="busiAddr"){
		menu=4;
		if(id=="links") {
			ff=0;
		}
	}
	if(window.opener){
		
		
		//alert(openerWind);
		//openerWind.focus();
		window.opener.menuCh(menu,0,landingPageId);
		window.opener.focusFieldId=ff;
		openerWind.setTimeout("window.focus();",3000);
		//window.close();
	}
	else{
		wind=window.open("main.php?onloadMenu="+menu+"&landingPageId="+landingPageId+"&focusFieldId="+ff,"realPage");
	}
}

