/*--- Post Forms ---*/
function PostForm(Form){
	var Query="";
	var First=true;
	
	for(i=0;i<Form.elements.length;i++){
		if(!First){
			Query=Query+"&";
		}else{
			First=false;
		}

		var Value="";
		Query=Query+Form.elements[i].name+"=";		
		switch(Form.elements[i].type){
			case "radio":
				var Radio=document.getElementsByName(Form.elements[i].name);
				for(j=0;j<Radio.length;j++){
				  	if (Radio[j].checked){
			    		Value=encodeURI(Radio[j].value);
					}
				}
			break;
			case "checkbox":
				Value=0;
				if(Form.elements[i].checked==true){
					Value=1;
				}
			break;
			default:
				Value=encodeURI(Form.elements[i].value);
			break;
		}
		Query=Query+Value;			
	}
	
	PostQuery(Query);
	
	return false;
}

/*--- Post Queries ---*/
var QueryStack=new Array();
var RunningStack=false;

function PostQuery(Query){
	QueryStack[QueryStack.length]=Query;
	
	if(!RunningStack){
		SendQuery();
	}
}

function SendQuery(){
	var XmlHttpQuery=false;
	var self=document;
	
	if(QueryStack.length>0){
		RunningStack=true;
		Query=QueryStack.shift();
	
		if(window.XMLHttpRequest){
			self.XmlHttpQuery=new XMLHttpRequest();
		}else{
			self.XmlHttpQuery=new ActiveXObject("Microsoft.XMLHTTP");		
		}
		self.XmlHttpQuery.open('POST', 'http://www.easytahiti.com/CallBack.html', true);
		self.XmlHttpQuery.onreadystatechange=function(){ 
			if(self.XmlHttpQuery.readyState==4){ 
				if(self.XmlHttpQuery.responseText!="NULL"){
					var CallBack=new Function("",self.XmlHttpQuery.responseText);
					CallBack();
		   		}
		   		SendQuery();
			}	 
		}
		self.XmlHttpQuery.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
		self.XmlHttpQuery.send(Query); 
	}else{
		RunningStack=false;
	}
}

/*--- Popup ---*/
function Popup_New(Name){
	var page=document.getElementById("easyPage");
	var layer=document.getElementById("easyTransparent");
	
	layer.style.height=(page.offsetHeight+15)+"px";
	layer.style.top="-15px";	
	layer.style.left="-15px";		
	layer.style.right="-15px";			
	layer.style.visibility="visible";
	
	var body=document.getElementById('easyBody');
	var popup=document.createElement('div');
	
	var Parameters=Name.split("-");
	
	popup.id="easyPopup_"+Parameters[0];
	popup.className='Popup';
	body.appendChild(popup);
	
	var Query="Type=Popup&CallBack=Init&Name="+Parameters[0];
	
	if(Parameters.length>1){
		var AdditionalParameters="&Parameters="+Parameters[1];
		
		for(i=2;i<Parameters.length;i++){
			AdditionalParameters=AdditionalParameters+"::"+Parameters[i];
		}
		Query=Query+AdditionalParameters;
	}
	
	PostQuery(Query);
}

function Popup_Resize(PopupId){
	var Content=document.getElementById("easyPopup_Content_"+PopupId);

	var xOffset=-10;
	var yOffset=40;
	
	NewWidth=parseInt(Content.offsetWidth)+xOffset;
	NewHeight=parseInt(Content.offsetHeight)+yOffset;

	var Container=document.getElementById("easyPopup_"+PopupId);
	Container.style.width=NewWidth+'px';
	Container.style.height=NewHeight+'px';	
	
	Content.style.width=NewWidth+'px';
	Content.style.height=NewHeight+'px';	
	
}

function Popup_Close(DivId){
	var body=document.getElementById('easyBody');
	if(document.getElementById(DivId)){
		var div=document.getElementById(DivId);
		body.removeChild(div);
	}

	var layer=document.getElementById("easyTransparent");
	layer.style.visibility="hidden";
}

function Popup_DnD(DivId,DivIdParent){
	var div=document.getElementById(DivId);	
	var divparent=document.getElementById(DivIdParent);	
	Popup_MakeDraggable(div,divparent);
}

function Popup_MakeDraggable(div,div_parent){
  var xDelta=0;
  var yDelta=0;
  var xStart=0;
  var yStart=0;

  function Popup_Drop(){
	document.onmouseup = null;
    document.onmousemove = null;
  }

  function Popup_Drag(e){
    e=e || window.event;
    xDelta=xStart-parseInt(e.clientX);
    yDelta=yStart-parseInt(e.clientY);
    xStart=parseInt(e.clientX);
    yStart=parseInt(e.clientY);
    div_parent.style.top=(parseInt(div_parent.offsetTop)-yDelta)+'px';
    div_parent.style.left=(parseInt(div_parent.offsetLeft)-xDelta)+'px';
  }

  function Popup_StartDrag(e){
    e=e || window.event;
    xStart=parseInt(e.clientX);
    yStart=parseInt(e.clientY);
    document.onmouseup=Popup_Drop;
    document.onmousemove=Popup_Drag;
    return false;
  }

  div.onmousedown=Popup_StartDrag;
}

/*
Copyright (c) Copyright (c) 2007, Carl S. Yestrau All rights reserved.
Code licensed under the BSD License: http://www.featureblend.com/license.txt
Version: 1.0.3
*/
var FlashDetect = new function(){
	var self = this;
	self.installed = false;
	self.raw = "";
	self.major = -1;
	self.minor = -1;
	self.revision = -1;
	self.revisionStr = "";
	var activeXDetectRules = [
		{
			"name":"ShockwaveFlash.ShockwaveFlash.7",
			"version":function(obj){
				return getActiveXVersion(obj);
			}
		},
		{
			"name":"ShockwaveFlash.ShockwaveFlash.6",
			"version":function(obj){
				var version = "6,0,21";
				try{
					obj.AllowScriptAccess = "always";
					version = getActiveXVersion(obj);
				}catch(err){}
				return version;
			}
		},
		{
			"name":"ShockwaveFlash.ShockwaveFlash",
			"version":function(obj){
				return getActiveXVersion(obj);
			}
		}
	];
	var getActiveXVersion = function(activeXObj){
		var version = -1;
		try{
			version = activeXObj.GetVariable("$version");
		}catch(err){}
		return version;
	};
	var getActiveXObject = function(name){
		var obj = -1;
		try{
			obj = new ActiveXObject(name);
		}catch(err){}
		return obj;
	};
	var parseActiveXVersion = function(str){
		var versionArray = str.split(",");//replace with regex
		return {
			"raw":str,
			"major":parseInt(versionArray[0].split(" ")[1], 10),
			"minor":parseInt(versionArray[1], 10),
			"revision":parseInt(versionArray[2], 10),
			"revisionStr":versionArray[2]
		};
	};
	var parseStandardVersion = function(str){
		var descParts = str.split(/ +/);
		var majorMinor = descParts[2].split(/\./);
		var revisionStr = descParts[3];
		return {
			"raw":str,
			"major":parseInt(majorMinor[0], 10),
			"minor":parseInt(majorMinor[1], 10), 
			"revisionStr":revisionStr,
			"revision":parseRevisionStrToInt(revisionStr)
		};
	};
	var parseRevisionStrToInt = function(str){
		return parseInt(str.replace(/[a-zA-Z]/g, ""), 10) || self.revision;
	};
	self.majorAtLeast = function(version){
		return self.major >= version;
	};
	self.FlashDetect = function(){
		if(navigator.plugins && navigator.plugins.length>0){
			var type = 'application/x-shockwave-flash';
			var mimeTypes = navigator.mimeTypes;
			if(mimeTypes && mimeTypes[type] && mimeTypes[type].enabledPlugin && mimeTypes[type].enabledPlugin.description){
				var version = mimeTypes[type].enabledPlugin.description;
				var versionObj = parseStandardVersion(version);
				self.raw = versionObj.raw;
				self.major = versionObj.major;
				self.minor = versionObj.minor; 
				self.revisionStr = versionObj.revisionStr;
				self.revision = versionObj.revision;
				self.installed = true;
			}
		}else if(navigator.appVersion.indexOf("Mac")==-1 && window.execScript){
			var version = -1;
			for(var i=0; i<activeXDetectRules.length && version==-1; i++){
				var obj = getActiveXObject(activeXDetectRules[i].name);
				if(typeof obj == "object"){
					self.installed = true;
					version = activeXDetectRules[i].version(obj);
					if(version!=-1){
						var versionObj = parseActiveXVersion(version);
						self.raw = versionObj.raw;
						self.major = versionObj.major;
						self.minor = versionObj.minor; 
						self.revision = versionObj.revision;
						self.revisionStr = versionObj.revisionStr;
					}
				}
			}
		}
	}();
};

function Connexion(Id){
	var src="http://www.easytahiti.com/img/Logo_Top.jpg";

	var body=document.getElementById('easyBody');
	var div=document.createElement('div');
	div.style.visibility="hidden";
	
	var Timer=new Date();
	var Timer=Timer.getTime();
	
	div.innerHTML="<img src='"+src+"?easy="+Id+"' onload='ConnexionSend("+Timer+");' />";
	
	body.appendChild(div);
}

function ConnexionSend(StartTime){
	var size=11153; 

	var Timer=new Date();
	var Timer=Timer.getTime();

	var bandwidth=size/(Timer-StartTime);

	var Java="";
	var Flash=FlashDetect.raw;
	PostQuery("Type=UserAgent&CallBack=SetUpdate&ResX="+screen.width+"&ResY="+screen.height+"&Colors="+screen.colorDepth+"&Flash="+Flash+"&Java="+Java+"&Bandwidth="+bandwidth);
}
