var incheckbox=false;
var CheckMessage=false;

function showSubMenu(parent, id)

{
	menuItemHide = false;
	if (menuItemCurrent && menuItemCurrent.id == "menuitem" + id)
		return;
	if (menuItemCurrent)
	{
		if (menuItemCurrent.filters && menuItemCurrent.filters.length)
			menuItemCurrent.filters[0].apply();
		menuItemCurrent.style.visibility = "hidden";
		if (menuItemCurrent.filters && menuItemCurrent.filters.length)
			menuItemCurrent.filters[0].play();
	}
	var item = document.getElementById("menuitem" + id);
	if (!item) return;
	var isRtl = document.body.style.direction == "rtl";
	item.style.top = _offsetTop(parent) - 1;
	item.style.left = _offsetLeft(parent) - (isRtl ? item.offsetWidth - 30 : -parent.offsetWidth + 30);
	if (item.filters && item.filters.length)
		item.filters[0].apply();
	item.style.visibility = "visible";
	if (item.filters && item.filters.length)
		item.filters[0].play();
	menuItemCurrent = item;
}
function hideSubMenu()
{
	if (!menuItemHide)
		return;
	if (menuItemCurrent.filters && menuItemCurrent.filters.length)
		menuItemCurrent.filters[0].apply();
	menuItemCurrent.style.visibility = "hidden";
	if (menuItemCurrent.filters && menuItemCurrent.filters.length)
		menuItemCurrent.filters[0].play();
	menuItemCurrent = null;
	menuItemHide = false;
}
var menuItemCurrent = null;
var menuItemHide = false;
var globalEvent;

function _offsetTop(obj)
{
	var top = 0;
	for (; obj; obj=obj.offsetParent)
		top += obj.offsetTop;
	return top;
}

function _offsetLeft(obj)
{
	var left = 0;
	for (; obj && obj != document.body; obj=obj.offsetParent)
		left += obj.offsetLeft;
	return left;
}

// returns true if node a contains event.toElement/relatedTarget.
function containsToElement(a)
{
	var b = globalEvent.toElement ? globalEvent.toElement : globalEvent.relatedTarget;
	while (b.parentNode)
		if ((b = b.parentNode) == a)
			return true;
	return false;
}

/*
	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 = "";
	var titleb="Please fill "
	var check=0;
	var temp="";
	var messagex="";
	var messagexR="";
	var strva="";
	var strvaR="";
	var Emailvalid="";
	var invaliddig="";
	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				
		//return;
		switch (input.type.toLowerCase())
		{
		case "text":
		case "password":
		case "textarea":
		case "file":
			t=input.value.toString()
			//check=checktavForm(t);											
			//if  (check==-1)
			//{			
			//	input.focus();
			//	return false;				
			//}
			if (!input.getAttribute("validation"))
				input.setAttribute("validation", "string");
			if (input.getAttribute("mandatory"))
			{
				if (input.getAttribute("mandatory").toLowerCase() != "true" && input.value.length == 0)
					continue;
			}
			else
				if (input.value.length == 0)
					continue;
		
			switch (input.getAttribute("validation").toLowerCase())
			{
			case "string":
			case "password":
				if (input.value.length == 0)
					valid = false;					
				break;
			case "integer":											
			invaliddig="";
				if (!/\d+/.test(input.value))																			
					valid = false;												
				if(isnum(input.value)==false)				
				{
				invaliddig=input.validationError + " Invalid value. Please enter only digits";																														
				valid = true;
				}
				break;
			case "email":
				if (!/^[\w\.\-]+@[\w\-]+(\.\w+)+$/.test(input.value))
				{
				if (input.value.length > 0)
				{
				Emailvalid="The Email field requires the two symbols: \"@\" and \".\", Please re-enter the Email address";							
				input.focus();
				}	
				else
				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;
				break;
			default:
				var regExp = new RegExp(input.getAttribute("validation"), "im");
				valid = regExp.test(input.value);
			}

			// 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 "radio":
			if (input.getAttribute("mandatory"))
			{		 		
				temp=eval("document.getElementsByName('" + input.getAttribute("name") + "')");										
				var y=0;
				var x=0;
				strvaR="";
				if (temp.length>1)
				{
					for(y=0;y<temp.length;y++)				
					{
					
					if (temp[y].checked==false)
					x=x+1
					else					
					strvaR=strvaR + temp[y].value + "|";					 					
					
					}
					
					if (strvaR=="")
					valid=false;
				}
				else	
				{
				valid = input.checked;
				}						
			}		
			break;
		case "checkbox":						 
		 	
			if (input.getAttribute("mandatory"))
			{	
		 		
				temp=eval("document.getElementsByName('" + input.getAttribute("name") + "')");										
				var j=0;
				var x=0;
				
				if (temp.length>1)
				{
					strva="";
					for(j=0;j<temp.length;j++)				
					{
					if (temp[j].checked==false)
					x=x+1
					else					
					strva=strva + temp[j].value + "|";					 					
					
					}
			
					if (strva=="")
					valid=false;
				}
				else	
				{
				valid = input.checked;
				
				}						
			}
			break;
		}

		
		if (!valid)
		{
			
			
			if (input.getAttribute("validationError"))
			{
				if(input.type.toLowerCase() =="checkbox" || input.type.toLowerCase() =="radio")		
				{			
				
				if (input.type.toLowerCase() =="radio")
				{
				messagexR = input.getAttribute("validationError") + "\n";
				
				}
				else
				messagex = input.getAttribute("validationError") + "\n";
				
				}
				else
				{
				if(input.type.toLowerCase()!="checkbox")					
				sErrorMsg += input.getAttribute("validationError") + "\n";
				}
			}
			else
			{
				
				sErrorMsg += "Error in field " + input.name + "\n";
			}
		}
	}
	if (sErrorMsg.length ||  messagex!="" || messagexR!="" ||  Emailvalid!="" || invaliddig!="")	
	{
		sErrorMsg=sErrorMsg + messagex + messagexR + Emailvalid + invaliddig;
		alert((titleb ? titleb + "\n" : "") + sErrorMsg);
		return false;
		
	}
	else
	{
	
		if (submit)
			form.submit();
		return true;
	}
}

function SendS(str,keyx)
{

if (str.length<2)
{
	alert("Please type more then one character")
	return false;
	
}
check=0;
	check=checktav(str)	
	if (check==-1)		
		document.FormS.q.focus();
	else
	{			
		document.FormS.action="Search.aspx?&q=" +  str;
		document.FormS.submit();
	}
}

function checktav(the_string,keyx){
		for(i=0;i<=the_string.length;i++) 
		{
			 
			 tav=(the_string.toLowerCase().charAt(i));
			 if(tav=="'" ||  tav=="*" || tav=="%")
			 {
			 	
			 	alert("Invalid characters " + tav)
			 	return -1;
			 }
		}
return 0;
}

	function isnum(the_string) {
	var numbers="1234567890";	
		for(i=0;i<=the_string.length;i++) {
			 if(numbers.indexOf(the_string.charAt(i),0)<0)
			 	return false
		}
	}
	
function checktavForm(the_string){
		for(i=0;i<=the_string.length;i++) 
		{
			 
			 tav=(the_string.toLowerCase().charAt(i));
			 if(tav=="*")
			 {
			 	
			 	alert("Invalid characters " + tav)
			 	return -1;
			 }
		}
return 0;
}
	
function OpenSpecialForm(objpath,objid)
{
}

function QuiqAccess(PageId)
{
temp=PageId;
document.location= temp;
}