// DOM helper
if (document.all) {
	var domRef = ".all";
} else {
	var domRef = ".getElementById";
}

// image ID, new image 
function swapImg(sImg, sSrc) {
	document.images[sImg].src = sSrc;
}

// object ID
function hideObj(sObj) {
	eval("document" + domRef + "('" + sObj + "').style.display = 'none'");
}

// object ID
function showObj(sObj) {
	eval("document" + domRef + "('" + sObj + "').style.display = ''");
}

// object ID, top (y), left (x)
function positionObj(sObj, iTop, iLeft) {
	eval("document" + domRef + "('" + sObj + "').style.top = iTop");
	eval("document" + domRef + "('" + sObj + "').style.left = iLeft");
}

function animateObj(sObj, iTop0, iLeft0, iTop1, iLeft1, iIncrement, sShow, sNext) {
	eval('var ' + sObj + 'X = iLeft0');
	eval('clearTimeout(' + sObj + 'TimeOut)');
	positionObj(sObj, iTop0, iLeft0);
	if (iLeft0 < iLeft1) {
		positionObj(sObj, iTop1, iLeft1);
		eval('clearTimeout(' + sObj + 'AniTimeOut)');
		if (sShow != 'null') showObj(sShow);
		if (sNext != 'null') window.location.href = sNext;
	} else {
		iLeft0 = iLeft0 - iIncrement;
		eval( sObj + "AniTimeOut = setTimeout(\"animateObj('" + sObj + "', " + iTop0 + ", " + iLeft0 + ", " + iTop1 + ", " + iLeft1 + ", " + iIncrement + ", '" + sShow + "', '" + sNext + "')\", 0)" );
	}	
}

// a = obj name
// b = start top (y)
// c = start left (x)
// d = end top (y)
// e = end left (x)
// f = wait x milliseconds before animation
// g= move x pixels during animation
// h = display x object after animation
// i = goto x page after animation
// moveObj('a', b, c, d, e, f, g, 'h', 'i');
function moveObj(sObj, iTop0, iLeft0, iTop1, iLeft1, iDelay, iIncrement, sShow, sNext) {
	eval( sObj + "TimeOut = setTimeout(\"animateObj('" + sObj + "', " + iTop0 + ", " + iLeft0 + ", " + iTop1 + ", " + iLeft1 + ", " + iIncrement + ", '" + sShow + "', '" + sNext + "')\", " + iDelay + ")" );
}

// number of feedback items to hide
function hideFeedback(iObjects) {
	for (x = 1; x <= iObjects; x++) {
		hideObj('feedback' + x);
	}
}

// feedback number to show 
function showFeedback(iObject) {
	showObj('feedback' + iObject);
}

// number of options 
function clearChecks(iObjects) {
	for (x = 1; x <= iObjects; x++) {
		swapImg('opt' + x + 'Img', 'images/check_unchecked.gif');
	}
}

// option number to check
function checkOption(iObject) {
	swapImg('opt' + iObject + 'Img', 'images/check_choosen.gif');
}

// show next control after x clicks
function checkClicks() {
	iClick++;
	if (iClick >= iClicks) {
		showObj('next');
	}
}

function popupWin(sUrl) {
	window.open(sUrl, 'popup', 'width=600,height=538,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1');
}

// create cookie
function createCookie(sName, bValue) {
	var sName = sName;
	var bValue = bValue;
	var dExpires = new Date();
	var dTemp = dExpires.getTime() + (365 * 24 * 60 * 60 * 1000);
	dExpires.setTime(dTemp);
	var sPath = '/'
	document.cookie = sName + "=" +escape(bValue) +
		( (dExpires) ? ";expires=" + dExpires.toGMTString() : "") +
		( (sPath) ? ";path=" + sPath : "")
}

// delete Cookie
function deleteCookie(sName) {
	document.cookie = sName + "=" + "; path=/; + expires=Thu, 01-Jan-70 00:00:01 GMT";
}

// read cookie
function readCookie(s) {
	var sCookie = s + '=';
	var iStart = document.cookie.indexOf(sCookie);
	var iEnd = document.cookie.indexOf(";", iStart);
	if (iEnd == -1) iEnd=document.cookie.length;
	var bValue = document.cookie.substring(iStart + sCookie.length, iEnd);
	return(unescape(bValue));
}