var b_version=navigator.appVersion;
var isIE6 = b_version.search(/MSIE 6/i) != -1;
var isIE7 = b_version.search(/MSIE 7/i) != -1;
var isSafari = b_version.search(/applewebkit/i) != -1;
var first = true;
var dropdownBuild = true;
var tabRido = document.getElementsByName('tabview');
var frameWidth = 180;
var frameHeight = 360;
var iframeCode = '';
var uidsid = '/'+uid+'/'+sid;
TemplatCode = TemplatCode.toLowerCase();
logDebug("TemplatCode," + TemplatCode);
function changeIframeCode(url) {
    $("iframecode").value = iframeCode;
    var cur =$("iframecode").value.split('src="');
    var temString = '';
    temString = cur[0]+'src="'+url+'"></iframe>';
    var newurl = temString;
    $("iframecode").value = newurl;
	window.frames["schmapEmbeded"].schmapplet.customizePage = '/templates/customize_sports.html';
	if( first){
	 updateRadios();
	 first = false;	
	 if(window.frames["schmapEmbeded"].showTwoMenus[1] != 1){
		  var navPath = ['', uid,
          window.frames["schmapEmbeded"].settings.MiniMenu2OverrideName].join('/');
	      window.frames["schmapEmbeded"].loadNavInfo(navPath);
	}
	}

}

function setup(){
if(placementImg !== ''){
	hideElement('choosTeam');
	hideElement('teamSelect');
	var imghtml = '';
	if(isIE6){
	imghtml = '<img class="chooseCitymap citymapforie" src="/images/widgetjsp/'+placementImg+'" />';
	}
	$('Title').innerHTML =imghtml +  '<img class="chooseCitymap" src="/images/widgetjsp/'+placementImg+'" />';
   $('Title').style.visibility = 'visible';
}else {
   $('Title').style.visibility = 'visible';
}
   $('Title').style.visibility = 'visible';
if(showCaseList!==''){
	var showCase = showCaseList.split(',');
	var linkInner = ['','',''];
	for(i=0;i<showCase.length;i++){
	var j =i%3;
	var linka = '<a href="http://'+showCase[i]+'" target="_blank" rel="nofollow">'+showCase[i]+'</a><br/>';
	linkInner[j] += linka;
	}
	for(i=0;i<linkInner.length;i++){
	$('show'+i).innerHTML = linkInner[i];
	}
}else{
	if(isSafari) {
       $('showCase').innerHTML = '<span style="color:white; visibility:hidden;height:0px;"></span>';
     // $('showCase').style.margin = '0px';
	  $('showCase').style.padding = '0 27px 0';
	}else
      hideElement('showCase');
}
if(TemplatCode.substr(0,1) =='s'){
var mapType = 's'
}else{
var mapType = 'g'
}
if(parami!==''){        
	parami = '&sit=' + parami;
}
if(paramt!==''){
        if (paramt=='schedule'){
            paramt = '&tab=article';
        }
        else{
	    paramt = '&tab=' + paramt;
	}
}
else{
        paramt = '&tab=map';
}
$('firLev-left').style.visibility = 'visible';
var rigH = getElementDimensions('firLev-right').h;
if(placementImg !== '' && getElementDimensions($('Title').firstChild).h < 100 ) {
	 if(isIE6 || isIE7) {
	     var leftH = getElementDimensions('firLev-left').h +101;
	 } else {
	     var leftH = getElementDimensions('firLev-left').h +101+34;
	 }
    
}  else {
	if(isIE6 || isIE7) {
       var leftH = getElementDimensions('firLev-left').h +17;
	} else {
	   var leftH = getElementDimensions('firLev-left').h+34;
	}
}
if(rigH >leftH) 
      setElementDimensions('firLev-embeded',{h:rigH});
else {
     setElementDimensions('firLev-embeded',{h:leftH });
     setElementDimensions('firLev-right',{h:leftH});
}
     
 iframeCode ='<iframe id="schmapplet" name="schmapEmbeded" frameborder="0" scrolling="no" marginwidth="0" marginheight="0" allowTransparency="true" style="border-style:none; border-width:0px;" width=180 height=360 src="/templates/'+TemplatCode+mapType+'.html?uid='+uid+'&sid='+sid+'&ultranarrow=true'+parami+'#mapview=Map'+paramt+'&applycolors=yes&topleft=undefined&bottomright=undefined&c='+colorString+'"></iframe>';
$('iframeC').innerHTML = iframeCode;
iframeCode = iframeCode.replace(' name="schmapEmbeded"','');
var temStr = iframeCode
$('iframecode').value = temStr;
$('widthinput').value = frameWidth;
$('heightinput').value = frameHeight;
$('gotcustomize').style.visibility="visible";
map(function(ele){
         connect(ele,'onclick',changeTab);
   },tabRido);
connect('widthinput','onchange',changeWidth);
connect('heightinput','onchange',changeHeight);
connect('gotcustomize','onclick',goCustomize);
showElement('showcaseText');
}

function goCustomize(){
 window.frames["schmapEmbeded"].clickHere();
}

function changeTab(){
  var thisOrder = window.frames["schmapEmbeded"].schmapplet.tabOrder;
  window.frames["schmapEmbeded"].changeViewByOrder(thisOrder,this.value);
}

function changeWidth(){
     var old = 'width='+frameWidth;
     var newv = 'width='+this.value;
        
     $("iframecode").value =$("iframecode").value.replace(old,newv);
	 frameWidth = this.value;
	 window.frames["schmapEmbeded"].schmapplet.frameWidth = frameWidth;
}
function changeHeight(){
     var old = 'height='+frameHeight;
	 var newv = 'height='+this.value;
     $("iframecode").value =$("iframecode").value.replace(old,newv);
	 frameHeight = this.value;
	 window.frames["schmapEmbeded"].schmapplet.frameHeight = frameHeight;
}
function updateRadios(){
    var tabs = window.frames["schmapEmbeded"].tabs;
	var thisOrder = window.frames["schmapEmbeded"].schmapplet.tabOrder;
	for(i=0;i<tabs.length;i++){
	    if(tabs[i].tabType == 'htmltitle1'){
		   tabRido[2].disabled = false; 
		}
    } 
	tabRido[thisOrder].checked=true; 
	}
function buildDropDown(navMenu,ssid){
    if(!dropdownBuild && uidsid.search(ssid) !=-1){
	 return;
	}
	var uidsida = '/'+uid+'/'+ssid;
	$('teamSelect').innerHTML = '';
	var alpha = [];
    var team = navMenu.bigMenus;
	for(i=0; i<team.length; i++){
	    var teamk = team[i].midMenus
	    for(k=0; k<teamk.length; k++){
		    var teamj = teamk[k].smallMenus;
			for(j=0; j<teamj.length; j++){
			        var teamjj = teamj[j];
			    	var op = OPTION({'value' : teamjj.link},teamjj.text);
	                op.currentLink = teamjj.link;
					op.text = teamjj.text;
					alpha.push(op);
					//if(op.currentLink.search(ssid)!==-1)
					if(op.currentLink ==uidsida){
					op.selected = true;
					}
				    if(teamjj.schmapmap !=='' 
					    && teamjj.schmapmap !=='null'){
				        var schmapmap = teamjj.schmapmap;
				     }else{
				     	var schmapmap = '';
				   	}
				 	op.schmapmap = schmapmap;
					op.template = teamjj.template;
			}
		}
	}
	if(seoVar5 == 'alpha'){
		alpha.sort(function(x,y){
					    var tmp = [x.text, y.text];
						tmp.sort();
						if (tmp[0] == x.text) {
						    if (tmp[1] == x.text) return 0;
						    return -1;
							}
							return 1;
					  	})
	}
	for(i=0;i<alpha.length;i++){
		appendChildNodes('teamSelect',alpha[i]);
	}
	disconnect('teamSelect','onchange',loadNewSchmapplets);
	connect('teamSelect','onchange',loadNewSchmapplets);
	dropdownBuild = false;
}	

function loadNewSchmapplets(){
    var newXml = this.value + '/places.xml';
	var tcode = this.template;
	var frame = window.frames["schmapEmbeded"];
	uidsid=this.value;
    if(frame) {
        if(frame.loadNewPlaces) {
		   if(frame.schmapplet.map.provider === "s") {
		            logDebug(this.currentLink);
                    frame.loadSchmapMapData(this.value,newXml,tcode);
                }else
                frame.loadNewPlaces(newXml,tcode);
           }
    }
}

function selectMe(thisTag){
    thisTag.firstChild.selected = true;
	changeTab.apply(thisTag.firstChild);

}
