﻿// File JScript

//MakeLayout("maincontainer",1000,1000,1000);

//Delete
function MakeLayout(id,minr,maxw,maxr){
	if(document.getElementById){
	
		SetWidth(id,minr,maxw,maxr);
		window.onresize=function(){
		    SetWidth(id,minr,maxw,maxr);
		}
    }
}

//Delete
function SetWidth(id,a,b,c){
	var w=getBrowserWidth();
	if(w==0) return;
	var el=document.getElementById(id);
	el.style.margin="0 auto";
	var d=el.style;
	
	if(w<=a) larghezza=a;
	else if(w>=c) larghezza=b;
	else{
			var m=(b-a)/(c-a);
			larghezza=parseInt(m*w+a*(1-m));
			}
	d.width = larghezza+"px";
}

function getBrowserWidth(){
	if (window.innerWidth) return window.innerWidth;
	else if (document.documentElement && document.documentElement.clientWidth!=0)
			return document.documentElement.clientWidth;
	else if (document.body) return document.body.clientWidth;
	return 0;
}

var cX = 0; var cY = 0;
var pvtd = ''; var pvtp = '';

function UpdateCursorPosition(e) { cX = e.pageX; cY = e.pageY; }

//Delete
function getOffset(el) {
    var _x = 0;
    var _y = 0;
    while (el && !isNaN(el.offsetLeft) && !isNaN(el.offsetTop)) {
        _x += el.offsetLeft - el.scrollLeft;
        _y += el.offsetTop - el.scrollTop;
        el = el.parentNode;
        
    }
    return { top: _y, left: _x };
}

//Delete
function ShowWidth() {
    var el = window.event.srcElement;
    alert('Width: ' + getBrowserWidth())
}
//Delete
function ShowPos() {
    var el = window.event.srcElement;
    alert('ClientX: ' + window.event.clientX + ' ClientY: ' + window.event.clientY + ' Top: ' + getOffset(el).top + ' Left: ' + getOffset(el).left + ' - ElTop: ' + getElementPosition(window.event).top + ' ElLeft: ' + getElementPosition(window.event).left + ' - Scroll: ' + GetScrollTop())
    var _nodeName = '';
    while (el && !isNaN(el.offsetLeft) && !isNaN(el.offsetTop)) {
        _nodeName = _nodeName + ' |' + el.nodeName + ': ' + el.offsetTop;
        el = el.parentNode;
    }
    alert(_nodeName);
}

//Delete
function ShowScroll() {
    alert('Scroll: ' + (document.documentElement.scrollTop + document.body.scrollTop));
}

//Delete
function GetScrollTop() {
    return (document.documentElement.scrollTop + document.body.scrollTop);
}
//Delete
function GetScrollLeft() {
    return (document.documentElement.scrollLeft + document.body.scrollLeft);
}

// Delete
function ShowDiv() {
    var el = window.event.srcElement;
    var _D = document.getElementById('Div1');
    _D.style.top = getElementPosition(window.event).top;
    _D.style.left = getElementPosition(window.event).left + 150;
    _D.style.display = 'block';
}

function getElementPosition(ev) {
    var _x = ev.clientX;
    var _y = ev.clientY;
    var _width = getBrowserWidth();
    var _leftBorder = (_width - 970) / 2;
    var _topBorder = 151;
    var _leftOffset = 0; // relative to the control
    var _topOffset = 0; // relative to the control
    var _scrollTop = (document.documentElement.scrollTop + document.body.scrollTop);
    var _scrollLeft = (document.documentElement.scrollLeft + document.body.scrollLeft);
    var _top = (_y - _topBorder + _scrollTop + _topOffset);
    var _left = (_x - _leftBorder + _scrollLeft + _leftOffset);
    return { top: _top, left: _left };
}

//Delete
function ShowDiv2() {
    var el = window.event.srcElement;
    var _D = document.getElementById('Div1');
    _D.style.top = getElementPosition(el).top;
    _D.style.left = getElementPosition(el).left + 150;
    _D.style.display = 'block';
}

//Delete
function getElementPosition2(el) {
    var _x = 0;
    var _y = 0;
    while (el && !isNaN(el.offsetLeft) && !isNaN(el.offsetTop)) {
        _x += el.offsetLeft - el.scrollLeft;
        _y += el.offsetTop - el.scrollTop;
        el = el.parentNode;
    }
    var _width = getBrowserWidth();
    var _leftBorder = (_width - 970) / 2;
    var _topBorder = 151;
    var _leftOffset = 0; // relative to the control
    var _topOffset = 0; // relative to the control
    var _scrollTop = (document.documentElement.scrollTop + document.body.scrollTop);
    var _scrollLeft = (document.documentElement.scrollLeft + document.body.scrollLeft);
    var _top = (_y - _topBorder + _scrollTop + _topOffset);
    var _left = (_x - _leftBorder + _scrollLeft + _leftOffset);
    return { top: _top, left: _left };
}

function UpdateCursorPositionDocAll(e) {
    var _ManagedEvent;
    
    if (window.event)
        _ManagedEvent = window.event;
    else
        _ManagedEvent = e;

    cX = getElementPosition(_ManagedEvent).left + 30;
    cY = getElementPosition(_ManagedEvent).top - 70;

}

function UpdateCursorPositionNew(e) {
    cX = getElementPosition(window.event.srcElement).left;
    cY = getElementPosition(window.event.srcElement).top;
}
    
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPositionDocAll; }

function AssignPosition(d) {
d.style.left = (cX) + "px";
d.style.top = (cY) + "px";
}

function HideContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "none";
}

function ShowContent(d,p) {
pvtd = d;
pvtp = p;
var iTimeoutId =setTimeout("ShowContent1()", 1);
}

function ShowContent1() {
document.getElementById(pvtp).click();
if(pvtd.length < 1) { return; }
if(pvtp.length < 1) { return; }
var dd = document.getElementById(pvtd);
AssignPosition(dd);
dd.style.display = "block";
return false;
}

function ShowContentUpdate(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd);
}


//<![CDATA[
var locX=0;
var locY=150;
var imgW=0;
var maxX=0;
var getC=0;
var docW=document.body.clientWidth;
var hldX=0;
var incX=1;
var cStat=1;

imgPoll=new Image();
imgPoll.onload=chkImg;

function woAfterLoad(){
 var tmpDiv=document.createElement('DIV');
 tmpDiv.setAttribute('name', 'woInvite');
 tmpDiv.setAttribute('id', 'woInvite');
 tmpDiv.setAttribute('align', 'right');
 tmpDiv.style.position='absolute';
 tmpDiv.style.top=150;
 tmpDiv.style.left=0;
 tmpDiv.style.zIndex=999;
 document.body.appendChild(tmpDiv);
 setTimeout('getImg()',1000); // 1000
}

function woMove(){
 if(hldX==0){
  newX=locX+incX;
  if(incX>0){
   if(newX<maxX){
    locX=newX;woDIVs.left=locX+'px';
    setTimeout('woMove()',12);
   } else {
    incX=-1;
    setTimeout('woMove()',1000);
   }
  } else {
   if(locX>0){
    locX=newX;woDIVs.left=locX+'px';
    setTimeout('woMove()',6);
   } else {
    setTimeout('stopInvite()',4000);
   }
 }
 }
}

function getImg(){
 var rTimer=5000;
 var pUrl="http://www.easydomus.com:8090/poll.gif?d=www.easydomus.com&ip="+varWOIP+"&u="+varWOSESSION+"&stamp="+(new Date()).getTime();
 imgPoll.src=pUrl;
 getC++;
 if(getC>10)rTimer=10000;
 if(rTimer>0)setTimeout("getImg()",rTimer);
}

function chkImg(){
 if(imgPoll!=null){
  nStat=imgPoll.width;
  if(nStat==1 && cStat==2)nStat=2;
  if(nStat!=cStat){
   cStat=nStat;
   if(cStat==3)startChat();
   if(cStat==2)startInvite();
   if(cStat==1)stopInvite();
  }
 }
}

function getIImgw(){
 imgW=woIMG.width;maxX=docW-imgW;
}

function startInvite(){
  showModalPopupViaClient();
}

function startInviteORIG(){
 var ofsY;
 if(document.documentElement && document.documentElement.scrollTop){
  ofsY=document.documentElement.scrollTop;
 } else {
  ofsY=document.body.scrollTop;
 }
 hldX=0;incX=1;locX=0;locY=150;
 woDIVs=document.getElementById('woInvite').style;
 woDIVh=document.getElementById('woInvite');
 woDIVh.innerHTML='<a href="javascript:void(0);" onclick="return startChat(event);" onMouseOver="anPause()" onMouseOut="anResume()"><img border="0" src="http://www.easydomus.com:8090/invite.gif?d=www.easydomus.com&ip='+varWOIP+'&u='+varWOSESSION+'&stamp='+(new Date()).getTime()+'" name="woIImg"</a>';
 woDIVs.top=(locY+ofsY)+'px';woDIVs.left=locX+'px';
 setTimeout('woMove()',3000);
 woIMG=document.images.woIImg;
 woIMG.onload=getIImgw;
}

function stopInvite(){
 cStat=1;woDIVh.innerHTML="";
 setTimeout("getImg()",5000);
}

function startChat(event){
 clsX=locX+imgW-12;
 clsY=locY+12;
 if(event.clientX<clsX || event.clientY>clsY){
  this.chatWindow=window.open("http://chat.easydomus.com/chatstart.htm?domain=www.easydomus.com","Chat","width=484,height=361");
  this.chatWindow.focus();this.chatWindow.opener=window;
 }
 stopInvite();
}

function DoNothing(){
}

function ChatInvitePanelClickCustomUrl(CustomUrl) {
    this.chatWindow = window.open(CustomUrl, "Chat", "width=484,height=361");
    this.chatWindow.focus();
    this.chatWindow.opener = window;
    cStat = 1;
    setTimeout("getImg()", 5000);
}

function ChatInvitePanelClick() {
  this.chatWindow=window.open("http://chat.easydomus.com/chatstart.htm?autostart=1&domain=www.easydomus.com","Chat","width=484,height=361");
  this.chatWindow.focus();
  this.chatWindow.opener=window;
  cStat=1;
  setTimeout("getImg()",5000);
}

function showModalPopupViaClient() {
    var cipi=document.getElementById('ChatInvitePanelIn');
    cipi.innerHTML='<a href="javascript:void(0);" onclick="return ChatInvitePanelClick();" style="cursor:default"><img src="http://www.easydomus.com:8090/invite.gif?d=www.easydomus.com&ip='+varWOIP+'&u='+varWOSESSION+'&stamp='+(new Date()).getTime()+'" style="border:none 0px transparent; height:1000px; width:100%;" alt="" /></a>'
    
    var modalPopupBehavior = $find('programmaticModalPopupBehavior');
    modalPopupBehavior.show();
}

function hideModalPopupViaClient() {
    var modalPopupBehavior = $find('programmaticModalPopupBehavior');
    modalPopupBehavior.hide();
}
        
function anPause(){
 hldX=1;
}

function anResume(){
 hldX=0;
 setTimeout('woMove()',1000);
}
var woOldOnload=window.onload;

if(typeof woOldOnload=='function'){
 if (! (String(woOldOnload).indexOf('woAfterLoad') > 0))
 {
   var woRunOnload = woOldOnload;
   window.onload=function(){woRunOnload();woAfterLoad();};
 }
} else {
 window.onload=woAfterLoad;
}

//]]>
