var fontsize = 13;
var savedFontSize = 13;
var tickerIndex = 0;

$(document).ready(function () {
		$("#icon-search").bind("mouseover", function () {$("#icon-search").attr("src",$("#icon-search").attr("src").replace("off", "on"))});
		$("#icon-search").bind("mouseout", function () {$("#icon-search").attr("src",$("#icon-search").attr("src").replace("on", "off"))});
		$("#txtSearch").bind("focus", function () {if ($(this).val() == "SEARCH") $(this).val("")});
		$("#txtSearch").bind("blur", function () {if (!$(this).val()) $(this).val("SEARCH")});
		$("#txtSearch").keypress(function (event) {
				if ( event.which == 13 ) {
					 doSearch();
				   }
		});
		$("#languages").bind("change", switchLanguage);
		$("#icon-lang").bind("click", function () {$("#divLanguages").css("display", "block")});

		$("#SalesAreaID2").keypress(function (event) {
				if ( event.which == 13 ) {
					 loadContact2($('#SalesAreaID2').val());
				   }
		});
//		setFontSize(); 
	}
);
function setFontSize() {
	if (savedFontSize)
	{
		savedFontSize = Get_Cookie("FontSize");
		if (parseInt(savedFontSize)) fontsize = savedFontSize;
		el = document.getElementsByTagName("body");
		if (el)
		{
			try
			{
				el[0].style.fontSize = fontsize + "px";	
			}
			catch (ex)
			{
				;
			}
			
		}
	}
}

function changeFontSize(direction) {
	el = document.getElementsByTagName("body");
	if (direction == 0)
	{
		el[0].style.fontSize = "13px";
		fontsize = 13;
	} else {
		if (fontsize >= 19 && direction > 0) return true;
		if (fontsize <= 11 && direction < 0) return true;
		fontsize = parseInt(fontsize) + parseInt(direction); 
		el[0].style.fontSize = fontsize + "px";
	}
	direction = 1 - direction;
	Set_Cookie("FontSize", fontsize, 1);
}







function in_array(needle, haystack) {
	for (idx in haystack)
	{
		if (needle == haystack[idx])
		{
			return true;
		}
	}
	return false;
}


function alert2(msg, title) {
	txt = "<div class='alert'>";
	if (title)
	{
		txt += "<div class='title'>" + title + "</div>";
	}
	txt += "<div class='message'>" + msg + "</div>";
	message2(txt);
}

function alert3(msg) {
	showOverlay();
	box("<div>"+'<div class="login-close" style="text-align: right"> <a href="#" onclick="return false"><img style="position: relative; top: 24px; left: -3px;" src="images/icon_delte_up.gif" alt="close" name="closepop"  border="0" id="closepop" onmouseover="MM_swapImage(\'closepop\',\'\',\'images/icon_delte_over.gif\',1)" onmouseout="MM_swapImgRestore()" onclick="closeWait()" /></a></div>'+ "<div class='msgalert' style='-moz-border-radius: 0.6em;	-webkit-border-radius: 0.6em;	border-radius: 0.6em; border: 2px solid #f10000; padding: 0px;'>" + msg+"</div></div>");
}

function checkKey(e) {
	try
	{
		if (e.keyCode == 13) doSearch();	
	}
	catch (ex)
	{
	}
	
}

function doSearch() {
//	window.location="index.php?o=search-results&query=" + $("#Search").val();
	window.location='index.php?s=support&o=results&q='+$('#txtSearch').val()
}

var boxes = [1,1,1,1,1,1,1,1,1,1];
function toggleBox(obj) {
	try
	{
		boxid = obj.attr("id").substring(3);
		if (boxid == 1) return true;
		if (boxes[boxid])
		{
			obj.hide('slow', 'swing');
			if (boxid != 2) obj.parent().find(".boxhead").css("background-image", "url(images/triangle-red-right.png)");
		} else {
			obj.show('fast', 'swing');
			if (boxid != 2) obj.parent().find(".boxhead").css("background-image", "url(images/triangle-red-up.png)");
		}
		boxes[boxid] = 1 - boxes[boxid];
		Set_Cookie("Boxes", boxes.concat(), 30);		
	}
	catch (ex)
	{
	}

}

var sliderLeft = 0;
var sliderCount = 4;
var slideInterval;
var slideTimer = 150;
var slideDirection = 0;
var slideStep = 0;
var slideSteps = 0;
var stepDuration = 10;
var slideLength = 0; //pixels

function slideLeft() {
	if (sliderLeft>=-100) return false;
	slideDirection = 1;
	slideSteps = slideTimer/stepDuration;
	slideInterval = setInterval(slide, stepDuration);
	$("#pageno").html("1/2");
}

function slideRight() {
	slideDirection = -1;
	el = document.getElementById("slider");
	slideLength = el.offsetWidth * -1 + 990;
	if (sliderLeft <= slideLength) return false;
	slideSteps = slideTimer/stepDuration;
	slideInterval = setInterval(slide, stepDuration);
	$("#pageno").html("2/2");	
}

function slide() {
	slideStep ++;
	if (slideStep > slideSteps)
	{
		slideStep = 0;
		clearInterval(slideInterval);
		return true;
	}
	increment = Math.abs(855) / slideSteps;
	el=document.getElementById('slider'); 
	sliderLeft = sliderLeft + increment * slideDirection;
	el.style.marginLeft= sliderLeft + 'px';
	
}


function enableTab(id, pages) {
	for (i=1; i<=pages ;i++ )
	{
		if (i==id) continue;
		$("#page" + i).css("display", "none");
		$("#tab" + i).removeClass("active")
	}
	$("#page" + id).css("display", "block");
	$("#tab" + id).addClass("active")
	return true;
}

function highlight(obj) {
	$(obj).addClass("active");
}

function unhighlight(obj) {
	$(obj).removeClass("active");
}

var currentMode;
function searchCondos(mode) {
	if (!mode) mode = currentMode;
	if (!mode) mode = getQueryVariable("mode");
	if (!mode) mode = "city";
	currentMode = mode;
	criteria = "";
	criteria = $("#price").val() + "|" + $("#sqft").val();
	txt = [];
	el = document.getElementsByName("Bedrooms");
	for (i=0;i<el.length ;i++ )
	{
		if (el[i].checked)
		{
			txt[txt.length] = el[i].value;
		}
	}
	criteria += "|" + txt.join(";");

	el = document.getElementsByName("Bathrooms");
	txt = [];
	for (i=0;i<el.length ;i++ )
	{
		if (el[i].checked)
		{
			txt[txt.length] = el[i].value;
		}
	}
	criteria += "|" + txt.join(";");

	el = document.getElementsByName("Occupancy");
	txt = [];
	for (i=0;i<el.length ;i++ )
	{
		if (el[i].checked)
		{
			txt[txt.length] = el[i].value;
		}
	}
	criteria += "|" + txt.join(";");

	el = document.getElementsByName("City");
	txt = [];
	for (i=0;i<el.length ;i++ )
	{
		if (el[i].checked)
		{
			txt[txt.length] = el[i].value;
		}
	}
	criteria += "|" + txt.join(";");
//	alert(mode);
	url = "index.php?s=main&o=get-results&criteria=" + criteria + "&mode=" + mode;
//	wait();
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_searchCondos;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
	txt = "";
}

function _searchCondos() {
	if(checkReadyState(xmlhttp)) {

		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		ret=response.getElementsByTagName("content");
		$("#results").html(getXMLNode(ret));
	}
}



function filterSpotlight(obj, idx) {
	slideLeft();
	$(".spotlight .spotlight-nav-button-active").removeClass("spotlight-nav-button-active").addClass("spotlight-nav-button");
	setClass(obj, "spotlight-nav-button-active");
	var c = 0;
	$(".slide-cell").each(function () { x = $(this).attr("id"); y = x.split("-");  if (parseInt(y[2]) == parseInt(idx)) { $(this).css("display", "block"); c++}else $(this).css("display", "none"); });
	if (c > 5) { $("#pageno").html("1/2"); $("#pageno").css("display","block");} else {$("#pageno").css("display","none");}

	
	obj2 = $(obj).parent().parent().find('.spotlight-content');
	if (!boxes[obj2.attr("id").substr(3)]) toggleBox(obj2);
	return false;
}

function filterInventory(obj, idx) {
	$("#movetoday .spotlight-nav-button-active").removeClass("spotlight-nav-button-active").addClass("spotlight-nav-button");
	setClass(obj, "spotlight-nav-button-active");
	$("#movetoday .spotlight-content").each(function () {x = $(this).attr("id"); y = x.split("-");  if (parseInt(y[1]) == parseInt(idx)) $(this).css("display", "block"); else $(this).css("display", "none"); });
	return false;
}

function filterFinances(obj, idx) {
	$("#finances .spotlight-nav-button-active").removeClass("spotlight-nav-button-active").addClass("spotlight-nav-button");
	setClass(obj, "spotlight-nav-button-active");
	$("#finances .spotlight-content").each(function () {x = $(this).attr("id"); y = x.split("-");  if (parseInt(y[1]) == parseInt(idx)) $(this).css("display", "block"); else $(this).css("display", "none"); });
	return false;
}

function saveStory() {
	url = "index.php?s=main&o=save-testimonial&Name=" + $("#Name").val() + "&Email=" + $("#Email").val() + "&Phone=" + $("#Phone").val() + "&Story=" + $("#Story").val();
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_saveStory;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
	txt = "";
}

function _saveStory() {
	if(checkReadyState(xmlhttp)) {

		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		ret=response.getElementsByTagName("content");
		alert2(getXMLNode(ret));
	}
}


function maintenancePopup(popupid) {
	txt = "<div class='alert'>" + $("#" + popupid).html() + "</div>";
	alert3(txt);
}


var feeds = ["togglestates", 1,1,1,1];
function toggleAppFeed(obj) {
	i = obj.id.split("-");
	if (feeds[i[1]])
	{
		obj.src = obj.src.replace(".png", "-off.png");
	} else {
		obj.src = obj.src.replace("-off", "");
	}
	feeds[i[1]] = 1 - feeds[i[1]];
	updateFeeds();
}

function updateFeeds() {
	$("#feedData").html("<img src='images/spinning.gif' style='margin: 100px 0 0 60px'>");
	url = "index.php?o=update-feeds&feeds=" + feeds.concat();
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_updateFeeds;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
	txt = "";
}

function _updateFeeds() {
	if(checkReadyState(xmlhttp)) {

		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		ret=response.getElementsByTagName("content");
		$("#feedData").html(getXMLNode(ret));
	}
}

function loadBoxes() {
	tmp = "";
	tmp2 = "";
	tmp = Get_Cookie("Boxes");
	if (tmp)
	{
		tmp2 = tmp.split(",");
		for (i=1;i<=boxes.length ;i++ )
		{
			if (!parseInt(tmp2[i])) toggleBox($('#box' + i));
		}
	}

}






var box1arrowsopacity = 0;
var box1int1 = "";
var box1int2 = "";
var box1animation = true;
var box1index = 0;
var box1delta = 0;

function box1ShowArrows() {
	box1animation = true;
	box1int1 = setInterval(_box1ShowArrows, 10);
}

function _box1ShowArrows() {
	if (!box1animation) {
		clearInterval(box1int1);
		return false;
	}
	box1arrowsopacity = box1arrowsopacity + 5;
	el1 = document.getElementById("box1arrow1");
	el2 = document.getElementById("box1arrow2");
	opacity(el1, box1arrowsopacity);
	opacity(el2, box1arrowsopacity);
	if (box1arrowsopacity >= 100)
	{
		clearInterval(box1int1);
	}
}

function  box1HideArrows() {
	box1animation = true;
	box1int1 = setInterval(_box1HideArrows, 10);

}

function _box1HideArrows() {
	if (!box1animation) {
		clearInterval(box1int1);
		return false;
	}
	box1arrowsopacity = box1arrowsopacity - 5;
	if (box1arrowsopacity <= 0) box1arrowsopacity = 0;
	el1 = document.getElementById("box1arrow1");
	el2 = document.getElementById("box1arrow2");
	opacity(el1, box1arrowsopacity);
	opacity(el2, box1arrowsopacity);
	if (box1arrowsopacity <= 0)
	{
		clearInterval(box1int1);
	}
}

function box1SlideLeft() {
	box1index --;
	if (box1index >= 0)
	{
		box1int2 = setInterval(_box1SlideLeft, 10);
	} else box1index = 0;
}

function _box1SlideLeft() {
	box1delta += 15;
	if (box1delta >= 487)
	{
		box1delta = 487;
	}
	el1 = document.getElementById("box1container");
	el1.style.left = (-(box1index+1) * 487  + box1delta) + 'px';
	if (box1delta == 487)
	{
		box1delta = 0;
		clearInterval(box1int2);
	}

}

function box1SlideRight() {
	box1index ++;
	if (box1index < 3)
	{
		box1int2 = setInterval(_box1SlideRight, 10);
	} else box1index = 2;
	
}

function _box1SlideRight() {
	box1delta += 15;
	if (box1delta >= 487)
	{
		box1delta = 487;
	}
	el1 = document.getElementById("box1container");
	el1.style.left = (-(box1index-1) * 487  - box1delta) + 'px';
	if (box1delta == 487)
	{
		box1delta = 0;
		clearInterval(box1int2);
	}

}

var box2int1 = "";
//var box1index = 0;
var box2delta = 0;
var box2animation = false;
function box2FlipUp() {
	if (box2delta >= 100 || box2animation)
	{
		return false;
	}
	box2animation = true;
	setTimeout(_box2FlipUp, 500);
	
}

function _box2FlipUp() {
	box2int1 = setInterval(__box2FlipUp, 10);
}

function __box2FlipUp() {
	box2delta += 5;
	if (box2delta >= 110)
	{
		box2delta = 110;
	}
	el1 = document.getElementById("box2container");
	el1.style.top = (- box2delta) + 'px';
	if (box2delta == 110)
	{
		clearInterval(box2int1);
		box2animation = false;
	}

}

function box2FlipDown() {
	if (box2delta <= 0 || box2animation)
	{
		return false;
	}
	box2animation = true;
	box2int1 = setInterval(_box2FlipDown, 10);
}

function _box2FlipDown() {
	box2delta -= 15;
	if (box2delta <= 0)
	{
		box2delta = 0;
	}
	el1 = document.getElementById("box2container");
	el1.style.top = (- box2delta) + 'px';
	if (box2delta == 0)
	{
		clearInterval(box2int1);
		box2animation = false;
	}

}

var box3feeds = 6;
var box3curfeed = 1;
var box3animation = false;
var box3int1 = "";
var box3int2 = "";
var box3delta = 100;
function box3ScrollStart() {
	if (box3curfeed >= 6 || box3animation)
	{
		return false;
	}
	box3animation = true;
	box3int1 = setInterval(_box3ScrollStart, 10);
}

function box3ScrollStart2() {
	if (box3curfeed >= 6)
	{
		return false;
	}
	box3int1 = setInterval(_box3ScrollStart, 10);
}

function _box3ScrollStart() {
	box3delta -= 1;
	if (box3delta <= 0)
	{
		box3delta = 0;
	}
	el1 = document.getElementById("box3feed" + box3curfeed);
	opacity(el1, box3delta);
	if (box3delta == 0)
	{
		el1.style.display = "none";
		clearInterval(box3int1);
		box3curfeed ++;
		box3delta = 100;
		box3int2 = setTimeout(box3ScrollStart2, 1500);
	}

}

function box3ScrollStop() {
		clearInterval(box3int1);
		clearTimeout(box3int2);

}

var maps = ["world1", "sa", "na", "asia", "australia", "europe", "", "africa"];
function loadCountries(obj, id) {
	activemap = id;
	$(".continents a").attr("class", "");
	$(obj).attr("class", "active");
	$("#world-map").attr("src", "images/maps/map-" + maps[id] + ".jpg");
	url = "index.php?s=company&o=get-countries&id=" + id;
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_loadCountries;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}

	return false;
}

function _loadCountries() {
	if(checkReadyState(xmlhttp)) {

		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		cid = response.getElementsByTagName("countryid");
		cn = response.getElementsByTagName("countryname");
		txt = "<h2>SELECT YOUR COUNTRY</h2>";
		for (i=0; i<cid.length ; i++ )
		{
			txt += '<a href="index.php?s=company&o=sales&id='+getXMLNode(cid,i)+'">'+getXMLNode(cn,i)+'</a>';
		}

		$(".countries").html(txt);
		$(".countries").css("display", "block");
	}
}


function loadContact(id) {
	window.location="index.php?s=company&o=sales&id=" + getQueryVariable("id") + "&areaid=" + id;
//	url = "index.php?s=company&o=get-contact&id=" + id;
//	initObj();
//	if (xmlhttp!=null) {
//	  xmlhttp.onreadystatechange=_loadContact;
//	  xmlhttp.open("GET",url,true);
//	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
//	  xmlhttp.send(null);
//	}
//
	return false;
}

function loadContact2(id) {
	if (!id)
	{
		return false;
	}
	window.location="index.php?s=company&o=sales&id=" + getQueryVariable("id") + "&postalcode=" + id;
//	url = "index.php?s=company&o=get-contact&id=" + id;
//	initObj();
//	if (xmlhttp!=null) {
//	  xmlhttp.onreadystatechange=_loadContact;
//	  xmlhttp.open("GET",url,true);
//	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
//	  xmlhttp.send(null);
//	}
//
	return false;
}
//
//function _loadContact() {
//	if(checkReadyState(xmlhttp)) {
//
//		var response = xmlhttp.responseXML.documentElement;
//		response.normalize;
//		$("#SalesContactInfo").css("display", "block");
//		ret = response.getElementsByTagName("areatype"); $(".area-code").html(ret);
//		ret = response.getElementsByTagName("cname"); $(".sales-namee").html(ret);
//		ret = response.getElementsByTagName("clocation"); $(".sales-location").html(ret);
//		ret = response.getElementsByTagName("cpicture"); $(".area-code").html(ret);
//		ret = response.getElementsByTagName("areatype"); $(".area-code").html(ret);
//		ret = response.getElementsByTagName("areatype"); $(".area-code").html(ret);
//
//	}
//}


function showEvent(id) {
//	alert($("#event-info-" + id).attr("id"));
	$("#event-info-" + id).css("display", "block");
}

function hideEvent(id) {
	$("#event-info-" + id).css("display", "none");
}

var curDocCategory = 0;
function filterDocuments(obj, catid) {
	$(".sales-contacts a").attr("class", "");
	$(obj).attr("class", "active");
	curDocCategory = parseInt(catid);
	searchDocuments();
}

function searchDocuments() {
	str = $("#qSearch").val().toLowerCase();
	for (i in docs)
	{
		if ((!str || docs[i].tags.indexOf(str) >= 0) && (!curDocCategory || docs[i].categ == curDocCategory))
		{
			$("#Document" + i).css("display", "block");
		} else {
			$("#Document" + i).css("display", "none");
		}
	}

//	for (i in docs )
//	{
//		if (docs[i].categ == parseInt(catid))
//		{
//			$("#Document" + i).css("display", "block");
//		} else 
//			$("#Document" + i).css("display", "none");
//
//	}

}


function updateCatalog() {
	str = $("#qSearch").val().toLowerCase();
	q1 = parseInt($("#qComponent").val());
	q2 = parseInt($("#qSize").val());
	q3 = parseInt($("#qGating").val());

	for (i in catalog)
	{
		if ((!str || catalog[i].tags.indexOf(str) >= 0) && (!q1 || catalog[i].component == q1) && (!q2 || catalog[i].size == q2) && (!q3 || catalog[i].gate == q3))
		{
			$("#Catalog" + i).css("display", "block");
		} else {
			$("#Catalog" + i).css("display", "none");
		}
	}

}


function showLogin() {
	txt = "<div class='login'>";
	txt += '<h1>LOGIN</h1>';
	txt += '<table cellpadding="0" cellspacing="0" border="0" class="">';
	txt += '		<tr><td>Email: </td><td><input type="text" id="logEmail" value=""></td></tr>';
	txt += '		<tr><td>Password: </td><td><input type="password" id="logPassword" value=""></td></tr>';
	txt += '		<tr><td></td><td><img src="images/bt-login.png" style="cursor: pointer; " onclick="doLogin();"></td></tr>';
	txt += '	</table>';
	txt += '	<div>Don\'t have an account? <a href="#" onclick="return showRegister();">Click here to sign up</a></div>';
	txt += '	</div>';
	alert2(txt);
	return false;
}

function showRegister() {
	txt = "<div class='login'>";
	txt += '<h1>REGISTRATION</h1>';
	txt += '<table cellpadding="0" cellspacing="0" border="0" class="">';
	txt += '		<tr><td>Name: </td><td><input type="text" id="logName" value=""></td></tr>';
	txt += '		<tr><td>Company: </td><td><input type="text" id="logCompany" value=""></td></tr>';
	txt += '		<tr><td>Email: </td><td><input type="text" id="logEmail" value=""></td></tr>';
	txt += '		<tr><td>Phone: </td><td><input type="text" id="logPhone" value=""></td></tr>';
	txt += '		<tr><td>Password: </td><td><input type="password" id="logPassword" value=""></td></tr>';
	txt += '		<tr><td></td><td><img src="images/bt-register.png" style="cursor: pointer; " onclick="doRegister();"></td></tr>';
	txt += '	</table>';
	txt += '	</div>';
	alert2(txt);
	return false;
}

function doLogin() {
	 if (!$("#logEmail").val() || !$("#logPassword").val() )
	 {
		 alert("Please enter your email and password!");
		 return false;
	 }

	url = "index.php?s=support&o=login&username=" + $("#logEmail").val() + "&pwd=" + md5($("#logPassword").val());
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_doLogin;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}

	return false;
}

function _doLogin() {
	if(checkReadyState(xmlhttp)) {

		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		ret = response.getElementsByTagName("result");
		if (getXMLNode(ret) == "ok")
		{
			window.location="index.php?s=support&o=catalog";
		} else {
			alert("Your credentials are invalid, please try again.");
			return false;
		}

	}
}

function doRegister() {
	 if (!$("#logEmail").val() || !$("#logPassword").val()  || !$("#logName").val()  || !$("#logCompany").val() )
	 {
		 alert("Please fill all required fields!");
		 return false;
	 }

	url = "index.php?s=support&o=register&email=" + $("#logEmail").val() + "&name=" + $("#logName").val() + "&phone=" + $("#logPhone").val() + "&company=" + $("#logCompany").val() + "&pwd=" + md5($("#logPassword").val());
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_doRegister;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}

	return false;
}

function _doRegister() {
	if(checkReadyState(xmlhttp)) {

		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		ret = response.getElementsByTagName("result");
		if (getXMLNode(ret) == "ok")
		{
			window.location="index.php?s=support&o=catalog";
		} else {
			alert2("We're sorry, your registration could not be completed at this time!");
			return false;
		}

	}
}

function logout() {
	window.location='index.php?s=support&o=logout';
}


function loadPositions(obj, id) {
	$(".continents a").attr("class", "");
	$(obj).attr("class", "active");

	url = "index.php?s=company&o=get-positions&id=" + id;
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_loadPositions;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}

	return false;
}

function _loadPositions() {
	if(checkReadyState(xmlhttp)) {

		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		clabel = response.getElementsByTagName("positionslabel");
		cid = response.getElementsByTagName("positionid");
		cn = response.getElementsByTagName("positionname");
		cd = response.getElementsByTagName("positiondate");
		cl = response.getElementsByTagName("positionlocation");
		ctype = response.getElementsByTagName("positiontype");
		txt = "<h2>"+getXMLNode(clabel)+"</h2>";
		for (i=0; i<cid.length ; i++ )
		{
			if (getXMLNode(ctype,i) != "internal") txt += '<a href="#" onclick="showPosition(' + getXMLNode(cid,i) + ')"><span  style="color: #008c9b">'+getXMLNode(cn,i) + "</span><br><i>" + getXMLNode(cd,i) + "</i><br>" + getXMLNode(cl,i) + "</a>";
			else txt += '<a href="index.php?s=company&o=show-position&id='+getXMLNode(cid,i)+'"><span  style="color: #008c9b">'+getXMLNode(cn,i) + "</span><br><i>" + getXMLNode(cd,i) + "</i><br>" + getXMLNode(cl,i) + "</a>";
		}

		$(".positions").html(txt);
		$(".positions").css("display", "block");
	}
}

function showPosition(id) {
	url = "index.php?s=company&o=get-position&id=" + id;
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_showPosition;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}

	return false;
}
function _showPosition() {
	if(checkReadyState(xmlhttp)) {

		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		ret = response.getElementsByTagName("positiondata");
		txt = "You are about to leave the MoldMasters.com website. <a target='_blank' href='"+getXMLNode(ret) +"'><br>Click here to view the position's details and to apply</a>";
		alert2("<div style='padding: 20px;'>"+txt + "</div>");
//		alert2("<div style='padding: 20px;'><iframe width='920' height='540' frameborder='no' src='" + getXMLNode(ret) + "'></iframe></div>");
	}
}


function submitContactForm() {

	 if (!$("#Email").val() || !$("#FirstName").val()  || !$("#LastName").val()  || !$("#Comments").val()  || !$("#PostalCode").val() )
	 {
		 alert("Please fill all required fields!");
		 return false;
	 }
	url = "index.php?s=support&o=docontact&Type=" + $("#Type").val() + "&Source=" + $("#Source").val() + "&" + $("#frmContact").serialize();
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_submitContactForm;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}

	return false;
}

function _submitContactForm() {
	if(checkReadyState(xmlhttp)) {

		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		ret = response.getElementsByTagName("result");
	
		alert2("<div style='padding: 30px'>Thank your for your inquiry.</div>");

//		$("#frmContact").get(0).reset();
		$(':input','#frmContact')
		 .not(':button, :submit, :reset, :hidden')
		 .val('')
		 .removeAttr('checked')
		 .removeAttr('selected');
		return false;
	}
}

function submitSalesContactForm(contactid) {
	 if (!$("#Email").val() || !$("#Name").val()  || !$("#Type").val()  || !$("#Comments").val()  || !$("#Country").val() )
	 {
		 alert("Please fill all required fields!");
		 return false;
	 }
	url = "index.php?s=support&o=dosalescontact&id="+contactid+"&Source=" + $("#Source").val() + "&" + $("#frmSalesContact").serialize();
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_submitSalesContactForm;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}

	return false;

}

function _submitSalesContactForm() {
	if(checkReadyState(xmlhttp)) {

		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		ret = response.getElementsByTagName("result");
	
		alert2("<div style='padding: 30px'>Thank your for your inquiry.</div>");
		$(':input','#frmSalesContact')
		 .not(':button, :submit, :reset, :hidden')
		 .val('')
		 .removeAttr('checked')
		 .removeAttr('selected');

		return false;

	}
}


function playWebinar() {
	txt = '<div style="padding: 40px; background-color: #000;"><iframe width="560" height="315" src="http://www.youtube.com/embed/MvA8Hdmit-U" frameborder="0" allowfullscreen></iframe></div>';
	alert2(txt);
}

var curHistoryIndex = 0;

//1881 - 1221 = 660

var historyAnimationInProgress = false;
var historyLength = 19;
var lastDot = 0;
function historySlideLeft() {
	historyLength = historyDots.length;
	if (curHistoryIndex <= 0 || historyAnimationInProgress)
	{
		return false;
	}
	historyAnimationInProgress = true;
	var hst = new Tween($("#historySlides").get(0).style,"left",Tween.strongEaseInOut,- curHistoryIndex * 644, - (curHistoryIndex -1) * 644,1,"px");
	hst.onMotionFinished = function () {historyAnimationInProgress = false; curHistoryIndex --};
	hst.start();
	centerTimeline(curHistoryIndex-1, false);
}

function historySlideRight() {
	historyLength = historyDots.length;
	if (curHistoryIndex >= historyLength-1 || historyAnimationInProgress)
	{
		return false;
	}
	$("#dot" + lastDot).attr("src", "images/history/history-dot.png");
	historyAnimationInProgress = true;
	var hst = new Tween($("#historySlides").get(0).style,"left",Tween.strongEaseInOut,- curHistoryIndex * 644, - (curHistoryIndex + 1) * 644,1,"px");
	hst.onMotionFinished = function () {historyAnimationInProgress = false; curHistoryIndex ++};
	hst.start();
	centerTimeline(curHistoryIndex+1, false);

}

function historySlideTo(histSlide) {
	if (historyAnimationInProgress)
	{
		return false;
	}
	$("#dot" + lastDot).attr("src", "images/history/history-dot.png");
	historyAnimationInProgress = true;

	var hst = new Tween($("#historySlides").get(0).style,"left",Tween.strongEaseInOut,- curHistoryIndex * 644, - (histSlide) * 644,1,"px");
	curHistoryIndex = histSlide;
	hst.onMotionFinished = function () {historyAnimationInProgress = false; };
	hst.start();
	$("#dot" + lastDot).attr("src", "images/history/history-dot.png");
//	centerTimeline(curHistoryIndex, false);

}

function loadHistory() {
	for (i=0; i< historyDots.length ;i++ )
	{
		img = new Image();
		img.src= "images/history/history-dot.png";
		img.id = "dot"  + i;
		img.onclick = function () {showHistory(this)};
		$("#historyTimeline").append(img);
		$("#dot" + i).css("left", historyDots[i].x + 660);
		$("#dot" + i).css("top", historyDots[i].y -20);
	}
}

function showHistory(obj) {
	hid = parseInt(obj.id.replace("dot", ""));
	$("#dot" + lastDot).attr("src", "images/history/history-dot.png");
	historySlideTo(hid);
	centerTimeline(hid, false)
}

function centerTimeline(id, slideTop) {
	realpos = 660 + historyDots[id].x;
	newpos = realpos - 365;
//	alert($("#historyTimeline").css("left"));
	var hst2 = new Tween($("#historyTimeline").get(0).style,"left",Tween.strongEaseInOut,parseInt($("#historyTimeline").css("left")), - newpos, 1,"px");
//	hst.onMotionFinished = function () {historyAnimationInProgress = false; };
	hst2.start();
//	if (slideTop)
//	{
		lastDot = id;
		var hst3 = new OpacityTween($("#dot" + id).get(0),Tween.bounceEaseInOut,0,100,1);
		hst3.onMotionFinished = function () {$("#dot" + id).attr("src", "images/history/history-dot2.png")};
		hst3.start();
//	}
}

var activemap = 0;
function showMap(id) {
	$("#world-map").attr("src", "images/maps/map-" + maps[id] + ".jpg");
	
}

function hideMap() {
	$("#world-map").attr("src", "images/maps/map-" + maps[activemap] + ".jpg");

}

function playYoutube(link) {
//	http://www.youtube.com/embed/
	if (link.substring(0,4) != "http")
	{
		link = "http://www.youtube.com/embed/" + link;
	}
	link += "?rel=0";
	txt ='<iframe width="560" height="315" src="'+link+'" frameborder="0" allowfullscreen></iframe>';
	showOverlay();
	box("<div>"+'<div class="login-close" style="text-align: right"> <a href="#" onclick="parent.closeWait(); return false"><img style="position: absolute; top: 8px; right: 8px;" src="images/icon_delte_up.gif" alt="close" name="closepop"  border="0" id="closepop" onmouseover="MM_swapImage(\'closepop\',\'\',\'images/icon_delte_over.gif\',1)" onmouseout="MM_swapImgRestore()"  /></a></div>'+ "<div class='video'>" + txt+"</div></div>");

}

function showEventRegistration(eventname, eventid) {
	txt = "<div class='login'>";
	txt += '<h1>EVENT REGISTRATION</h1>';
	txt += '<table cellpadding="0" cellspacing="0" border="0" class="">';
	txt += '		<tr><td>Event: </td><td>'+eventname+'<input type="hidden" id="logEventID" value="'+eventid+'"></td></tr>';
	txt += '		<tr><td>Name: </td><td><input type="text" id="logName" value=""></td></tr>';
	txt += '		<tr><td>Company: </td><td><input type="text" id="logCompany" value=""></td></tr>';
	txt += '		<tr><td>Email: </td><td><input type="text" id="logEmail" value=""></td></tr>';
	txt += '		<tr><td>Phone: </td><td><input type="text" id="logPhone" value=""></td></tr>';
	txt += '		<tr><td></td><td><img src="images/bt-register.png" style="cursor: pointer; " onclick="doEventRegister();"></td></tr>';
	txt += '	</table>';
	txt += '	</div>';
	alert2(txt);
	return false;
}

function doEventRegister() {
	 if (!$("#logEmail").val() || !$("#logEventID").val()  || !$("#logName").val()  || !$("#logCompany").val() )
	 {
		 alert("Please fill all required fields!");
		 return false;
	 }

	url = "index.php?s=support&o=event_register&email=" + $("#logEmail").val() + "&name=" + $("#logName").val() + "&phone=" + $("#logPhone").val() + "&company=" + $("#logCompany").val() + "&id=" + $("#logEventID").val();
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_doEventRegister;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}

	return false;
}

function _doEventRegister() {
	if(checkReadyState(xmlhttp)) {

		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		ret = response.getElementsByTagName("result");
		if (getXMLNode(ret) == "ok")
		{
			txt = "You are now registered for this training event!";
			alert2("<div style='padding: 20px;'>"+txt + "</div>");
			return false;
		} else {
			txt = "We're sorry, your registration could not be completed at this time!";
			alert2("<div style='padding: 20px;'>"+txt + "</div>");
			return false;
		}
	}
}


function downloadCAD(pageid) {
	url = "index.php?s=support&o=get-cad-files&id=" + pageid;
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_downloadCAD;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}

	return false;
	
}

function _downloadCAD() {
	if(checkReadyState(xmlhttp)) {

		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		ret = response.getElementsByTagName("content");
		ret2 = response.getElementsByTagName("pageid");
		alert2("<div style='padding: 20px;'>"+ getXMLNode(ret)+ "</div>");
		$("#DownloadAll").val(getXMLNode(ret2));
	}
}


function startDownloadCAD() {
	url = "index.php?s=support&o=download-cad&pageid=" + $("#DownloadAll").val() + "&id=";
	if (!$("#DownloadAll").attr("checked"))
	{
		x = document.getElementsByName("CadID[]");
		for (i=0; i< x.length ;i++ )
		{
			if (x[i].checked) url += x[i].value + ",";
		}
	}
	alert2("<div style='padding: 30px;'>Please wait while your files are prepared for download ... <br><br><span id='downloadLink'><center><img src='cms/_common/images/loadingAnimation.gif'></center></span></div>");
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_startDownloadCAD;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}

	return false;
}

function _startDownloadCAD() {
	if(checkReadyState(xmlhttp)) {

		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		ret = response.getElementsByTagName("content");
		ret2 = response.getElementsByTagName("filesize");
		txt = "Your files are ready. Click the link below to start the download<br><br><a href='"+getXMLNode(ret)+"'>Download File ("  + getXMLNode(ret2) + ")</a>";
		$("#downloadLink").html(txt);
	}
}

function switchLanguage() {
	switch (this.value)
	{
		case "en": 
		case "de": 
			if (location.search) url = location.href + "&reset-lang=" + this.value; 
			else  url = location.href + "?reset-lang=" + this.value; 
			location = url;
			return true;
		default: url = "index.php?s=company&o=get-coming&lang=" + this.value;
	
	}
	
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_switchLanguage;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}

	return false;
	
}

function _switchLanguage() {
	if(checkReadyState(xmlhttp)) {

		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		ret = response.getElementsByTagName("content");
		showOverlay();
		box(getXMLNode(ret));
	}

}

function md5(st) {
	return st;
}
