var type = getType(); var browser = new Browser(); var dragObj = new Object(); dragObj.zIndex = 0; var putX = 0; var putY = 0; var putURL = ""; var isMoved = false; var vers = 1.024; function Browser() { var ua, s, i; this.isIE = false; this.isNS = false; this.version = null; ua = navigator.userAgent; s = "MSIE"; if ((i = ua.indexOf(s)) >= 0) { this.isIE = true; this.version = parseFloat(ua.substr(i + s.length)); return;}
s = "Netscape6/"; if ((i = ua.indexOf(s)) >= 0) { this.isNS = true; this.version = parseFloat(ua.substr(i + s.length)); return;}
s = "Gecko"; if ((i = ua.indexOf(s)) >= 0) { this.isNS = true; this.version = 6.1; return;}
}
function getType() { var type; if (navigator.userAgent.indexOf("Opera")!=-1
&& document.getElementById) type="OP"; if (document.all) type="IE"; if (document.layers) type="NN"; if (!document.all && document.getElementById) type="MO"; return type;}
function sf() { getEl("q").focus(); getEl("q").select();}
function dumpProps(obj, parent) { for (var i in obj) { if (parent) { msg = parent + "." + i + "\n" + obj[i];} else { var msg = i + "\n" + obj[i];}
if (!confirm(msg)) { return;}
if (typeof obj[i] == "object") { if (parent) { dumpProps(obj[i], parent + "." + i);} else { dumpProps(obj[i], i);}
}
}
}
function insertContent(id, str) { if (type=="IE") { document.all[id].innerHTML = str;}
if (type=="NN") { document.layers[id].document.open(); document.layers[id].document.write(str); document.layers[id].document.close();}
if (type=="MO" || type=="OP") { document.getElementById(id).innerHTML = str ;}
}
function addContent(id, str) { if (type=="IE") { document.all[id].innerHTML = str + document.all[id].innerHTML;}
if (type=="NN") { document.layers[id].document.open(); document.layers[id].document.write(str + document.layers[id].document); document.layers[id].document.close();}
if (type=="MO" || type=="OP") { document.getElementById(id).innerHTML = str + document.getElementById(id).innerHTML;}
}
function getImgUrl(id) { var ret; if (type=="IE") { ret = document.all[id].src;}
if (type=="NN") { ret = document.layers[id].src; document.layers[id].document.close();}
if (type=="MO" || type=="OP") { ret = document.getElementById(id).src;}
return ret;}
function duplicate(event, id, url,name,icon) { id=id + "2"; if (!getEl(id)) { img_src = '<img id="' + id + '" style="cursor:move; z-index:5;"  onmousedown="dragStart(event,' + "'" + id + "'" + ')" src="' + icon + '" alt="" width="16" height="16" border="0" align="top">'; var new_cont = '<DIV id="' + id + '" style="z-index:10; position:absolute; left:200px; top:200px;text-align:center; display:block;">' + img_src + '<br /><a href="' + url + '">' + name + '</a></DIV>'; addContent("bodyBackground", new_cont);}
dragStart(event, id);}
function dragStart(event, id) { var el; var x, y; putURL = id; isMoved = false; if (getEl("wp").style.visibility != "hidden") { return false;}
if (id)
dragObj.elNode = document.getElementById(id); else { if (browser.isIE)
dragObj.elNode = window.event.srcElement; if (browser.isNS)
dragObj.elNode = event.target; if (dragObj.elNode.nodeType == 3)
dragObj.elNode = dragObj.elNode.parentNode;}
if (browser.isIE) { x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft; y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;}
if (browser.isNS) { x = event.clientX + window.scrollX; y = event.clientY + window.scrollY;}
dragObj.cursorStartX = x; dragObj.cursorStartY = y; dragObj.elStartLeft = parseInt(dragObj.elNode.style.left, 10); dragObj.elStartTop = parseInt(dragObj.elNode.style.top, 10); if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0; if (isNaN(dragObj.elStartTop)) dragObj.elStartTop = 0; dragObj.elNode.style.zIndex = ++dragObj.zIndex; if (browser.isIE) { document.attachEvent("onmousemove", dragGo); document.attachEvent("onmouseup", dragStop); window.event.cancelBubble = true; window.event.returnValue = false;}
if (browser.isNS) { document.addEventListener("mousemove", dragGo, true); document.addEventListener("mouseup", dragStop, true); event.preventDefault();}
}
function dragGo(event) { var x, y; isMoved = true; if (browser.isIE) { x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft; y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;}
if (browser.isNS) { x = event.clientX + window.scrollX; y = event.clientY + window.scrollY;}
dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px"; dragObj.elNode.style.top = (dragObj.elStartTop + y - dragObj.cursorStartY) + "px"; dragObj.elNode.style.left = x + "px"; dragObj.elNode.style.top = y + "px"; putX = x; putY = y; if (x>20) {dragObj.elNode.style.visibility = "visible";} else {dragObj.elNode.style.visibility = "hidden";}
if (browser.isIE) { window.event.cancelBubble = true; window.event.returnValue = false;}
if (browser.isNS)
event.preventDefault();}
function dragStop(event) { if (isMoved == true) { savePos(putURL, putX, putY);}
if (browser.isIE) { document.detachEvent("onmousemove", dragGo); document.detachEvent("onmouseup", dragStop);}
if (browser.isNS) { document.removeEventListener("mousemove", dragGo, true); document.removeEventListener("mouseup", dragStop, true);}
}
function setIframe(h) { var theIframe = document.getElementById? document.getElementById('ifrm'): document.all? document.all['ifrm']: null; if (theIframe) { viewport.getWinHeight(); theIframe.style.height = Math.round( h * viewport.height ) + "px"; theIframe.style.marginTop = Math.round( (viewport.height - parseInt(theIframe.style.height) )/2 ) + "px";}
}
function switchVisibility(id) { if (id == true) id = "wp"; var wp = getEl(id); if(wp.style.visibility=='hidden') { wp.style.visibility='visible';} else { wp.style.visibility='hidden';}
}
function go(gourl) { go2(gourl); getEl("q").value = gourl; checkQ(true); insertContent("maxleft", genMaxLeft(gourl)); createCookie("_changed",1,365); getEl("save").disabled = false;}
function go2(url) { var wp = getEl("wp"); var fr = getEl("ifrm"); wp.style.visibility='visible'; fr.src=url ;}
function getEl(id) { var ret = document.getElementById? document.getElementById(id): document.all? document.all[id]: null; return ret;}
function openQ() { var str = getEl("q").value; var butonText = getEl("sa").value; var q = getEl("q"); var s = getEl("sa")
var url = ""; switch (butonText) { case "Welcome": url = "http://www.google.com/"; break; case "Show MaxiGate": url = "show.php?maxigate=" + str; break; case "Install on this PC":
url = "set.php?maxigate=" + str + "&ac=" + Math.round(10000*Math.random()) ; if (readCookie("_changed")=="1") { if(!confirm('Your actual maxigate has been changed. Install anyway ?')) url = "save.php?ac=" + Math.round(10000*Math.random());}
break; case "Search in Google": url = "http://www.google.com/search?hl=en&lr=&safe=off&c2coff=1&q=" + encodeURI(str); break; case "Open URL": url = str; if (str.substring(0,4) != "http") { url = "http://" + url; q.value= url;}
s.value = "Add this URL into MaxiGate"; break; case "Edit link":
url="add.php?url=" + q.value + "&name=" + inCookies(q.value,"_name") + "&icon=" + inCookies(q.value,"_icon") + "&etc=" + inCookies(q.value,"_etc") + "&edit=1"; break; case "Add this URL into MaxiGate": url="add.php?url=" + q.value + "&icon=" + getEl("f_icon").value + "&name=" + getEl("f_name").value; getEl("f_icon").value = ""; getEl("f_name").value = ""; break;}
getEl("wp").style.visibility='visible'; getEl("ifrm").src = url;}
function checkQ(e) { var elQ = getEl("q"); var str = elQ.value; var elSA = getEl("sa"); if (e) { if (e.keyCode == 13) { openQ();} else { if (str.indexOf(" ") == -1) { if (str.indexOf(".") == -1) { elSA.value = "Show MaxiGate";} else { if (inCookies(str,"_url")!=false) { elSA.value = "Edit link";} else { elSA.value = "Open URL";}
}
} else { elSA.value = "Search in Google";}
}
}
}
function inCookies(url,cookname) { if (readCookie("_url")) { var arr_url = readCookie("_url").split("|"); var arr_cook = readCookie(cookname).split("|"); var cnt = arr_url.length; for (var i=0;i < cnt;i++) { if (arr_url[i] == url || arr_url[i] == ("http://"+url) ) { return arr_cook[i];}
}
}
return false;}
function createCookie(name,value,days)
{ if (days)
{ var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString();}
else var expires = ""; document.cookie = name+"="+value+expires;}
function readCookie(name)
{ var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++)
{ var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));}
return null;}
function eraseCookie(name)
{ createCookie(name,"",-1);}
function savePos(url,x,y) { var arr_url = readCookie("_url").split("|"); var arr_etc = (readCookie("_etc")).split("|"); var cnt = arr_url.length; for (var i=0;i < cnt;i++) { var arr_inEtc = arr_etc[i].split(","); if ( arr_url[i] == url) { arr_inEtc[0] = x; arr_inEtc[1] = y; if (x<15) {arr_inEtc[2] = 0;} else {arr_inEtc[2] = 1;}
}
arr_etc[i] = arr_inEtc.join(",");}
createCookie("_etc",(arr_etc.join("|")),365); createCookie("_changed",1,365); getEl("save").disabled = false;}
function genMaxLeft(url) { var n=0; var str=""; var str2=""; var var_id; var wp = getEl("wp"); var new_url = new Array(); var new_name = new Array(); var new_icon = new Array(); var new_etc = new Array(); if (wp.style.visibility == 'visible') { var curs = 'style="cursor:hand"';} else { var curs = 'style="cursor:move"';}
if ( readCookie("_url") ) { var arr_url = readCookie("_url").split("|"); var arr_icon = readCookie("_icon").split("|"); var arr_name = unescape(readCookie("_name")).split("|"); var arr_etc = (readCookie("_etc")).split("|"); var cnt = arr_url.length; var sys = readCookie("_sys"); if (readCookie("_sys")) var sys = readCookie("_sys"); else var sys = "#99CCFF"; document.body.bgColor = sys; for (var i=0;i < cnt;i++) { if (arr_url[i] != url) { if (arr_url[i] != "") { var_id = arr_url[i]; var arr_inEtc = arr_etc[i].split(","); if(arr_inEtc[2]==0) {var visi="hidden";} else {var visi="visible";}
var str_duplicate = "javascript:dragStart(event,'"+var_id+"')"; str = str + '<a href="javascript:go(' + "'" + arr_url[i] + "'" + ')" title="' + arr_name[i].replace('+',' ') + '"><img id="' + var_id + '" onmousedown="' + str_duplicate + '" src="' + arr_icon[i] + '" ' + curs + ' alt="' + unescape(arr_name[i].replace('+',' ')) + '" title="' + unescape(arr_name[i].replace('+',' ')) + '" width="16" height="16" border="0" align="top">&nbsp;&nbsp;' + unescape(arr_name[i].replace('+',' ')) + '</a>'; if (url.length == 0) { var img_src = '<IMG id="' + var_id + '" style="cursor:move;"  onmousedown="dragStart(event,' + "'" + var_id + "'" + ')" src="' + arr_icon[i] + '" alt="" border="0" align="top">'; var new_cont = '<DIV class="maxlink" id="' + var_id + '" style="visibility:'+visi+';position:absolute; left:' +arr_inEtc[0]+ 'px; top:' +arr_inEtc[1]+ 'px;text-align:center; display:block;">' + '<br /><a href="javascript:go(' + "'" + arr_url[i] + "'" + ')">' + img_src + "<br />"+ arr_name[i].replace('+','<br />') + '</a></DIV>'; str2 = str2 + new_cont;}
n++; new_url[n] = arr_url[i]; new_name[n] = arr_name[i]; new_icon[n] = arr_icon[i]; new_etc[n] = arr_etc[i];}
} else { new_name[0] = arr_name[i]; new_icon[0] = arr_icon[i]; new_url[0] = url; new_etc[0] = arr_etc[i];}
}
if (url.length>0) { var str_duplicate = "javascript:dragStart(event,'"+var_id+"')"; str = '<a href="javascript:go(' + "'" + url + "'" + ')" title="' + new_name[0] + '"><img id="' + var_id + '" onmousedown="' + str_duplicate + '" src="' + new_icon[0] + '" ' + curs + ' alt="' + new_name[0] + '" title="' + new_name[0] + '" width="16" height="16" border="0" align="top">&nbsp;&nbsp;' + new_name[0] + '</a>' + str; createCookie("_url",new_url.join("|"),365); createCookie("_name",(new_name.join("|")),365); createCookie("_icon",new_icon.join("|"),365); createCookie("_etc",(new_etc.join("|")),365);}
} else { str = "<a href='add.php?url=http://maxigate.blogspot.com&name=MaxiGateBlog&icon=http://maxigate.com/favicon.ico'><h1>First time? So click here (need cookies)</h1></a>";}
var my_q=getEl("q").value; if (readCookie("_maxigate")) var title = readCookie("_maxigate").toUpperCase(); else var title = ""; insertContent("maxtitle", title)
document.title = title + " MaxiGate.com v."+vers; if (readCookie("_changed")) getEl("save").disabled = false; else getEl("save").disabled = true; addContent("bodyBackground", str2); var q=getEl("q"); q.value = my_q; return str;}
function setQ(url) { var q = getEl("q"); q.value = url; checkQ(true);}
function startEngine() { checkQ(true); insertContent("maxleft", genMaxLeft("")); if ( readCookie("_auto") ) { var auto = readCookie("_auto"); eraseCookie("_auto");}
}
