function openWin(url,n,w,h) {
	window.open(url,n,'width='+w+',height='+h+',location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes');
}

function addJs() {
	if (arguments.length>0) files=arguments;
	if (typeof files!="undefined"){
		for(var i=0;i<files.length;i++){
			document.writeln("<script src='/js/"+files[i]+".js' type='text/javascript'></script>");
		}
	}
}

// additional scripts
addJs("cookies","validation");

function createXMLHttpRequest() {
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   try { return new XMLHttpRequest(); } catch(e) {}
   alert("XMLHttpRequest not supported");
   return null;
 }

function Write_If_loggedin(passed_Str) {
	if (getCookie2("username")!=""){
    	document.write (passed_Str);
	}
}


function Write_Ifnot_loggedin(passed_Str){
    if (getCookie2("username")=="") {
        document.write (passed_Str); 
    }
}

function Write_Ifnot_excededTradelimit(passed_Str) {
try{
  if ( global_js_remainingtrades<=0 )  document.write (passed_Str);
  }catch(err){}
}

function TradelimitNotExceeded() {
try{
  if ( global_js_remainingtrades<=0)  return true;
  else return false;
  }catch(err){}  
}

function Write_If_owner(passed_Str,ownerid) {
    if (getCookie2("userid")==ownerid){
        document.write (passed_Str);
    }
}

// Get Query String Param value 
function PageQuery(q) {
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	if(q) {
	for(var i=0; i < this.q.split("&").length; i++) {
	this.keyValuePairs[i] = this.q.split("&")[i];
	}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
	for(var j=0; j < this.keyValuePairs.length; j++) {
	if(this.keyValuePairs[j].split("=")[0] == s)
	return this.keyValuePairs[j].split("=")[1];
	}
	return false;
	}
	this.getParameters = function() {
	var a = new Array(this.getLength());
	
	for(var j=0; j < this.keyValuePairs.length; j++) {
	a[j] = this.keyValuePairs[j].split("=")[0];
	}
	return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; } 
}

function queryString(key){
	var page = new PageQuery(window.location.search); 
	return unescape(page.getValue(key)); 
}

function getQsParam(paramname){
	if(queryString(paramname)=='false') {
	   return null;
	} else {
		return queryString(paramname);
	}
}

function loadUserModule() {										    					
js_username = getCookie2("username");						
js_temp_str = "";						
	if(js_username != "") {						
		    js_temp_str += '<div class="col_w33">Welcome </div>';
		    js_temp_str += '<div class="col_w66"><em>'+js_username+'</em> <span class="xsm">(<a href="/user/logout.asp">logout</a>)</span></div>';
		    js_temp_str += '<div class="clear"></div>';
	}
	else{		
			js_temp_str += '<form name="Login" id="LoginForm" onsubmit="return validateLogin()" action="/user/bin/user_login.asp" method="post" >';
	        js_temp_str += '<div class="Field sm">';
		    js_temp_str += '<strong>username</strong>:<br />';
		    js_temp_str += '<input type="text" size="20" name="username" id="login_username" value="" class="light" />';
	        js_temp_str += '</div>';
	        js_temp_str += '<div class="Field sm">';
		    js_temp_str += '<strong>password</strong>:<br/>';
		    js_temp_str += '<input type="password" size="20" name="password" id="login_password" value="" onKeyPress="return submitenter_validateLogin(this,event)" class="light" />';
	        js_temp_str += '</div>';
	        js_temp_str += '</form>';
            js_temp_str += '<div class="Field sm">';
		    js_temp_str += '&nbsp;<input type="button" class="button" name="submit" value="Login &#187;"  onClick="validateLogin()"/> &nbsp;&nbsp;OR&nbsp;<em><a href="/user/register.asp" class="button">Join &#187;</a></em>';
	        js_temp_str += '</div>';
	        js_temp_str += '<div class="xsm" align="right"><a href="/user/forgot_password.asp">forgot password?</a>&nbsp;</div>';  
      	}	
     document.getElementById("dynamic_left").innerHTML = js_temp_str;
          
	//js_cur_team = getQsParam("teamId");		
	//js_cur_team = getCookie2("curteam");
						
	if(js_username != "") {
	    js_totalteams = getCookie2("teamcount");							    
	    js_temp_str = "";
		js_cur_team = getCookie2("curteam");	
																
		cur_team_style = 0;
		if (js_totalteams==0){					    
    	    js_temp_str = '<br />&nbsp;<a href="/leagues/create.asp">Start a league &#187;</a>';
            js_temp_str +='<br />&nbsp;<a href="/leagues/browse.asp">Join a league &#187;</a>';
		}
        else{                		 	
			for (var x = 1; x <= js_totalteams; x++){                		        
            	arr_vars = getCookie2("team%5F"+x).split("&");                		        
            	    for (var y = 0; y <= 5; y++){                		        
            	    if (arr_vars[y].split("=")[0]=="league") js_league  = arr_vars[y].split("=")[1].replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ");
            	    if (arr_vars[y].split("=")[0]=="name") js_teamname  = arr_vars[y].split("=")[1].replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ");
            	    if (arr_vars[y].split("=")[0]=="icon") js_teamicon  = arr_vars[y].split("=")[1].replace("+"," ").replace("+"," ").replace("+"," ");
            	    if (arr_vars[y].split("=")[0]=="id") js_teamid      = arr_vars[y].split("=")[1].replace("+"," ").replace("+"," ").replace("+"," ");
					if (arr_vars[y].split("=")[0]=="leagueid") js_leagueid = arr_vars[y].split("=")[1].replace("+"," ").replace("+"," ").replace("+"," ");
					if (arr_vars[y].split("=")[0]=="RemainingTrades") js_remainingtrades = arr_vars[y].split("=")[1];
					}    
			   if(js_cur_team=="" && x==1) {			            
				    CreateCookie("curteam", js_teamid, 0); //debug
					//js_cur_team = getCookie2("curteam");
					js_cur_team=js_teamid; //temp hack
					document.location = '/teams/view.asp?teamId='+js_teamid;
			   }			  
			  cur_team_style = 0;
			  if(js_cur_team==js_teamid) {			  
			        cur_team_style = "current_team"; 
			        global_js_remainingtrades =js_remainingtrades;
			        global_js_teamname = js_teamname;
			        global_js_remainingtrades = (js_remainingtrades/2);			        
			  }
			   js_temp_str +='<div class="nav_team '+cur_team_style+'"><img src="/imgs/icons/teams/'+js_teamicon+'" class="nav_icon" align="left"/><a href="/teams/view.asp?teamId='+js_teamid+'" class="team_name" onclick="CreateCookie(\'curteam\','+js_teamid+', 0)"><strong>'+js_teamname+'</strong></a><br />';
		       js_temp_str +='<a href="/leagues/view.asp?leagueid='+js_leagueid+'" class="team_name" onclick="CreateCookie(\'curteam\','+js_teamid+', 0)">'+js_league+'</a></div>';                		        
            }
			js_temp_str +='<div class="my_picks"><a href="/mls_survivor/my_picks.asp">My Survivor Picks</a></div>';
			 js_temp_str +='<div class="watch_list"><a href="/players/my_list.asp?teamId='+ js_cur_team +'">My Player Watch List</a></div>';
            		 
	    }                   		
		document.getElementById("dynamic_left").innerHTML+=js_temp_str;
	}	
}	