if (document.getElementById || document.all){
	document.write('<div id="dentastix_icon_container" style="position: absolute; visibility: hidden; left: 0px; top: -1000px;"><div style="padding: 10px; text-align: right; background-color: #ffffff;"><a href="javascript: HideContestResult();">close</a></div><div id="dentastix_icon_result">&nbsp;</div></div>');
	document.write('<div id="dentastix_icon_1" style="position: absolute; visibility: hidden; left: 0px; top: -1000px;"></div>');
	document.write('<div id="dentastix_icon_2" style="position: absolute; visibility: hidden; left: 0px; top: -1000px;"></div>');
}

var mainContainer = document.getElementById('main-container');
var DentastixHolder = document.getElementById('dentastix_icon_0');
var DentastixHolder_0 = document.getElementById('dentastix_icon_1');
var DentastixHolder_1 = document.getElementById('dentastix_icon_2');
var currentHolder;
var currentPosition = new Array();

function SetStartDentastix(){
	var divPosition = SetPositionStartDentastix();
	document.write('<div id="dentastix_start" style="position: absolute; visibility: visible; left: ' + divPosition[0] + 'px; top: ' + divPosition[1] + 'px;"><div id="dentastix_start_container"><img src="images/dentastix_start_600.png" alt="" width="600" height="477" usemap="#map_d" border="0" /><map name="map_d"><area alt="" coords="271,160,302,177" href="javascript: HideStartDentastix();"><area alt="" shape="CIRCLE" coords="290,395,45" href="javascript: HideStartDentastix();"><area alt="" coords="258,448,328,469" href="' + thisURL + 'docs/Regulament_pedigree_dentastix.doc"></map></div></div>');
}

function HideStartDentastix(){
	GetStartObjectContainer().style.visibility = "hidden";
	GetStartObjectContainer().style.left = 0;
	GetStartObjectContainer().style.top = -1000;
}

function GetStartObjectContainer(){
	if (document.getElementById){
		return document.getElementById("dentastix_start");
	}else if (document.all){
		return document.all.dentastix_start_container;
	}
}

function resizeWindow(){
	if( DentastixHolder_0 && (DentastixHolder_0.style.visibility == 'visible') ){
		currentPosition = DentastixHolder0;
		var mainContainerPosition  = FindPos(mainContainer);
		DentastixHolder_0.style.left = mainContainerPosition[0] + currentPosition[0];
		DentastixHolder_0.style.top = mainContainerPosition[1] + currentPosition[1];
	}
	
	if( DentastixHolder_1 && (DentastixHolder_1.style.visibility == 'visible') ){
		currentPosition = DentastixHolder1;
		var mainContainerPosition  = FindPos(mainContainer);
		DentastixHolder_1.style.left = mainContainerPosition[0] + currentPosition[0];
		DentastixHolder_1.style.top = mainContainerPosition[1] + currentPosition[1];
	}
}

function SetMoreDentastix( holder, oParam, oTop, oLeft ){
	if( holder && oParam ){
		holder.innerHTML = '<div style="text-align: center;"><input type="image" src="images/dentastix_80.gif" onclick="javascript: ShowContestResult(' + holder.id + ', ' + oParam + ');" /></div>';
		var mainContainerPosition = FindPos(mainContainer);
		holder.style.left = mainContainerPosition[0] + oLeft;
		holder.style.top = mainContainerPosition[1] + oTop;
	}
}

function SetPositionStartDentastix() {
	myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
    	//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    	//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    	//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	myWidth = parseInt((myWidth - 830)/2) + 172;
	myHeight = 100;
	return [myWidth, myHeight];
}

function GetObjectContainer(){
	if (document.getElementById){
		return document.getElementById("dentastix_icon_container");
	}else if (document.all){
		return document.all.dentastix_icon_result;
	}
}

function GetObjectResult(){
	if (document.getElementById){
		return document.getElementById("dentastix_icon_result");
	}else if (document.all){
		return document.all.dentastix_icon_result;
	}
}

function FindPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

function ShowContestResult( holder, op ){
	currentHolder = holder;
	var xLeft = 0;
	var xTop = 0;
	var contestResult = '';
	var url = thisURL + 'dentastix.php?id=' + op + '&sid=' + Math.random();
	
	xmlHttp = GetXmlHttpObject();
	if(xmlHttp == null){
		alert ("Please update your browser!");
		return;
	}
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4){
			var pageStatus = xmlHttp.responseText;
			var stixPosition = FindPos(currentHolder);
			if( pageStatus == 'N' ){
				contestResult = ShowTryAgain();
				xLeft = stixPosition[0];
				xTop = (stixPosition[1]-160);
			}else
			if( pageStatus == 'Y' ){
				contestResult = ShowInsertDatas( op );
				xLeft = (stixPosition[0]+30);
				xTop = (stixPosition[1]-190);
			}
			if( contestResult != '' ){
				GetObjectContainer().style.visibility = "visible";
				GetObjectContainer().style.left = xLeft;
				GetObjectContainer().style.top = xTop;
				GetObjectResult().innerHTML = contestResult;
				currentHolder.style.visibility = 'hidden';
			}
		}
	}
}

function SetDentastix( oParam ){
	if( DentastixHolder && oParam ){
		DentastixHolder.innerHTML = '<div style="text-align: center;"><input type="image" src="images/dentastix_80.gif" onclick="javascript: ShowContestResult(' + DentastixHolder.id + ', ' + oParam + ');" /></div>';
	}
}

function HideContestResult(){
	GetObjectContainer().style.visibility = "hidden";
	GetObjectContainer().style.left = 0;
	GetObjectContainer().style.top = -1000;
	GetObjectResult().innerHTML = '&nbsp;';
	currentHolder.style.visibility = 'visible';
}

function ShowTryAgain(){
	var container = '<img src="images/dentastix-not-winner.gif" alt="" width="200" height="231" />';
	return container;
}

function ShowCongratulation(){
	var container = '<img src="images/dentastix-congratulation.gif" alt="" width="200" height="232" />';
	return container;
}

function ShowInsertDatas( oParam ){
	var container = '<div style="background-image: url(images/dentastix-winner.jpg); background-repeat: no-repeat; width: 500px; height: 516px;"><form name="dentastix_form_name"><div id="dentastix_form"><input type="hidden" name="id" value="' + oParam + '" /><table border="0" cellpadding="0" cellspacing="0"><tr><td class="h19"><input type="text" name="FirstName" class="FirstName" /></td></tr><tr><td class="h3"></td></tr><tr><td class="h19"><input type="text" name="LastName" class="LastName" /></td></tr><tr><td class="h4"></td></tr><tr><td class="h19"><input type="text" name="Address" class="Address" /></td></tr><tr><td class="h3"></td></tr><tr><td class="h19"><input type="text" name="Phone" class="Phone" /></td></tr><tr><td class="h3"></td></tr><tr><td class="h19"><input type="text" name="Email" class="Email" /></td></tr><tr><td class="h5"></td></tr><tr><td><input type="button" class="send" value="" onclick="javascript: sendDatas();"></td></tr></table></form></div>';
	return container;
}

function sendDatas(){
	var xLeft = 0;
	var xTop = 0;
	var contestResult = '';
	var errorMessage = '';
	
	var oForm = document.forms['dentastix_form_name'];
	var sURL = thisURL + 'dentastix.php';
	var sPostVars = '';
	for (i = 0; i < oForm.elements.length; ++i){
		if (oForm.elements[i].type == "text" || oForm.elements[i].type == "hidden"){
			if( oForm.elements[i].value == '' ){
				errorMessage = 'Toate campurile sunt obligatorii!';
			}else{
				sPostVars += oForm.elements[i].name + "=" + oForm.elements[i].value + "&";
			}
		}
	}
	
	if( (sPostVars != '') && (errorMessage == '') ){
		sPostVars += 'getDatas=' + Math.random();
		
		xmlHttp = GetXmlHttpObject();
		if(xmlHttp == null){
			alert ("Please update your browser!");
			return;
		}
		xmlHttp.open("POST", sURL, true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1");
		xmlHttp.setRequestHeader("Content-length", sPostVars.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.setRequestHeader("Accept-Charset", "ISO-8859-1");
		xmlHttp.send(sPostVars);
		xmlHttp.onreadystatechange = function(){
			if(xmlHttp.readyState == 4){
				var pageStatus = xmlHttp.responseText;
				var stixPosition = FindPos(currentHolder);
				if( pageStatus == 'D' ){
					contestResult = ShowCongratulation();
					xLeft = stixPosition[0];
					xTop = (stixPosition[1]-160);
				}else
				if( pageStatus == 'T' ){
					alert('Deja ati participat la acest concurs.');
					contestResult = '';
				}else
				if( pageStatus == 'E' ){
					alert('Introduceti o adresa de e-mail valida.');
					contestResult = '';
				}else
				if( pageStatus = 'error' ){
					HideContestResult();
					contestResult = '';
				}
				if( contestResult != '' ){
					GetObjectContainer().style.visibility = "visible";
					GetObjectContainer().style.left = xLeft;
					GetObjectContainer().style.top = xTop;
					GetObjectResult().innerHTML = contestResult;
					currentHolder.style.visibility = 'hidden';
				}
			}
		}
	}else{
		alert(errorMessage);
	}
}

function GetXmlHttpObject(){
	var xmlHttp = null;
	try{// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}catch (e){// Internet Explorer 6+
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      	}catch (e){
			try{// Internet Explorer 5+
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e){
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return xmlHttp;
}
