var finalPosX,finalPosY;
var ttopBeg, lleftBeg;
var ttop,lleft ;
var step = 4;
var curMenu = ""
var TimeOutId;
var curSubMenu;
var curTopMenu;
var curBotMenu;
var curMenuId;
var menuElemWasClicked = false;
var lastTopMenuId;
var lastBotMenu;
var firstBotMenu;

var topNavLefton = new Image();
var topNavRighton = new Image();

var topNavLeftoff = new Image();
var topNavRightoff = new Image();

var topNavCorner3L = new Image();
var topNavCorner3R = new Image();

var topNavCorner2R = new Image();
var topNavCorner2L = new Image();
var topNavCorner1 = new Image();
var topNavCorner2 = new Image();
var topNavCorner3 = new Image();

var topNav1Ron = new Image();
var topNav2Ron = new Image();
var topNav1Lon = new Image();
var topNav2 = new Image();
var topNav1 = new Image();

topNavLefton.src = "images/topnav-dropdown-left-on.gif";
topNavRighton.src = "images/topnav-dropdown-right-on.gif";
topNavLeftoff.src = "images/topnav-dropdown-left-off.gif";
topNavRightoff.src = "images/topnav-dropdown-right-off.gif";

topNavCorner3L.src = "images/topnav-corner-3-left.gif";
topNavCorner2L.src = "images/topnav-corner-2-left.gif";		
topNavCorner3R.src = "images/topnav-corner-3-right.gif";
topNavCorner2R.src = "images/topnav-corner-2-right.gif";

topNavCorner3.src = "images/topnav-corner-3.gif";
topNavCorner2.src = "images/topnav-corner-2.gif";
topNavCorner1.src = "images/topnav-corner-1.gif";

topNav1Lon.src = "images/topnav-1-left-on.gif";
topNav2Ron.src = "images/topnav-2-right-on.gif";
topNav1Ron.src =  "images/topnav-1-right-on.gif";

topNav2.src = "images/topnav-2.gif";
topNav1.src ="images/topnav-1.gif";
function Move(event,elName,countSubElements,menuCounter,isLast,isFirst,flashImageID)
{
	bottomMenuSelect(menuCounter,isLast,isFirst);
	var intCurrentImageNum = elName;
	elName = 'subMenu_'+elName;
	if(curMenu == elName) return;	
	HideAllMenu();
	var posX , posY
	var p = event.srcElement;
	var callerHeight = 15;
	
	if(window.document.clock1 && typeof(window.document.clock1.classid) != 'undefined'){
	window.document.clock1.SetVariable("CheckFlag", 1);
	window.document.clock1.SetVariable("FlashImagePosition", intCurrentImageNum+1);
	window.document.clock1.SetVariable("FlashImageNumber", flashImageID);
	//alert('imgPos='+ (intCurrentImageNum+1) +';imgID=' + flashImageID)
	}	
	if(document.getElementById(elName) == null) return;
	var el = document.getElementById(elName);
	
	//if(typeof(el) == 'undefined')return;
	if(el.style.visibility == "visible") return;
	var gx = 3;
	var gy = 0;
	
	while(p&& p.offsetParent)
	{
		p=p.offsetParent;
		gx+=p.offsetLeft;
		gy+=p.offsetTop;
	}

	el.style.left = gx-1 - 10 + "px";
	el.style.top = gy +1+ callerHeight - el.clientHeight+"px";
	
	el.style.visibility = "visible";
	//for(var i=1;i<=1000000;i++){var a = 1}
	
	
	finalPosY = gy + callerHeight-1;
	finalPosX = gx -(countSubElements+1)*10;

	ttopBeg = parseInt(el.style.top);
	lleftBeg = parseInt(el.style.left);
	
	ttop = ttopBeg;
	lleft = lleftBeg;
	curMenu = elName;
	MoveMenu(elName);

}

function MoveMenu(elName)
{
	if(ttop<finalPosY) TimeOutId = setTimeout("MoveMenu('"+elName+"')",20);
	ttop +=step;
	var el=document.getElementById(elName);
	lleft = Math.round(  lleftBeg - (lleftBeg - finalPosX)* (ttop-ttopBeg)/(finalPosY-ttopBeg) );
	el.style.left = lleft + "px";
	el.style.top = ttop + "px";
	
}
function HideAllMenu()
{
	curMenu = "";
	if(window.document.clock1 && typeof(window.document.clock1.classid) != 'undefined'){
		window.document.clock1.SetVariable("CheckFlag", 1);
		window.document.clock1.SetVariable("FlashImagePosition", 0);
	}
	
	if(TimeOutId)clearTimeout(TimeOutId);
	var divs = document.getElementsByTagName("DIV")
	for(var i = 0;i<divs.length;i++)
	{
		var subM = divs[i];
		if(subM.className == 'Test18' && subM.style.visibility == "visible")
			subM.style.visibility = "hidden";
	}	
}
function GetPartElement(subElem)
{
	var partFrame = subElem
	while (partFrame)
		if(partFrame.className == 'Test18' ||partFrame.className == 'main' || partFrame.className == 'topNavMenu' || partFrame.className == 'botNavMenu')
		{
			return true;
		}
		else {partFrame = partFrame.parentElement;}
	return false;
}
function GetPartElement1(subElem, classElemName)
{
	var partFrame = subElem
	//a++
	while (partFrame)
	{
		if(partFrame.className == classElemName)
		{
			return true;
		}
		else {
		partFrame = partFrame.parentElement;
		}
	}
	return false;
}
function onMouseMove()
{
	var zone = document.elementFromPoint(event.x, event.y);
	
	if(!GetPartElement(zone)) {
		HideAllMenu();
		UnselectSubMenu(curSubMenu);
		if(!menuElemWasClicked )
		{
			if(GetPartElement1(document.getElementById('td_'+curMenuId),'topNavMenu'))
			{
				UnselectBotMenu(curBotMenu);
				if(curTopMenu != curMenuId)	topMenuSelect(curMenuId,0);
			}
			else if(GetPartElement1(document.getElementById('td_'+curMenuId),'botNavMenu') )
			{
				UnselectTopMenu(curTopMenu);
				if(curBotMenu != curMenuId)bottomMenuSelect(curMenuId,curMenuId == lastBotMenu,curMenuId == firstBotMenu)
			}
		}	
	};
}
function SubMenuMouseOver(menuNum,elemNum)
{
	if(curSubMenu != menuNum+ '' +elemNum)UnselectSubMenu(curSubMenu);
	
	document.all['leftimg_'+menuNum+''+elemNum].src = topNavLefton.src; //"images/topnav-dropdown-left-on.gif";
	document.all['rightimg_'+menuNum+''+elemNum].src = topNavRighton.src; //"images/topnav-dropdown-right-on.gif";
	var tr = document.getElementById("tr_"+menuNum+''+elemNum)
	for(var i =0; i<tr.childNodes.length;i++)
	{
		var elem = tr.childNodes[i];
		if(typeof(elem.className) !='undefined' && elem.className == "HoriznavDropdownOff")
			elem.className = "HoriznavDropdownOn";
				if(elem.childNodes.length >0)
				{
					for(var k =0; k < elem.childNodes.length;k++)
					{
						if(elem.childNodes[k].className != 'undefined' && elem.childNodes[k].className == 'HoriznavDropdownOff')
							elem.childNodes[k].className = "HoriznavDropdownOn";
					}
				}
	}
	curSubMenu = menuNum+ '' +elemNum;
	
}
function UnselectSubMenu(curMenuID)
{
	if(curMenuID == null)return;
	var curSubMenuTR = document.getElementById("tr_"+curMenuID)
	document.all['leftimg_'+curMenuID].src = topNavLeftoff.src; //"images/topnav-dropdown-left-off.gif";
	document.all['rightimg_'+curMenuID].src = topNavRightoff.src; //"images/topnav-dropdown-right-off.gif";
	
	for(var i =0; i<curSubMenuTR.childNodes.length;i++)
	{
		var elem = curSubMenuTR.childNodes[i];
		if(typeof(elem.className) !='undefined' && elem.className == "HoriznavDropdownOn")
			elem.className = "HoriznavDropdownOff"
				if(elem.childNodes.length >0)
				{
					for(var k =0; k < elem.childNodes.length;k++)
					{
						if(elem.childNodes[k].className != 'undefined' && elem.childNodes[k].className == 'HoriznavDropdownOn')
							elem.childNodes[k].className = "HoriznavDropdownOff";
					}
				}			
	}
	curSubMenu = null;
	
}
function bottomMenuSelect(elemId,isLast,isFirst)
{
	elemId = parseInt(elemId);
	//UnselectTopMenu(curTopMenu);
	if(curBotMenu != null && elemId  != curBotMenu) {UnselectBotMenu(curBotMenu);}

	var nextInt = elemId +1;
	var prevInt = elemId -1;
	if(isFirst != 0)//first
	{
		firstBotMenu = elemId;
		document.all['botimg_'+prevInt+''+elemId].src =  topNavCorner3L.src; //"images/topnav-corner-3-left.gif";
	}
	else
	{
		document.all['botimg_'+prevInt+''+elemId].src = topNavCorner2L.src; //"images/topnav-corner-2-left.gif";		
	}
	if(isLast != 0)//last
	{
		lastBotMenu = elemId;
		document.all['botimg_'+elemId+''+nextInt].src = topNavCorner3R.src; //"images/topnav-corner-3-right.gif";
	}
	else{
		document.all['botimg_'+elemId+''+nextInt].src = topNavCorner2R.src; //"images/topnav-corner-2-right.gif";
	}
	document.all['td_'+elemId].className = 'HoriznavOn';
	curBotMenu = elemId;
}

function UnselectBotMenu(botMenuId)
{
	if(botMenuId == null)return;
	var el = document.getElementById('td_'+botMenuId);
	var nextInt = botMenuId +1;
	var prevInt = botMenuId -1;
	
	if(lastBotMenu != null && botMenuId == lastBotMenu)
		document.all['botimg_'+botMenuId+''+nextInt].src = topNavCorner3.src; //"images/topnav-corner-3.gif";
	else
		document.all['botimg_'+botMenuId+''+nextInt].src = topNavCorner2.src; //"images/topnav-corner-2.gif";
	if(firstBotMenu != null && botMenuId == firstBotMenu)
		document.all['botimg_'+prevInt+''+botMenuId].src = topNavCorner1.src;//"images/topnav-corner-1.gif";		
	else
		document.all['botimg_'+prevInt+''+botMenuId].src = topNavCorner2.src; //"images/topnav-corner-2.gif";		
	
	el.className = "Horiznav";
	curBotMenu = null;
}
function topMenuSelect(elemId,isLast)
{
	elemId = parseInt(elemId);
	//UnselectBotMenu(curBotMenu);
	if(curTopMenu != null && elemId  != curTopMenu) {UnselectTopMenu(curTopMenu);}
	
	var nextInt = elemId +1;
	var prevInt = elemId -1;
	if(elemId !=0 && typeof(document.all['img_'+prevInt+''+elemId]) != 'undefined')
	{
		document.all['img_'+prevInt+''+elemId].src = topNav1Lon.src; //"images/topnav-1-left-on.gif";
	}	
	if(isLast !=0)
	{
		lastTopMenuId = elemId;
		document.all['img_'+elemId+''+nextInt].src = topNav2Ron.src; //"images/topnav-2-right-on.gif";
	}
	else
		document.all['img_'+elemId+''+nextInt].src = topNav1Ron.src;//"images/topnav-1-right-on.gif";
	document.all['td_'+elemId].className = 'topNavOn';
	curTopMenu = elemId;
	
}
function UnselectTopMenu(topMenuId)
{
	if(topMenuId == null)return;
	var el = document.getElementById('td_'+topMenuId);
	var nextInt = topMenuId +1;
	var prevInt = topMenuId -1;
	if(document.all['img_'+topMenuId+''+nextInt])
	{
		if(lastTopMenuId != null && topMenuId ==lastTopMenuId)
		document.all['img_'+topMenuId+''+nextInt].src = topNav2.src;//"images/topnav-2.gif";
		else
		document.all['img_'+topMenuId+''+nextInt].src = topNav1.src;//"images/topnav-1.gif";
	}
	if(document.all['img_'+prevInt+''+topMenuId])
		document.all['img_'+prevInt+''+topMenuId].src = topNav1.src;//"images/topnav-1.gif";		
	el.className = "topNavOff";
	curTopMenu = null;
}
function clickMenuItem(clickedID)
{
	menuElemWasClicked = true;
}
function clickBotMenuItem(clickedID)
{
	menuElemWasClicked = true;
}
function CheckEmail(val,args)
{
	var sEmail = args.Value;
	args.IsValid = sEmail.match(/^[\w_\.=-]+@[\w-]+(\.[\w-]+)+$/);
}

var aDeletedOptions = new Array();
var curCountry = 0;
function ValidateState(val,args)
{
	var country = args.Value;
	if(country != curCountry)
	{
		var pos = 1;
		for(var i = aDeletedOptions.length-1 ;i >=0;i--)
		{
			if(aDeletedOptions[i].value < 53)
			{
				document.all['_ctl3:_ctl0:ddlState'].options.add(aDeletedOptions[i],pos);
			}else
			{
				document.all['_ctl3:_ctl0:ddlState'].options.add(aDeletedOptions[i]);
			}
			pos++;
		}
		aDeletedOptions = new Array();
	}
	
	if(country == 225)
	{
		for(var i=document.all['_ctl3:_ctl0:ddlState'].options.length - 1; i >=0;i--)
		{
			if(document.all['_ctl3:_ctl0:ddlState'].options[i].value > 53)
			{
				aDeletedOptions[aDeletedOptions.length] = document.all['_ctl3:_ctl0:ddlState'].options[i];
				document.all['_ctl3:_ctl0:ddlState'].options.remove(i);
			}
		}
		if(document.all['_ctl3:_ctl0:ddlState'].selectedIndex == 0){
			document.all['_ctl3__ctl0_CustomValidatorState'].style.visibility = "visible";
			args.IsValid=false;
		}
	}
	else if (country == 38)
	{
		for(var i=document.all['_ctl3:_ctl0:ddlState'].options.length - 1; i >=0;i--)
		{
			if(document.all['_ctl3:_ctl0:ddlState'].options[i].value < 53)
			{
				aDeletedOptions[aDeletedOptions.length] = document.all['_ctl3:_ctl0:ddlState'].options[i];
				document.all['_ctl3:_ctl0:ddlState'].options.remove(i);
			}
		}	
		
		if(document.all['_ctl3:_ctl0:ddlState'].selectedIndex == 0){
			document.all['_ctl3__ctl0_CustomValidatorState'].style.visibility = "visible";
			args.IsValid=false;
		}
	}
	else
	{
		document.all['_ctl3:_ctl0:ddlState'].selectedIndex = 0;
		document.all['_ctl3__ctl0_CustomValidatorState'].style.visibility = "hidden";
		args.IsValid=true;
	}
	curCountry = country;
}
function ValidateCountry(control, selectedStateIndex)
{
	if(control.options[selectedStateIndex].value < 53)
	{
		document.all['_ctl3__ctl0_ddlCountry'].selectedIndex = document.all['USAIndex'].value;
		document.all['_ctl3__ctl0_RequiredFieldValidatorCountry'].style.visibility = "hidden";
	}
	else if(control.options[selectedStateIndex].value > 53)
	{
		document.all['_ctl3__ctl0_ddlCountry'].selectedIndex = document.all['CanadaIndex'].value;
		document.all['_ctl3__ctl0_RequiredFieldValidatorCountry'].style.visibility = "hidden";
	}
	if(control.options[selectedStateIndex].value != 53)	
	{
		document.all['_ctl3__ctl0_CustomValidatorState'].style.visibility = "hidden";
	}
	else
	{
		document.all['_ctl3__ctl0_CustomValidatorState'].style.visibility = "visible";
	}
}
