function expandUserZipForm(templateId){
	var dummyLink = $$('input.expandUserZipFormDummyButton'+templateId)[0];
	calculatePosition(templateId);
	dummyLink.click();
}

function expandUserZipFormDirect(templateId){
	//updateUserLocationLinkCSS#{userLocationTemplateId}
	//showUserLocationLinkCSS#{userLocationTemplateId}
	
	var dummyLink = $$('a.showUserLocationLinkCSS'+templateId);
	try{
		dummyLink = dummyLink[0];
		if(dummyLink == null){
			dummyLink = $$('a.updateUserLocationLinkCSS'+templateId);
			dummyLink = dummyLink[0];
		}
	}catch(e){
		
	}
	
	if(dummyLink != null)
		dummyLink.click();
}
function collapseUserZipForm(templateId){
	var dummyLink = $$('input.collapseUserZipFormDummyButton'+templateId)[0];
	dummyLink.click();
}

function decideToCollapseUserZipForm(templateId,val,callbackFunction,argList,actionCssSelector){
	try{
		templateId = templateId || "";
		var selectedLocationValue =  $$('input.userLocationInputCSS')[0].value;
		var zipSuccessfullySavedHidden = $$('input.zipSuccessfullySavedHidden'+templateId)[0];
		var zipSuccessfullySavedHiddenValue = false;
		if(zipSuccessfullySavedHidden != null){
			zipSuccessfullySavedHiddenValue = zipSuccessfullySavedHidden.value;
		}
		if(zipSuccessfullySavedHiddenValue == 'true'){
			closeLocationWidget(templateId);
			
			if(callbackFunction != null && callbackFunction != ""){
				if(argList){
					eval(callbackFunction+"("+argList+")");
				}else{
					eval(callbackFunction+"('"+selectedLocationValue+"')");
				}
			}else if(actionCssSelector != null && actionCssSelector != ""){
				$$("."+actionCssSelector)[0].click();
			}
			
			if(selectedLocationValue != null && selectedLocationValue != ""){
				var locationPanels = $$('.yourLocationZipcodePanel');
				if(locationPanels != null){
					for(var i=0;i < locationPanels.length;i++){
						//locationPanels[i].innerHTML = "Location: "+selectedLocationValue;
						locationPanels[i].style.display = "inline";
						//new Effect.Highlight(locationPanels[i], { startcolor: '#ffff99',endcolor: '#fffffff' });
					}
				}

				
				var updateUserLocationLinks = $$(".showUserLocationLinkCSS");
				if(updateUserLocationLinks != null){
					for(var i=0;i < updateUserLocationLinks.length;i++){
						updateUserLocationLinks[i].innerHTML = "<span>"+selectedLocationValue+"<em>Change</em></span>";
						//new Effect.Highlight(updateUserLocationLinks[i], { startcolor: '#ffff99',endcolor: '#fffffff' });
						updateUserLocationLinks[i].addClassName('btnPurpleHoriz');
						updateUserLocationLinks[i].removeClassName('btnGrayHoriz');
					}
				}
			}
			
			
			//var yourLocationPanel = $$('span.yourLocationPanel')[0];
			
			
		}
	}catch(e){
		//alert(e);
	}
}

function checkZipcodeData(obj){
	var selectedValue = obj.value;
	var indexOfNumber = selectedValue.search(/\d/);
	if(indexOfNumber > -1){
		return false;
	}
}

function testCallBack(x,y,z){
	alert("x--"+x+"---y"+y+"---z--"+z);
}



function calculatePosition(templateId,referenceWidthId){
	referenceWidthId = referenceWidthId || "header";
	var userLocationLinks = $$("a.showUserLocationLinkCSS"+templateId);
	if(!userLocationLinks || userLocationLinks.length == 0){
		userLocationLinks = $$("a.updateUserLocationLinkCSS"+templateId);
	}

	if(userLocationLinks){
		var anchor = userLocationLinks[0];
		var referenceWidthDiv = $(referenceWidthId);
		var containerWidth = referenceWidthDiv.getWidth();
		var offset = referenceWidthDiv.cumulativeOffset().left;
		var containerRightEnd = offset + containerWidth;
		var anchorLeft = anchor.cumulativeOffset().left;
		var popupRight = anchorLeft + 390; //add width of popup
		var difference = 0;
		if(popupRight > containerRightEnd){
			difference =  containerRightEnd - popupRight;
			var  locationContainerRichPanel = $$('.locationContainerRichPanel'+templateId)[0];
			locationContainerRichPanel.style.position = "absolute";
			locationContainerRichPanel.style.left = difference+"px";
		}
		
		
	}
	return false;
}

function closeLocationWidget(){
	new Effect.Fade($('setLocation'),{duration:0.5});
}

function showHideNeedVisaDropDown(){
	var wantToStudyUsDropdown = $$('select.wantToStudyUSDropdownCSS')[0];
	var needVisaDropDownContainer = $$('div.needVisaDropdownContainerCSS')[0];
	var wantToStudyUSValue = wantToStudyUsDropdown.options[wantToStudyUsDropdown.selectedIndex].value;
	if(wantToStudyUSValue == "true"){
		needVisaDropDownContainer.style.display = "block";
	}else{
		needVisaDropDownContainer.style.display = "none";
	}
}