function getDomainName(url) {
	var surl = "" + url;
	var splits = surl.split("/");
	if(splits == null || splits.length <=1) {
		return surl;
	} else {
        var domainWithPort = splits[2];
        var colonPort = domainWithPort.indexOf(':');
        if(colonPort > 0) {
            var domainWithPortParsed = domainWithPort.split(":");
            return domainWithPortParsed[0];
        } else {
            return domainWithPort;
        }
	}
}

function checkMatch(reqDomain,refDomain) {
    
    if(refDomain==null || (refDomain!=null && refDomain=="") ) 	
    {
        return false;
    }
    
    if(reqDomain!=null && reqDomain!="" && refDomain!=null && refDomain!="")
    {
		
			if(reqDomain==refDomain)
			{
				return true;
			}
			else
				{
					if(reqDomain.match("secure"))
					{
						reqDomain=reqDomain.replace("secure","");
					}
					if(refDomain.match("secure"))
					{
						refDomain=refDomain.replace("secure","");
					}
					
					if(reqDomain==refDomain)
					{
                        return true;
					}
				}
    }
	return false;
}

var http_request;

function makeRequest(url) {
	alert("makeRequest");
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
		 
         if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
			
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      http_request.onreadystatechange = alertContents;
      http_request.open('GET', url, true);
      http_request.send(null);
}

function writePopUpHtml() {
	var ref = "";
	var isie = false;
	try {
	    ref = document.referrer;
		if (ref == "" || ref == null) {
			ref = window.opener.document.location;
		}
	} catch(exception) {
		var agent = navigator.userAgent;
		//alert(agent);
		if (agent.match("MSIE 6.0") != null || agent.match("MSIE 7.0") != null || agent.match("MSIE 8.0") != null) {
			isie = true;
		}
	}
	
    var reqURL = document.URL;
    
    filePath = decodeURIComponent(filePath);
	decL = decodeURIComponent(decL);

	if (!isie) {
		ref = getDomainName(reqURL);  //changed 2/23/2010 from ref to reqURL
	}
	reqURL=getDomainName(reqURL);
	
	if (filePath != 'null' && filePath != '') {
		if (isie) {
			writeDocument(decL);
		} else {
		    if(checkMatch(reqURL,ref)) {
				writeDocument(decL);
		    } else {
				var whiteList = whiteListData();
				for (var i = 0; i < whiteList.length; i++) {
					if (checkMatch(whiteList[i],ref)) {
						writeDocument(decL);
						break;
					}
				}
			}
		}
	}
}

function writeDocument(decL) {
    document.write('<div id="app_disclaimer_buttons">');
    document.write('<div id="app_disclaimer_accept">');
    document.write('<a href="'+filePath+'" class="tsr_btn_link"><span class="tsr_btn_middle"><span>'+subImg+'</span></span></a>');
    document.write('</div>');
    if (decL != 'null' && decL != '') {
        document.write('<div id="app_disclaimer_decline">');
        document.write('<a href="'+decL+'" class="tsr_btn_link"><span class="tsr_btn_middle"><span>'+decImg+'</span></span></a>');
        document.write('</div>');
    }
    document.write('</div>');
}

function whiteListData() {
	var listDomains = new Array("www.latinoamerica.nokia.com",
"www.nokia.com.ar","www.nokia.com.br",
"www.nokia-caribbean.com","www.nokia.cl",
"www.nokia.com.co","www.nokia.com.mx",
"www.nokia.com.ve","www.farsi.nokia.com",
"www.nokia.co.il","www.nokia.com.sa",
"www.nokia.ae","www.nokiausa.com",
"www.nokia.ca","www.nokia-asia.com",
"www.nokia.com.au","www.nokia.com.bd",
"www.nokia.com.cn","www.nokia.com.hk",
"www.nokia.co.in","www.nokia.co.id",
"www.nokia.co.jp","www.nokia.co.kr",
"www.nokia.com.my","www.nokia.co.nz",
"www.nokia.com.ph","www.nokia.com.sg",
"www.nokia.com.tw","www.nokia.co.th",
"www.nokia.vn",",mea.nokia.com",
"www.europe.nokia.com","www.nokia.at",
"www.nokia.be","www.nokia.bg",
"www.nokia.com.hr","www.nokia.cz",
"www.nokia.dk","www.nokia.ee",
"www.nokia.fr","www.nokia.de","www.nokia.com.gr",
"www.nokia.hu","www.nokia.ie",
"www.nokia.co.il","www.nokia.it",
"www.nokia.lv","www.nokia.lt",
"www.nokia.be","www.nokia.nl",
"www.nokia.no","www.nokia.pl","www.nokia.pt",
"www.nokia.ro","www.nokia.com.ru",
"www.nokia.com","www.nokia.sk",
"www.nokia.si","www.nokia.es",
"www.nokia.se","www.nokia.ch","es.ncomit.nokia.com",
"www.nokia.com.tr","www.nokia.ua","www.nokia.co.uk");
	return listDomains;
}