// JavaScript Document
/*var menuids=["treemenu1"] //Enter id(s) of SuckerTree UL menus, separated by commas
	
if (window.addEventListener)
	window.addEventListener("load", buildsubmenus_horizontal, false)
else if (window.attachEvent)
	window.attachEvent("onload", buildsubmenus_horizontal)
		*/
function buildsubmenus_horizontal(){ 
for (var i=0; i<menuids.length; i++){
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
		if (ultags[t].parentNode.parentNode.id==menuids[i]){ //if this is a first level submenu
			ultags[t].style.top=ultags[t].parentNode.offsetHeight+"px" //dynamically position first level submenus to be height of main menu item
			ultags[t].parentNode.getElementsByTagName("a")[0].className="mainfoldericon"
		}
		else{ //else if this is a sub level menu (ul)
		  ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
    	ultags[t].parentNode.getElementsByTagName("a")[0].className="subfoldericon"
		}
    ultags[t].parentNode.onmouseover=function(){
    this.getElementsByTagName("ul")[0].style.visibility="visible"
	if(this.getElementsByTagName("ul")[0].id=='subMenu')
	showHideZoneBox('hide')
    }
    ultags[t].parentNode.onmouseout=function(){
    this.getElementsByTagName("ul")[0].style.visibility="hidden"
	if(this.getElementsByTagName("ul")[0].id=='subMenu')
	showHideZoneBox('show')
    }
    }
  }
}

function showHideZoneBox(opt)
{
	
	if(document.RatingForm.memberRatingId.value !=0 && document.getElementById("zoneBox")!=null)
	{
			if(opt=='show')
				document.getElementById("zoneBox").style.display='inline';
			else if(opt=='hide')
				document.getElementById("zoneBox").style.display='none';
	}
}


function headerfunction(prefValue)
{
	document.headermenu.headerPref.value=prefValue;
	document.headermenu.headerSubPref.value="";
	document.headermenu.submit();
}

function subHeaderFunction(prefValue, subPrefValue)
{
	document.headermenu.headerPref.value=prefValue;
	document.headermenu.headerSubPref.value=subPrefValue;	
	document.headermenu.submit();
}

function MyRatingView(memberRatingId,clickType)
{
	document.RatingForm.memberRatingId.value = memberRatingId;
	document.RatingForm.clickType.value = clickType;
	document.RatingForm.submit();
}

function submitQuickSearch()
{
	if(document.quickSearch.searchText.value=="" || document.quickSearch.searchText.value=="Search in this zone" )
	{
		alert("Please enter your search keywords");
		return false;
	}
	else if(document.quickSearch.zoneChannelCode.value=='!')
	{
		alert("Pleae choose Zone/Channel");
		return false;
	}
	else if(document.quickSearch.zoneChannelCode.value=='R')
	{
		if(document.quickSearch.validMember.value=="")
		{
			document.quickSearch.searchType.value="quick";
			document.quickSearch.submit();
			return true;
		}
		else if(document.quickSearch.validMember.value=="nolistings")
		{
			alert("You currently do not have any active job listings posted on Adsglobe.com. This feature is available to only employers who have posted active listings.");
		}
		else if(document.quickSearch.validMember.value=="notmember")
		{
			alert("You have to be member of Adsglobe.com and should have active job listings to search resumes.");
		}
	}
	else
	{
		document.quickSearch.searchType.value="quick";
		document.quickSearch.submit();
		return true;
	}
}

function submitZoneSpec(searchType)
{
	if(document.zoneform.zoneChannelCode.value=='!')
	{
		alert("Please select the zone");
	}
	else
	{
		document.zoneform.searchType.value=searchType;
		document.zoneform.submit();
	}
}

function submitAdvanceSearch()
{
	if(document.quickSearch.zoneChannelCode.value=='!')
	{
		alert("Pleae choose Zone/Channel");
	}
	else
	{
		document.quickSearch.searchType.value="advance";
		document.quickSearch.submit();
	}
}
function memberSearch(memberId, zoneChannelCode)
{	
	document.quickSearch.searchType.value="memberSearch";
	document.quickSearch.zoneChannelCode.value = zoneChannelCode;
	document.quickSearch.memberId.value = memberId;
	document.quickSearch.submit();
}
function memberTopFormSubmit(typeClick)
{	
	if(typeClick == 'Cancel')
	{
		if(confirm("Do you want to cancel ?"))
		{
			document.memberTopForm.clickType.value = typeClick;			
			document.memberTopForm.submit();
		}
	}
	else
	{
		document.memberTopForm.clickType.value = typeClick;		
		document.memberTopForm.submit();
	}
}

function submitEventSummary(choiceType)
{
	document.postingsSummaryForm.buttonType.value=choiceType;
	document.postingsSummaryForm.submit();	
}

function submitBusinessSummary(choiceType)
{
	document.businessSummaryForm.buttonType.value=choiceType;
	document.businessSummaryForm.submit();	
}

function submitAutoSummary(choiceType)
{
	document.postSummaryForm.buttonType.value=choiceType;
	document.postSummaryForm.submit();
}

function submitFlyerBoardSummary(choiceType)
{
	document.flyerBoardSummaryForm.buttonType.value=choiceType;
	document.flyerBoardSummaryForm.submit();
}

function submitVideoAdsSummary(choiceType)
{
	document.videoAdsSummaryForm.buttonType.value=choiceType;
	document.videoAdsSummaryForm.submit();
}

function submitCouponSummary(choiceType)
{
	document.couponSummaryForm.buttonType.value=choiceType;
	document.couponSummaryForm.submit();
}

function submitMerchandiseSummary(choiceType,adChannelCode,adTypeCode)
{
	document.postSummaryForm.buttonType.value=choiceType;
	document.postSummaryForm.adChannelCode.value=adChannelCode;
	document.postSummaryForm.adTypeCode.value=adTypeCode;
	document.postSummaryForm.submit();
}
function submitAdsCommonLoginCheck(choiceType)
{
	document.adsCommonForm.buttonType.value=choiceType;
	document.adsCommonForm.submit();
}

var path="";

function setCountry(selectedValue,pt,targetDiv)
{
	
	var requestParameters = null;
	
	if(path!="")
		path =pt;
	var url = path+"/DefaultCountryServlet";
	requestParameters = "selectedValue=" + selectedValue;
	
	var ajax = new Ajax.Request(
	url, {
	method: "post",
	parameters: requestParameters,
	onFailure: reportAjaxError,
	onSuccess: function(request) {
	var obj = eval('(' + ajax.transport.responseText + ')');
	Element.remove($(userCountry).getElementsByTagName("SELECT")[0]);
	
	Element.update(userCountry, obj.resultData);
	
	}
	});
}
function reportAjaxError() 
{
  alert("Cannot retrieve dependent options")
}
function setCountryHeader(selectedValue,pt,targetDiv)
{
	document.headerForm.selectedValue.value=selectedValue;	
  	headerForm.submit();
}

function showCountry()
{

	if(document.getElementById("locationPage").style.display=='none')
	{
		document.getElementById("locationPage").style.display='inline';
		loadCountryList();
	}
	else
		document.getElementById("locationPage").style.display='none';
	

}

function loadCountryList()
{
	document.getElementById("ctryProcess").style.display='inline';
	
	var requestParameters = null;
	
	var url = "/looadCountries.ads";
	var ajax = new Ajax.Request(
	url, {
	method: "post",
	parameters: requestParameters,
	onFailure: reportAjaxError,
	onSuccess: function(request) {
	var obj = eval('(' + ajax.transport.responseText + ')');
	Element.update(countryList, obj.resultData);
	document.getElementById("ctryProcess").style.display='none';
	}
	});
}

//Change Location method Starts
var docHeight=0;
function showLocation(country,state,city)
{
	var requestParameters = null;
	
	var url = "/locationDisplay.ads";
	document.getElementById("locationData").innerHTML="";
	requestParameters = "country=" + country + "&state=" + state + "&city=" + city ;
	document.getElementById("locationLoadImage").style.visibility = 'visible';
	var ajax = new Ajax.Request(
	url, {
	method: "post",
	parameters: requestParameters,
	onFailure: reportAjaxError,
	onSuccess: function(request) {
	var obj = eval('(' + ajax.transport.responseText + ')');

	Element.update(locationData, obj.locationData);
	
	document.getElementById("locationLoadImage").style.visibility = 'hidden';
	}
	});
	
	if (document.all)
	{               
		document.body.scroll = "no";
	}
	else
	{
		var oTop = document.body.scrollTop;
		document.body.style.overflow = "hidden";
		document.body.scrollTop = oTop;
	}
	doClick();	
	document.getElementById('fade').style.height= docHeight;	
	document.getElementById('location_light').style.display='block';
	document.getElementById('fade').style.display='block';
}

function hideLocation()
{
	document.getElementById('location_light').style.display='none';
	document.getElementById('fade').style.display='none'
	document.body.scroll = "";
    document.body.style.overflow = "";
}

function doClick()
{
	var x;
	
	// for all except Explorer
	if (self.innerHeight) 
	{
		x = self.innerWidth;
		docHeight = x-10;	
	// Explorer 6 Strict Mode
	} 
	else if (document.documentElement && document.documentElement.clientHeight) 
	{
		x = document.documentElement.clientWidth;
		docHeight = x;	
	// other Explorers
	} 
	else if (document.body) 
	{
		x = document.body.clientWidth;	
		docHeight = x;
	}
}

function loadHeadStates(selectBox, targetDiv, pt)
{	
	var requestParameters = null;
	path =pt;
	
	var url = path+"/HeadLocationLoaderServlet";
	var selectedValue = selectBox[selectBox.selectedIndex].value;
	
	requestParameters = "optionName=" + $(targetDiv).getElementsByTagName("SELECT")[0].name + "&selectedValue=" + selectedValue;
	
	dependHeadState.getElementsByTagName("SELECT")[0].disabled = true;
	dependHeadCity.getElementsByTagName("SELECT")[0].disabled = true;

	document.getElementById("headLocationImage").style.visibility = 'visible';
	var ajax = new Ajax.Request(
	url, {
	method: "post",
	parameters: requestParameters,
	onFailure: reportAjaxError,
	onSuccess: function(request) {
	var obj = eval('(' + ajax.transport.responseText + ')');

	Element.remove($(targetDiv).getElementsByTagName("SELECT")[0]);
	Element.update(targetDiv, obj.resultData);
	
	Element.update(headStateLabel,obj.stateLabel);
	Element.update(headCountryImage,obj.headCountryImage);
	Element.update(document.getElementById("dependHeadCity"),obj.cityData);
	
	document.getElementById("headLocationImage").style.visibility = 'hidden';
	}
	});
}
var path = "";
function loadHeadCities(selectBox, targetDiv,pt) 
{
	var country = dependHeadCountry.getElementsByTagName("SELECT")[0].value;
	
	if(path=="")
		path = pt;
	
	var requestParameters = null;
	
	var url = path+"/HeadLocationLoaderServlet";
	
	requestParameters = "countryName="+country+ "&optionName=" + $(targetDiv).getElementsByTagName("SELECT")[0].name + "&selectedValue=" + selectBox[selectBox.selectedIndex].value;
	dependHeadCity.getElementsByTagName("SELECT")[0].disabled = true;
	
	document.getElementById("headLocationImage").style.visibility = 'visible';
	dependHeadCity.getElementsByTagName("SELECT")[0].disabled = true;
	
	var ajax = new Ajax.Request(
	url, {
	method: "post",
	parameters: requestParameters,
	onFailure: reportAjaxError,
	onSuccess: function(request) {
	var obj = eval('(' + ajax.transport.responseText + ')');
	Element.remove($(targetDiv).getElementsByTagName("SELECT")[0]);
	Element.update(targetDiv, obj.resultData);
	
	document.getElementById("headLocationImage").style.visibility = 'hidden';
	
	}
	});
}

function locationSubmit()
{
	document.locationForm.submit();
}
//Change Location method Ends

function resumeSearch(prefValue)
{
	if(document.resumeSearchForm.validMember.value=="nolistings")
	{
		alert("You currently do not have any active job listings posted on Adsglobe.com. This feature is available to only employers who have posted active listings.");
	}
	else if(document.resumeSearchForm.validMember.value=="notmember")
	{
		alert("You have to be member of Adsglobe.com and should have active job listings to search resumes.");
	}
	else
	{
		document.headermenu.headerPref.value=prefValue;
		document.headermenu.headerSubPref.value="";
		document.headermenu.submit();
	}
}

function changeMemberLocation(country,state,city)
{
	document.changeMemberLocationForm.headCountry.value=country;
	document.changeMemberLocationForm.headState.value=state;
	document.changeMemberLocationForm.headCity.value=city;
	document.changeMemberLocationForm.submit();
}

function showForums(type)
{
	if(type=="national")
	{
		document.getElementById("cityForums").style.display="none";
		document.getElementById("nationalForums").style.display="inline";
		document.getElementById("nationalForumLabel").innerHTML="<strong>National Forums</strong>";
		document.getElementById("cityForumLabel").innerHTML="<a href=\"#nationalfrm\" onClick=\"javascript:showForums('city')\"><strong><u>City Forums</u></strong></a>";
	}
	else if(type=="city")
	{
		document.getElementById("nationalForums").style.display="none";
		document.getElementById("cityForums").style.display="inline";
		document.getElementById("cityForumLabel").innerHTML="<strong>City Forums</strong>";
		document.getElementById("nationalForumLabel").innerHTML="<a href=\"#nationalfrm\" onClick=\"javascript:showForums('national')\"><strong><u>National Forums</u></strong></a>";
	}
}



//Myhome related menu

var cX = 0; var cY = 0; var rX = 0; var rY = 0;
if(document.all) 
{ 
	document.onmousemove = UpdateCursorPositionDocAll; 
}
else
{ 
	document.onmousemove = UpdateCursorPosition; 
}

function HideMenu(id)
{
	document.getElementById(id).style.display = "none";
}

function ShowMenu(id)
{

	var d =document.getElementById(id);
	//var cnt = document.getElementById(id);
	//document.getElementById('content').innerHTML = cnt.innerHTML;
	d.style.display = "block";
	AssignPosition(d);
}

function UpdateCursorPosition(e)
{
	cX = e.pageX; cY = e.pageY;
}

function UpdateCursorPositionDocAll(e)
{
	cX = event.clientX; cY = event.clientY;
}

function AssignPosition(d) 
{
	/*if(self.pageYOffset)
	{
		rX = self.pageXOffset;
		rY = self.pageYOffset;
	}
	else if(document.documentElement && document.documentElement.scrollTop)
	{
		rX = document.documentElement.scrollLeft;
		rY = document.documentElement.scrollTop;
	}
	else if(document.body)
	{
		rX = document.body.scrollLeft;
		rY = document.body.scrollTop;
	}
	if(document.all)
	{
		cX += rX; 
		cY += rY;
	}
	
	d.style.left = (cX-20) + "px";
	d.style.top = (cY+5) + "px";	*/
	//alert(d.id);
	if(d.id=='myhome')
	{
		d.style.left = (890) + "px";
		d.style.top = (20) + "px";
	}
	else if(d.id=='postads')
	{
		d.style.left = (580) + "px";
		d.style.top = (74) + "px";
	}
	else if(d.id=='adzones')
	{
		d.style.left = (840) + "px";
		d.style.top = (74) + "px";
	}
	else if(d.id=='featuredads')
	{
		d.style.left = (700) + "px";
		d.style.top = (121) + "px";
	}
}

function submitPostFreeAd(zoneCode)
{
	document.postAdsForm.zoneChannelCode.value=zoneCode;
	document.postAdsForm.submit();
}

function submitPostFreeAdRealPostSummary(typeCode,buttonType)
{
	document.realEstateFreeAdPostSummaryForm.adTypeCode.value=typeCode;
	document.realEstateFreeAdPostSummaryForm.buttonType.value=buttonType;
	document.realEstateFreeAdPostSummaryForm.submit();
}
function submitPostFreeAdAutoPostSummary(typeCode,buttonType)
{
	document.autosFreeAdPostSummaryForm.adTypeCode.value=typeCode;
	document.autosFreeAdPostSummaryForm.buttonType.value=buttonType;
	document.autosFreeAdPostSummaryForm.submit();
}
function headerMemberLeftFormSubmit(typeClick)
{
	document.headerMemberLeftForm.clickType.value = typeClick;		
	document.headerMemberLeftForm.submit();
}
function headerMyRatingLeft(memberRatingId,clickType)
{
	document.headerRatingForm.memberRatingId.value = memberRatingId;
	document.headerRatingForm.clickType.value = clickType;
	document.headerRatingForm.submit();
}