function OpenPopup(subq) {
	var url = GetSiteUrl();
	url = url + "bannerads/user-type.asp";
	var height = 360;
	var width = 400;
	
	if (subq != ''){
		url = url + "?target=" + subq;
	}

	newwindow=window.open(url,'name','height='+height+',width='+width+'');
	if (window.focus) {newwindow.focus()}
	return false;
}

// Get Cookie value
function getCookie(c_name)
{
	if (document.cookie.length>0){
  		c_start=document.cookie.indexOf(c_name + "=");
  		if (c_start!=-1){ 
    		c_start=c_start + c_name.length+1; 
    		c_end=document.cookie.indexOf(";",c_start);
   	 		if (c_end==-1) c_end=document.cookie.length;
    		return unescape(document.cookie.substring(c_start,c_end));
    	} 
  	}
		return "";	
}

// Set cookie value
function setCookie(c_name,value,expiredays)
{
	var domain = ".wisdomtree.com";
	var path = "/"
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) + ( ( path ) ? ";path=" + path : "" ) +  ( ( domain ) ? ";domain=" + domain : "" );
}

function FlashGetCookie(){
	return getCookie('wttype');
}

function VerifyCkStatus(urlTo){
	//var exType = GetQueryString("xcld");	
	var exType =""
	if (urlTo.indexOf("&") != -1){
		var arrExPart = urlTo.split("&");
		arrExType = arrExPart[1].split("=");
		exType = arrExType[1];
	}
	if (exType == "indv"){	
		setCookie('wttype', '', -1);	
	}
	
	var ckValue = getCookie('wttype');

	if (ckValue == ""){	
		OpenPopup(urlTo);
	}else{	
		var url = GetSiteUrl();
		if (urlTo.indexOf("&") != -1){
			var arrUrlTo = urlTo.split("&");
			urlTo = arrUrlTo[0];
		}
		url = url + urlTo;
		location.href = url;
	}
}

function RedirectPageTo(subq){
	var urlToRedirect = "";	
	urlToRedirect = GetSiteUrl();
	if (subq == ''){
		urlToRedirect = urlToRedirect + "home.asp";
	}else{
		urlToRedirect = urlToRedirect + subq;
	}

	opener.window.location = urlToRedirect;
	self.close();
}

function GetSiteUrl(){
	var siteUrl = location.href;
	var arrSiteUrl = siteUrl.split("/");
	var siteDom = "http://" + arrSiteUrl[2] + "/";
	return siteDom;
}

function ShowMessage(){
	document.getElementById("msg").innerHTML = "Sorry, this content is only available to Financial Professionals.<div id='lnkclose'><a href='#' onclick='CloseWindow();'>[Close]</a></div>";	
}

function CloseWindow(){
	self.close();
}

function GetUrlPart(){
	var siteUrl = location.href, arrSiteUrl = siteUrl.split("/"),siteDom = "";
	for (i=3; i<arrSiteUrl.length; i++){
		if (i==(arrSiteUrl.length-1)) {siteDom += arrSiteUrl[i];}else{siteDom += arrSiteUrl[i]+"/";}
	}
	return siteDom;
}

function GetQueryString(key){
    var url = location.href,
    key = key.toLowerCase();
    val = "";
    var qString = "";

    if (url.indexOf("?") != -1){
        qString = url.split("?")[1];
    }

    if (qString != "" && key != ""){
        var arrQStringKeyValue = (qString.indexOf("&") != 1) ?  qString.split("&") : qString;
        if (arrQStringKeyValue.length > 1){
            for (i = 0; i < arrQStringKeyValue.length; i++){
                var temp = arrQStringKeyValue[i].toLowerCase();
                if (temp.indexOf(key) != -1){
                    if (arrQStringKeyValue[i].indexOf("=") != -1){
                        arrKeyVal = arrQStringKeyValue[i].split("=");
                        temp = arrKeyVal[0].toLowerCase();
                        val = (temp==key) ? arrKeyVal[1] : "";
                    }
                }
            }
        }else{
            var temp = arrQStringKeyValue[0].toLowerCase();
            if (temp.indexOf(key) != -1){
                if (arrQStringKeyValue[0].indexOf("=") != -1){
                    arrKeyVal = arrQStringKeyValue[0].split("=");
                    temp = arrKeyVal[0].toLowerCase();
                    val = (temp==key) ? arrKeyVal[1] : "";
                }
            }
        }
    }

    // Remove anything after #
    //val = (val.indexOf("#") != -1) ? val.split("#")[0] : val;
    return val;
}


