
var l = 0;
function onLoad() 
{
	if(document.all.cnt!='undefined')
	{
	
				setTimeout("swapPicture(img" + l + ")",100);
			
	}
	
}

function swapPicture(newImage)
{

	
	document.all.myimg.style.filter="blendTrans(duration=1)";
	document.all.myimg.filters.blendTrans.Apply();
	

	if(document.all.myimg.src!=newImage.src)
		document.all.myimg.src=newImage.src;
	document.all.myimg.filters.blendTrans.Play();
	
	l++;
	if(l>=cnt)
		l=0;
	setTimeout("swapPicture(img" + l + ")",3000);
	
}
function toggleDisplay(o)
{
	if (!o) return;
	if (currentDisplay && currentDisplay != o)
		currentDisplay.style.display = "none";
	currentDisplay = o;
	if (o.style.display == "")
		o.style.display = "none";
	else
		o.style.display = "";
}
var currentDisplay = null;



function checkSurvey(form)
{
	var element, i;
	for (i=0; i<form.elements.length; i++)
	{
		element = form.elements[i];
		if (element.type == "radio" && element.checked)
			return true;
	}
	return false;
}

function openWindow(url, width, height, name)
{
	if (typeof(url) == "number")
		url = "content.aspx?id=" + url;
	var top, left, i;
	if (!width)
	{
		width = screen.availWidth - 10;
		left = 0;
	}
	else
		left = (screen.availWidth - width) / 2;
	if (!height || screen.availHeight - height < 0)
	{
		height = screen.availHeight - 30;
		top = 0;
	}
	else
	{
		top = (screen.availHeight - height) / 2;
		if (height > screen.availHeight)
			height = screen.availHeight;
	}
	var options = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width + ",resize=no,scrollbars=auto,toolbar=no,location=no,menubar=no,status=no";
	if (/\.(gif|jpg|jpeg|png)$/i.test(url))
	{
		try
		{
			var win, body, img;
			win = window.open("", name, options);
			body = win.document.body;
			body.style.margin = "0px";
			body.style.textAlign = "center";
			body.scroll = "auto";
			url = url.split("|");
			for (i=0; i<url.length; i++)
			{
				if (!/^[a-z]:\/\//i.test(url[i]))
				{
					if (url[i].substring(0, 1) == "/")
						url[i] = location.protocol + location.port + "//" + location.hostname + url[i];
					else
						url[i] = location.protocol + location.port + "//" + location.hostname + /(.*\/)/.exec(location.pathname)[0] + url[i];
				}
				body.appendChild(img = win.document.createElement("IMG"));
				img.src = url[i];
			}
		}
		catch (e)
		{
			window.open(url, name, options);
		}
	}
	else
		window.open(url, name, options);
}

/*
	Validate a form's elements according to varius attributes
*/
function validateForm(form, title, submit)
{
	var i, j, u, sum;
	var input;
	var valid;
	var sErrorMsg = "";

	for (i=0; i<form.elements.length; i++)
	{
		input = form.elements[i];
		// skip input when it's not rendered (ie. parent display:none)
		if (input.offsetHeight == 0) continue;
		valid = true;

		// Validate value according to element type and validation type
		switch (input.type.toLowerCase())
		{
		case "text":
		case "password":
		case "textarea":
		case "file":
			if (!input.getAttribute("validation")) continue;
			if (input.getAttribute("mandatory"))
			{
				if (input.getAttribute("mandatory").toLowerCase() == "false" && input.value.length == 0) continue;
			}
			else
				continue;
			switch (input.getAttribute("validation").toLowerCase())
			{
			case "string":
				if (input.value.length == 0)
					valid = false;
				break;
			case "password":
				if (input.value.length == 0)
					valid = false;
				break;
			case "integer":
				if (!/\d+/.test(input.value))
					valid = false;
				break;
			case "email":
				if (!/^[\w\.\-]+@[\w\-]+(\.\w+)+$/.test(input.value))
					valid = false;
				break;
			case "phone":
				if (!/^\+?\d+(-\d+)*$/.test(input.value))
					valid = false;
				break;
			case "id":
				j = input.value.toString();
				input.value = j.replace(/\D/g, "");
				if (/\d+/.test(input.value))
				{
					sum = 0;
					for (j=0; j<input.value.length; j++)
					{
						u = (j % 2 ? 2 : 1) * parseInt(input.value.charAt(input.value.length - j - 1));
						sum += u > 9 ? Math.floor(u / 10) + u % 10 : u;
					}
					if (sum % 10) valid = false;
				}
				else
					valid = false;
				break;
			case "compare":
				// Check the compareInput attribute
				if (input.getAttribute("compareInput"))
					if (input.value != form.elements[input.getAttribute("compareInput")].value)
						valid = false;
			}

			// Validate max and min according to validation type
			if (valid == true)
			{
				switch (input.getAttribute("validation").toLowerCase())
				{
				case "integer":
					if (input.getAttribute("validmax"))
					{
						if (parseInt(input.value) > parseInt(input.getAttribute("validmax")))
							valid = false;
					}
					if (input.getAttribute("validmin"))
					{
						if (parseInt(input.value) < parseInt(input.getAttribute("validmin")))
							valid = false;
					}
					break;
				default:
					if (input.getAttribute("validmax"))
					{
						if (input.value.length > input.getAttribute("validmax")) valid = false;
					}
					if (input.getAttribute("validmin"))
					{
						if (input.value.length < input.getAttribute("validmin")) valid = false;
					}
					break;
				}
			}
			break;
		case "select-one":
			if (input.getAttribute("mandatory"))
				if (input.selectedIndex == 0)
					valid = false;
			break;
		case "select-multiple":
			if (input.getAttribute("mandatory"))
			{
				sum = 0;
				for (j=0; j<input.options.length; j++)
				{
					if (input.options[j].selected) sum++;
				}
				if ((!input.getAttribute("validmax")) && (!input.getAttribute("validmin")))
				{
					if (sum == 0) valid = false;
				}
				else
				{
					if (input.getAttribute("validmax"))
					{
						if (sum > input.getAttribute("validmax")) valid = false;
					}
					if (input.getAttribute("validmin"))
					{
						if (sum < input.getAttribute("validmin")) valid = false;
					}
				}
			}
			break;
		case "checkbox":
			if (input.getAttribute("mandatory"))
				if (!input.checked)
					valid = false;
			break;
		}

		if (!valid)
		{
			if (input.getAttribute("validationError"))
				sErrorMsg += input.getAttribute("validationError") + "\n";
			else
				sErrorMsg += "Error in field " + input.name + "\n";
		}
	}
	if (sErrorMsg.length)
	{
		alert((title ? title + "\n" : "") + sErrorMsg);
		return false;
	}
	else
	{
		if (submit)
			form.submit();
		return true;
	}
}
