function placeShopInfos(divId,contId,guideImgId, offsetY){
	var didDim = Element.getDimensions(divId)
	var divWidth = didDim.width
	
	var contDim = Element.getDimensions(contId)
	var contWidth = contDim.width

	var guideImgPos = Position.cumulativeOffset($(guideImgId))
	var guideImgX = guideImgPos[0]
	var guideImgY = guideImgPos[1]

	$(divId).style.left = Math.round(guideImgX + contWidth/2 - divWidth/2)
	$(divId).style.top = guideImgY + offsetY
}

/****/

var country = "";
var city = "";
var master;
var category;

function XOption(par,name,id){
	this.par = par;
	if(par)
	{
		this.depth=par.depth+1;
	}
	else
		this.depth=0;
	this.maxdepth=0;
	if(name)
		this.name=name;
	else 
		this.name="\\";
	if(id)
		this.id=id;
	else 
		this.id="\\";
	this.children = new Array();
	this.addChild=addChild;
	this.incDepth=incDepth;
}

function addChild(name,id){
	var child = new XOption(this,name,id);
	this.children[this.children.length] = child;
	this.incDepth(child);
	return child;
}

function incDepth(child){
	this.maxdepth = Math.max(this.maxdepth,child.depth-this.depth);
	if(this.par)
		this.par.incDepth(child);
}

function makePopup(id,title,count,change){
	var onchange="\\";
	if (change!="\\") 
		onchange=" onchange='" + change + "'";
	document.writeln("<select name='Xpop_" + id + "' size='1'" + onchange + ">");
	document.writeln("<option value=''>" + title + "</option>");
	for(var i=1;i<count;i++)
		document.writeln("<option value=''></option>");
		document.writeln("</select>");
}

function getOption(changed){
	var n = 0;
	var list = null;
	var option = master;
	while(true)
	{					
		list = getList(changed.form,n);
		if(!list) return null;
		option = option.children[list.selectedIndex];
		if(list==changed) break;
		n++;
	}
	return option;
}

function selectLeaf(id){
	if(id){};
}

function Xpop(list){
	var option = getOption(list);
	if(option)
	{
		var next = getNextList(list);
		if(next) setPopup(next,option);
		selectLeaf(option.id);
	}
}

function getListDepth(list){
	var pos = list.name.indexOf("_");
	return parseInt(list.name.substring(pos+1));
}

function getNextList(list){
	var num =  getListDepth(list);
	return getList(list,num+1);
}

function setPopup(list,option){	
	list.options.length=0;
	
	for(var i=0;i<option.children.length;i++)
	{
		list.options[list.options.length] = new Option(option.children[i].name,"\\"+option.children[i].id);
	}
	list.selectedIndex=0;
	var pos = list.name.indexOf("_");
	var num =  getListDepth(list);
	var next = getNextList(list);
	if(next)
	{
		if(option.children.length>0) setPopup(next,option.children[0]);
	}
}

function getList(form,depth){	
var form = GetMainFormName();
	return eval("document."+form+".Xpop_" + depth);
}

function initPopups(formName){
	var form = GetMainFormName();				
	if(form)
	{
		var first = getList(form,0);
		copyTab();					
		if(first) setPopup(first,master);
		
		if ( country.length != 0)
		{
			for (var i=0; i<master.children.length; i++)
			{
				if (master.children[i].name == country)
				{
					form.Xpop_0.selectedIndex=i;
					var optionTest = getOption(form.Xpop_0);
					Xpop(form.Xpop_0);
					break;
				}
			}
			
			for (var i=0;i<form.Xpop_1.options.length;i++)
			{
				if(optionTest.children[i].name==city)
				{
					
					form.Xpop_1.selectedIndex=i;
					break;
				}
			}
		}
	}
}

function copyTab(){
	for (var i=0; i<master2.children.length; i++){
		optionlist = master2.children[i];
		if (optionlist.children.length != 0){
			category = master.addChild(master2.children[i].name,master2.children[i].id);
			
			for(var j = 0; j < master2.children[i].children.length; j++){
				category.addChild(master2.children[i].children[j].name,master2.children[i].children[j].id);
			}
		}
	}
}

function showResults(){	
	var mf = GetMainFormName();
	var selectid1 = document.forms[mf].Xpop_0.selectedIndex;
	var selectid2 = document.forms[mf].Xpop_1.selectedIndex;
	var prefCode = master.children[selectid1].id;
	var areaCode = master.children[selectid1].children[selectid2].id;				
	
	var url = "result.aspx?prefcode=" + prefCode + "&areacode=" + areaCode;
	$("resultIframe").src = url
}

master = new XOption();
master2 = new XOption();

/****/

function writeZipCode(zipcode){
	zippart1 = zipcode.slice(0,3);
	zippart2 = zipcode.slice(3,7);
	document.write(zippart1 + '-' + zippart2);
}
