function DialogArguments()
{
	this.parent = window;
}

function loadCategory(lngCategoryID)
{
	location.href = "content.aspx?id=" + lngCategoryID;
}
function sendTo()
{
	var wLeft;
	var wTop
	wLeft = (window.screen.width/2) - 160;
	wTop = (window.screen.height/2) - 90;
	newWin = window.open("SendToFriend.aspx" , "newwin", "top=" + wTop + ",left=" + wLeft + ",width=320,height=180,resizable=no,scrollbars=no,toolbar=no,location=no,directories=no,menubar=no,status=no");
}

function printContent()
{
	
	var w = window.open('PrintDocument.html','name','top=5000;left=5000;height=400,width=500');
}

function openSurvey()
{
	var wLeft;
	var wTop
	wLeft = (window.screen.width/2) - 210;
	wTop = (window.screen.height/2) - 160;
	var w = window.open("Survey.aspx","","top=" + wTop + ",left=" + wLeft + ",width=420,height=320,resizable=no,scrollbars=yes,toolbar=no,location=no,directories=no,menubar=no,status=no")
}

/*
	Validate a form's elements according to varius attributes.
*/
function validateForm(form, title, submit, validclass, invalidclass)
{
	var i, j, u, sum;
	var input;
	var valid;
	var sErrorMsg = "";

	if (invalidclass)
	{
		for (i=0; i<document.styleSheets(0).rules.length; i++)
			if (document.styleSheets(0).rules.item(i).selectorText.toLowerCase() == "." + invalidclass.toLowerCase())
			{
				invalidclass = document.styleSheets(0).rules.item(i).style;
				break;
			}
	}

	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.validation) continue;
			if (input.mandatory)
			{
				if (input.mandatory.toLowerCase() == "false" && input.value.length == 0) continue;
			}
			else
			{
				continue;
			}
			switch (input.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.compareInput)
					if (input.value != form.elements[input.compareInput].value)
						valid = false;
			}

			// Validate max and min according to validation type
			if (valid == true)
			{
				switch (input.validation.toLowerCase())
				{
				case "integer":
					if (input.validmax)
					{
						if (parseInt(input.value) > parseInt(input.validmax))
							valid = false;
					}
					if (input.validmin)
					{
						if (parseInt(input.value) < parseInt(input.validmin))
							valid = false;
					}
					break;
				default:
					if (input.validmax)
					{
						if (input.value.length > input.validmax) valid = false;
					}
					if (input.validmin)
					{
						if (input.value.length < input.validmin) valid = false;
					}
					break;
				}
			}
			break;
		case "select-one":
			if (input.mandatory)
			{
				if (input.selectedIndex == 0) valid = false;
			}
			break;
		case "select-multiple":
			sum = 0;
			for (j=0; j<input.options.length; j++)
			{
				if (input.options[j].selected) sum++;
			}
			if ((!input.validmax) && (!input.validmin))
			{
				if (sum == 0) valid = false;
			}
			else
			{
				if (input.validmax)
				{
					if (sum > input.validmax) valid = false;
				}
				if (input.validmin)
				{
					if (sum < input.validmin) valid = false;
				}
			}
			break;
		case "checkbox":
			if (input.mandatory)
			{
				if (!input.checked) valid = false;
			}
			break;
		}

		if (!valid)
		{
			if (input.validationError)
			{
				sErrorMsg += input.validationError + "\n";
			}
			else
			{
				sErrorMsg += "Error in field " + input.name + "\n";
			}
			if (invalidclass)
			{
				if (typeof(input.originalColor) == "undefined") input.originalColor = input.style.color;
				if (typeof(input.originalBackgoundColor) == "undefined") input.originalBackgoundColor = input.style.backgroundColor;
				input.style.color = invalidclass.color;
				input.style.backgroundColor = invalidclass.backgroundColor;
			}
		}
		else
		{
			if (typeof(input.originalColor) != "undefined") input.style.color = input.originalColor;
			if (typeof(input.originalBackgoundColor) != "undefined") input.style.backgroundColor = input.originalBackgoundColor;
		}
	}
	if (sErrorMsg.length)
	{
		alert(title + "\n" + sErrorMsg);
		return(false);
	}
	else
	{
		if (submit)
		{
			form.submit();
		}
		return(true);
	}
}

function init()
{
	window.onresize = prepare_recalc;
	recalc();
}

// Envokes recalc() in 200ms, but first cancels last envoke
function prepare_recalc()
{
	window.setTimeout("recalc();", 1);
}

function recalc()
{
	if(document.all["Data"])
	{
			if (document.body.clientHeight>140)
			document.all["Data"].style.height = document.body.clientHeight-140
	}
}

function SearchSubmit()
{
	var L_SearchText = document.forms["Search"].elements["q"].value;
	//alert(L_SearchText);
	if (L_SearchText == "")
		return(false);
	return(true);
}

function getDescription(p_ID)
{
	var wLeft;
	var wTop;
	wLeft = (window.screen.width/2) - 290;
	wTop = (window.screen.height/2) - 180;
	newWin = window.open("ModelDescription.aspx?id=" + p_ID, "NewWin", "top="+ wTop +",left=" + wLeft + ",width=100,height=100,resizable=yes,toolbar=no,location=no,directories=no,menubar=no,status=no");
	return;
}

function getBranch(p_ID)
{
	var wLeft;
	var wTop;
	wLeft = (window.screen.width/2) - 125;
	wTop = (window.screen.height/2) - 120;
	newWin = window.open("BranchDescription.aspx?p=" + p_ID, "NewWin", "top="+ wTop +",left=" + wLeft + ",width=0,height=0,resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,menubar=yes,status=no");
	return;
}

//------------------------------------------------------------------
// Name      : SetSizeAndFocus
// Use       : This function resize the window and locat him in the middel.
// Parameters: None.
// Author    : Peleg Rozenberg
// Date      : 13/03/2003
//------------------------------------------------------------------
function SetSizeAndFocus()
{
	var L_ScreeWidth = window.screen.width;
	var L_ScreeHeight = window.screen.height;
	var L_MainTableWidth = document.getElementById("MainTable").offsetWidth;
	var L_MainTableHeight = document.getElementById("MainTable").offsetHeight;
	var L_XMove = 0;
	var L_YMove = 0;
	if (L_MainTableWidth + 28 > L_ScreeWidth)
		L_MainTableWidth = L_ScreeWidth;
	else
		L_MainTableWidth = L_MainTableWidth + 28;
	if (L_MainTableHeight + 57 > L_ScreeHeight - 28)
		L_MainTableHeight = L_ScreeHeight - 28;
	else
		L_MainTableHeight = L_MainTableHeight + 57;
	if (L_MainTableWidth < L_ScreeWidth)
		L_XMove = (L_ScreeWidth - L_MainTableWidth) / 2;
	if (L_MainTableHeight + 28 < L_ScreeHeight)
		L_YMove = (L_ScreeHeight - L_MainTableHeight) / 2;
	try
	{
		window.moveTo(L_XMove, L_YMove);
		window.resizeTo(L_MainTableWidth, L_MainTableHeight);
	}
	catch(e)
	{

	}
	document.getElementById("MainTable").width = "100%";
	window.focus();
	return(true);
}
