var isCokkie = false;
if(document.cookie.length>0){
	var cokkieStr = document.cookie;
	isCokkie = cokkieStr.indexOf("telemessage=") != -1;
}

if(!isCokkie){
	var round4 = Math.round(Math.random()*10000);
	var cookieToday = new Date();
	var nextMonth = new Date(cookieToday.getYear(), cookieToday.getMonth()+1, cookieToday.getDate());
	document.cookie = "telemessage=" + cookieToday.getTime() + round4 + "; expires=" + nextMonth.toGMTString()+"; path=/";
}

function statusMsg(s) {
  window.status = (s ? s : '')
  return true;
}

function openPPWindow(url , winWidth , winHeight ,resize  ) {
  var features = 'toolbar=yes,location=no,directories=no,status=yes,menubar=yes,scrollbars=' + resize + ' ,resizable=' +resize + ', width=' + winWidth + ',height=' +winHeight;
  window.open(url,'ppWindow',features);
}

function openPPWindow2(url , winWidth , winHeight   ) {
  var features = 'toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes, width=' + winWidth + ',height=' +winHeight;
  window.open(url,'ppWindow',features);
}

function install_tb_complete (name, result) {
	if (result != 0 && result != 999) alert("An error occured: " + result);
	else {
		alert ("Restart the browser to finish installation");
	}
}

function Install_tb_XPI () {
	if (document.all){
		alert("Sorry,Firefox installation link works only when opened with Firefox browser");
	}else{
		var xpi = new Object ();
		xpi["TeleMessage_Toolbar"] = "install/telemessagetoolbarplugin.xpi";
		InstallTrigger.install (xpi, install_tb_complete);
	}
}

function beginDownload(){
	if(beginDownload.arguments.length > 0){
		var args = '"' + beginDownload.arguments[0] + '","downloadThankYou.jsp?loc=enUS","34"'; 
		if(beginDownload.arguments.length == 2)
			args = '"' + beginDownload.arguments[0] + '","' + beginDownload.arguments[1] + '","34"';
		else if(beginDownload.arguments.length == 3)
			args = '"' + beginDownload.arguments[0] + '","' + beginDownload.arguments[1] + '","' + beginDownload.arguments[2] + '"';
		window.setTimeout('redirect(' + args + ')', 2500);
	}
}

function redirect(path,fileName,prodid){
	document.location.href = path + fileName + (fileName.indexOf("?") > 0 ? "&" : "?") + "prodid=" + prodid;
}

function showDownloadStatus(){
	if(showDownloadStatus.arguments.length > 0)
		window.status = showDownloadStatus.arguments[0];
	else
		window.status = "Download";
}

function clearDownloadStatus(){
	window.status = "";
}

function TM_Menu(name, url, target){
	if(name == "" && url == "" && target == "")
		this.empty = true;
	else
		this.empty = false;
	this.name = name;
	this.url = url;
	this.target = target;
	
	//methods
	this.getName = function(){return this.name;}
	this.getUrl = function(){return this.url;}
	this.getTarget = function(){return this.target;}
	this.isEmpty = function(){return this.empty}
}

var doCheck = (document.all != null);
var browser = "";
if (doCheck == false) {
	versionNN = navigator.userAgent.toLowerCase();
	if (versionNN.search(/mozilla\/4/i) != -1){
		browser = "NN4";
		brs = "IE";
	}else{
		browser = "NN6";
	}
} else {
	var agt = navigator.userAgent.toLowerCase();
	if ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)) {
		browser = "IE";
		brs = "IE";
	}else{
		browser = "OP";
	}
}

function getLayer(id) {
	if (browser == "IE" || browser == "OP")
		return document.all[id];
	else if (browser == "NN4")
		return document.layers[id];
	else
		return document.getElementById(id);
}

var Event = {
	add: function(eventName, func) {
		if (window.attachEvent) {
			window.attachEvent( ("on" + eventName), func);
		} else {
			try{
				window.addEventListener(eventName, func, false);
			}catch(e){alert(e);}
		}
	},
	remove: function(eventName, func) {
		if (window.detachEvent) {
			window.detachEvent(("on" + eventName), func);
		} else {
			try{
				window.removeEventListener(eventName, func, false);
			}catch(e){alert(e);}
		}
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function createXMLHttpRequest(){
    var xmlHttp;
    try{
        xmlHttp = new XMLHttpRequest();
    }catch(e){
        var xmlHttpVersions = new Array(
                    "MSXML2.XMLHTTP.6.0",
                    "MSXML2.XMLHTTP.5.0",
                    "MSXML2.XMLHTTP.4.0",
                    "MSXML2.XMLHTTP.3.0",
                    "MSXML2.XMLHTTP",
                    "Microsoft.XMLHTTP"
                );
        for(var i=0;i<xmlHttpVersions.length && ! xmlHttp;i++){
            try{
                xmlHttp = new ActiveXObject(xmlHttpVersions[i]);
            }catch(e){}
        }
    }
    if(!xmlHttp){
        alert("xmlHttp didn't initialize!");
        return null;
    }else{
        return xmlHttp;
    }
}

var curXMLHttp = createXMLHttpRequest();

function process(method, serverSideScript, handleFunction, vars, assync){
    if(curXMLHttp){
        try{
            var func = eval(handleFunction);
            if(func != null){
                curXMLHttp.open(method,serverSideScript + ( vars.length > 0 ? ("?"+vars) : "" ), assync);
                curXMLHttp.onreadystatechange = func;
				if(method.toLowerCase() == "post")
					curXMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                curXMLHttp.send(null);
            }else{}
        }catch(e){alert(e);}
    }
}

function TM_FAQ_QUESTION(ques, ans, ind){
	this.ques = ques;
	this.ans = ans;
	this.ind = ind;
	
	//methods
	this.getQuestion = function(){return this.ques;}
	this.getAnswer = function(){return this.ans;}
	this.getIndex = function(){return this.ind;}
}

function TMFAQ_PART(name){
	this.name = name;
	this.questions = new Array();
	this.size = -1;
	//methods
	this.getName = function(){return this.name;}
	this.getSize = function(){return (this.size+1);}
	this.isEmpty = function(){return (this.size < 0);}
	this.addQuestion = function(ques){this.size++; this.questions[this.size] = ques;}
	this.getQuestion = function(ind){ return (this.size > -1 ? this.questions[ind] : null );}
	this.getQuestions = function(){return this.questions;}
}

var partsAr = new Array();

function handleFAQRequest(){
	if(curXMLHttp.readyState == 4){
        if(curXMLHttp.status == 200 || curXMLHttp.status == 0){
            try{
                var xmlResponse = curXMLHttp.responseXML;
                if(!xmlResponse || !xmlResponse.documentElement){
                    throw("Not valid XML IE");
                }

				var rootNode = xmlResponse.documentElement;
                var rootNodeName = rootNode.nodeName;

                if(rootNodeName == "parsererror"){
                    throw("Not valid XML Mozilla " + rootNodeName);
                }
				
				var partsNodeList = rootNode.getElementsByTagName("part");
				var count = 0;
				for(var i=0; i<partsNodeList.length; i++){
					var partNode = partsNodeList[i];
					if(partNode.hasChildNodes()){
						var partName = partNode.getElementsByTagName("partName")[0].firstChild.nodeValue;
						if(partName != ""){
							var partClass = new TMFAQ_PART(partName);
							var questionsNodeList = partNode.getElementsByTagName("question");
							
							var quesInd = 0;
							for(var j=0; j<questionsNodeList.length; j++){
								var questionPair = questionsNodeList[j];
								if(questionPair.hasChildNodes()){
									var q 	= 	questionPair.getElementsByTagName("q")[0].firstChild.nodeValue;
									var ans = 	questionPair.getElementsByTagName("ans")[0].firstChild.nodeValue;
									var pair = new TM_FAQ_QUESTION(q, ans, quesInd);
									partClass.addQuestion(pair);
									quesInd++;
								}
							}
							
							partsAr[count] = partClass;
							count++;
						}
					}
				}
				
				var indCont 	= 	"<table class='indexTable' id='faqindTable' cellpadding='2' cellspacing='2'>";
				var qustCont 	= 	"<table class='contentTable' id='faqcontentTable' cellpadding='0' cellspacing='0' border='0'>";
				for(var i=0; i < partsAr.length; i++){
					var partClass = partsAr[i];
					
						indCont		+=	"<tr><td colspan='2' class='productTitle'><a href='#" + i + "'>" + partClass.getName() + "</a></td></tr>";
						qustCont	+=	"<tr><td colspan='3' class='productTitle'><a name='" + i + "'>" + partClass.getName() + "</a></td></tr>";
						
						var quess = partClass.getQuestions();
						for(var j=0; j<quess.length; j++){
							var faq = quess[j];
							var q = faq.getQuestion();
							var ans = faq.getAnswer();
							var ind = faq.getIndex();
							
							indCont			+=	"<tr class='quesText'><td class='number' id='ind_" + i + "_" + j + "'>" + (j+1) + ".</td><td class='qText'><a href='#q" + i + "_" + ind + "' onclick='javascript:scrollFirefoxTo(\"#q" + i + "_" + ind + "\");'>" + q + "</a></td></tr>";
							qustCont		+=	"<tr><td valign='top' class='numberA'>" + (j+1) + ".&nbsp;</td><td class='faq' id='ind1_" + i + "_" + j + "'><strong>Q:</strong> <a id='#q" + i + "_" + ind + "' name='q" + i + "_" + ind + "'><span>" + q + "</span></a></td><td width='5'></td></tr>";
							qustCont		+=	"<tr><td></td><td class='ans' align='justify' id='ans_" + i + "_" + j + "'><strong class='ans'>A:</strong> " + ans + "</td><td width='5'></td></tr>";
							qustCont		+=	"<tr><td colspan='3' height='6'></td></tr>";
						}
						indCont 	+= 	"<tr><td>&nbsp;</td></tr>";
						qustCont 	+= 	"<tr><td>&nbsp;</td></tr>";
				}
				indCont 	+= 	"</table>";
				qustCont 	+= 	"</table>";
				
				var getInd 	= getLayer("faqind");
				var getCont = getLayer("faqcontent");
				
				if(getInd != null && getCont != null){
					getInd.innerHTML = indCont;
					getCont.innerHTML = qustCont;
				}
				
			}catch(e){alert(e);}
        }
    }
}

function scrollFirefoxTo(id){
	var getInd 	= getLayer(id);
	if(browser != "IE" && getInd != null){
		var posAr = findPos(getInd);
		window.scroll(0,posAr[1]);
	}
}

function searchSupport(searchString){
	var getInd 	= getLayer("faqind");
	var getCont = getLayer("faqcontent");
	
	if(getInd != null && getCont != null){
		searchDTD(searchString,getInd);
		searchDTD(searchString,getCont);
	}
}

function searchDTD(searchString, objn){
	var firstMatch = null;
	if(objn != null){
		var trList = objn.getElementsByTagName("tr");
		for(var i=0; i<trList.length; i++){
			var objTr = trList[i];
			if(objTr.hasChildNodes()){
				var objTdList = objTr.getElementsByTagName("td");
				for(var j=0; j<objTdList.length; j++){
					var objTd = objTdList[j];
					if( objTd.hasChildNodes()){
						if( (tdID = objTd.getAttribute("id")) ){
							var spanList = objTd.getElementsByTagName("span");
							for(var k=0; k<spanList.length; k++){
								var spanNode = spanList[k];
								if(spanNode.hasChildNodes()){
									var nval = spanNode.firstChild.nodeValue;
									if(searchString != ""){
										if(nval.toLowerCase().indexOf(searchString.toLowerCase()) != -1){
											spanNode.className = "highlight";
											if(firstMatch == null){
												firstMatch = tdID;
											}
										}else{
											spanNode.className = "whiteBg";
										}
									}else{
										spanNode.className = "whiteBg";
										spanNode.className = "transpar";
									}
								}
							}
						}
					}
				}
			}
		}
	}
	if(firstMatch != null && firstMatch != ""){
		var foccur = getLayer(firstMatch);
		var posAr = findPos(foccur);
		window.scroll(0,posAr[1]);
	}
}

var lastObj = null;

function searchRegistrars(searchString){
	var objn = getLayer("coverage");
	if(searchString != "")
		disableBackground();
	searchDTD(searchString, objn);
}

function openCountry(slt){
	var value = slt.options[slt.selectedIndex].value;
	disableBackground();
	if(value != ""){
		document.location = "#" + value;
		var obj = getLayer("c" + value);
		if(obj != null){
			obj.style.backgroundColor = "yellow";
			lastObj = obj;
		}
	}
	
	searchRegistrars("");
}

function disableBackground(){
	if(lastObj != null){
		lastObj.style.backgroundColor = "white";
	}
}