// JavaScript Document
var browser = {
		'isIE' : (navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0),
		'isIE6' : (navigator.userAgent.indexOf('MSIE 6.0') >= 0) && (navigator.userAgent.indexOf('Opera') < 0),
		'isIE7' : (navigator.userAgent.indexOf('MSIE 7.0') >= 0) && (navigator.userAgent.indexOf('Opera') < 0),
		'isFirefox' : navigator.userAgent.indexOf('Firefox') >= 0,
		'isOpera' : navigator.userAgent.indexOf('Opera') >= 0
}; 
var _init = function(){};

function returnurl()
{
	if (!document.getElementById("left_nav")) 
	return;
	var hostName = "eu.avepoint.com";
	var hostName2 = "63.119.63.230";
	var hostName3 = "eustaging.avepoint.com";
	var regURL = new RegExp("^http://" + hostName);
	var regURL2 = new RegExp("^http://" + hostName2);
	var regURL3 = new RegExp("^http://" + hostName3);
	var url = window.location.href.toLowerCase().split('?')[0] + "/";
	url = url.replace(regURL, '');
	url = url.replace(regURL2, '');
	url = url.replace(regURL3, '');
	var urls = url.split('/');	
	if(urls[1]=="support"){
		document.getElementById("anchorRequestDemo").className = document.getElementById("anchorChatSales").className = "notdisplay";
		document.getElementById("anchorOpenTicket").className = document.getElementById("anchorSearchKB").className = "";
	}
	if(urls[2] == ""){
		url = "/" + urls[1] + "/";
	}else{
		url = "/" + urls[1] + "/" + urls[2] + "/";
	}
	return url;	
}
function bindLeftNav()
{
	var currenturl = returnurl();
	getmatchleft(currenturl);
}
function leftitemmatch(urllist)
{	
	var urlitem = returnurl();
	var ulLeftNav = urllist;
	var leftbutton = ulLeftNav;	
	var existLeftNav = false;
	if(ulLeftNav=="about"||ulLeftNav=="partners"||ulLeftNav=="about"||ulLeftNav=="support"||ulLeftNav=="resources"||ulLeftNav=="sharepoint-solutions"||ulLeftNav=="sharepoint-products")
	{
		existLeftNav = true;
		ulLeftNav += "LN";
	}
	var phostName = "eu.avepoint.com";
	var phostName2 = "63.119.63.230";
	var phostName3 = "eustaging.avepoint.com";
	var pregURL = new RegExp("^http://" + phostName);
	var pregURL2 = new RegExp("^http://" + phostName2);
	var pregURL3 = new RegExp("^http://" + phostName3);
	ulLeftNav = document.getElementById(ulLeftNav);
	if(!ulLeftNav)return;	
	var ems = ulLeftNav.getElementsByTagName("em");
	for(var i =0; i <ems.length; i++){
		if(ems[i].className.indexOf("NoChild") == -1){
			ems[i].className = "Add";
			ems[i].id = "em" + i;
			ems[i].onclick = new Function('showLeftNav(' + i + ')');
			var anchorL2 = ems[i].parentNode.getElementsByTagName('a')[0];
			var anchorL2Href = anchorL2.href.replace(pregURL, '');
			anchorL2Href = anchorL2Href.replace(pregURL2, '');
			anchorL2Href = anchorL2Href.replace(pregURL3, '');	
			if(anchorL2Href == urlitem){
				existLeftNav = true;
			}
			var ulul = ems[i].parentNode.getElementsByTagName('ul')[0];	
			if(anchorL2Href.indexOf('void') != -1){
				anchorL2.onclick = new Function('showLeftNav(' + i + ')');
			}else if(anchorL2Href == urlitem){
				ulul.style.display = 'block';
				ems[i].className = "Sub";
			}			
			ulul.id = 'ul' + i;		
			var ululas = ulul.getElementsByTagName('a');
			for(var j =0; j <ululas.length; j++){
				var anchorululas = ululas[j].href.replace(pregURL, "");
				anchorululas = anchorululas.replace(pregURL2, "");
				anchorululas = anchorululas.replace(pregURL3, "");
				if(anchorululas == urlitem){
					ululas[j].parentNode.className = "LNFocus";
					ulul.style.display = 'block';
					ems[i].className = "Sub";
					existLeftNav = true;
				}
			}
		}else{
			ems[i].className = "Add";
		}
	}
	if(existLeftNav){
		ulLeftNav.style.display = "block";	
	}
	/*if(urlitem == '/sharepoint-products/'){
		document.getElementById('sharepoint-productsLN').style.display = "block";
	}
	if(leftbutton == "support"){
		document.getElementById("anchorRequestDemo").className = document.getElementById("anchorChatSales").className = "notdisplay";
		document.getElementById("anchorOpenTicket").className = document.getElementById("anchorSearchKB").className = "";		
	}*/
}

function showLeftNav (i){
	var ul = document.getElementById('ul' + i);
	if(ul.style.display != 'block'){
		ul.style.display = 'block';
		document.getElementById('em' + i).className = "Sub";
	}else{
		ul.style.display = 'none';
		document.getElementById('em' + i).className = "Add";
	}
}
var strHttpheader;
function getmatchleft(urlheader){
	strHttpheader = myAjax.InitAjax();
	myAjax.POST2("url="+urlheader, '/toolkit/new-rebuild/matchleft.php', c_getmatchleft, strHttpheader);
}
function c_getmatchleft() {
	if(strHttpheader.readyState == 4 && strHttpheader.status == 200)
	{
		var  strmatchleft = strHttpheader.responseText;
		strmatchleft = strmatchleft.replace(/\d*$/,"");
		strmatchleft = strmatchleft.replace(" ","");
		//alert (strmatchleft);
		leftitemmatch(strmatchleft);
	}
}
//new IE6 Header need
function firstSpanHover(){
	var spanHover = document.getElementById("navbar").getElementsByTagName("li");
	for(var i=0; i<spanHover.length; i++){
		var spanA = spanHover[i].getElementsByTagName("a");
		for(var j=0; j<spanA.length; j++){	
			var aarray = spanA[j].getElementsByTagName("span"); 
			for(var c=0; c<aarray.length; c++){
				if(spanA[j].href.indexOf("void")!=-1){
					aarray[c].onmouseover = function(){
						this.style.backgroundColor = "";
						this.style.color = "#fff";}
					aarray[c].onmouseout = function(){
						this.style.backgroundColor = "";
						this.style.color = "#fff";
					}
				}
				else
				{
					if((location.href.match("atlas"))||(location.href.match("salesforce")))
					{
						aarray[c].onmouseover = function(){
							this.style.backgroundColor = "#e2f1f9";
							this.style.color = "#000";
						}
						aarray[c].onmouseout = function(){
							this.style.backgroundColor = "";
							this.style.color = "#fff";
						}
					}
					else
					{
						aarray[c].onmouseover = function(){
							this.style.backgroundColor = "#e3d0ac";
							this.style.color = "#000";
						}
						aarray[c].onmouseout = function(){
							this.style.backgroundColor = "";
							this.style.color = "#fff";
						}
					}
				}
			}
		}
	}
}
function LeftNavPreloadPic(){
	new Image().src = "/mysite/images/leftnav/requestDemoHover.png";
	new Image().src = "/mysite/images/leftnav/chatSalesHover.png";
	new Image().src = "/mysite/images/leftnav/free30DaysHover.png";
	new Image().src = "/mysite/images/leftnav/HowtoBuyHover.png";
	new Image().src = "/mysite/images/leftnav/openTicketHover.png";
	new Image().src = "/mysite/images/leftnav/SearchKBHover.png";
}
function Ie6Pngs(){
	var reg = /.*\.png$/;
	var pngs = document.getElementsByTagName("img");
	for (var i=0; i < pngs.length; i++){
		if(reg.test(pngs[i].src)){
			pngs[i].style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+pngs[i].src+"),sizingMethod='scale');";
			pngs[i].src="/mysite/images/blank.gif";
		}
	}	
	document.execCommand("BackgroundImageCache",false,true);
}
var tab_focus_level3 = "BusinessAdvantages";
function showCommon (id){
	document.getElementById(tab_focus_level3 + "_tab").className = "hiddeningCommon";
	document.getElementById(tab_focus_level3 + "_div").className = "tab_hidden";
	tab_focus_level3 = id;
	document.getElementById(tab_focus_level3 + "_tab").className = "showingCommon";
	document.getElementById(tab_focus_level3 + "_div").className = "tab_show";
}
var fourtab_focus_level3 = "ToolFeature";
function showCommonH (id){
	document.getElementById(fourtab_focus_level3 + "_tab").className = "hiddeningCommonH";
	document.getElementById(fourtab_focus_level3 + "_div").className = "tab_hidden";
	fourtab_focus_level3 = id;
	document.getElementById(fourtab_focus_level3 + "_tab").className = "showingCommonH";
	document.getElementById(fourtab_focus_level3 + "_div").className = "tab_show";
}
var tab_focus_level3eu = "TechnicalOverview";
function showCommonLong(id, className){
	var hidden = tab_focus_level3eu == "TechnicalOverview" ? "hiddeningCommonLong" : "hiddeningCommon";	
	document.getElementById(tab_focus_level3eu + "_tab").className = hidden;
	document.getElementById(tab_focus_level3eu + "_div").className = "tab_hidden";
	tab_focus_level3eu = id;
	var show = tab_focus_level3eu == "TechnicalOverview" ? "showingCommonLong" : "showingCommon";
	document.getElementById(tab_focus_level3eu + "_tab").className = show;
	document.getElementById(tab_focus_level3eu + "_div").className = "tab_show";
}
var tab_hr_level4s = {"Tokyo":"0px","Uxbridge":"-34px","JerseyCity":"-68px","Chicago":"-102px"};
var tab_focus_level4s = "Tokyo";
function hrShow(id){
	document.getElementById(tab_focus_level4s + "_div").className = "tab_hidden";
	tab_focus_level4s = id;
	document.getElementById(tab_focus_level4s + "_div").className = "tab_show";
	document.getElementById('TabsHrright').style.backgroundPosition  = tab_hr_level4s[id] + " 27px";			
}

var srcForIE = new Array();
srcForIE['SQLRCtrlButton'] = "/mysite/images/products/SQLRCtrlButton.png";
function ChangeSrc(id) 
{
	var img = document.getElementById(id);
	var temp = img.src;
	var regReplace = /hover.png$/i;
	var regReplaceHover = /.png$/i;	
	if(temp.indexOf('blank') != -1){
		temp = srcForIE[id];
	}
	if(regReplace.test(temp)){
		temp = temp.replace(regReplace, ".png");
	}else{
		temp = temp.replace(regReplaceHover, "Hover.png");
	}
	srcForIE[id] = img.src = temp;	
	if(browser.isIE6){
		img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+temp+"),sizingMethod='scale');";
		img.src = "/mysite/images/blank.gif";
	}
}

function showSubMenu(id, a){
	var ul = document.getElementById(id);
	if(ul != null){
		ul.style.display = "block";
		a.onclick = function(){hiddenSubMenu(id, a)}
		var img = a.firstChild;
		img.src = "/mysite/images/leftnav/sub.png";
		img.alt = "-";
	}
}

function hiddenSubMenu(id, a){
	var ul = document.getElementById(id);
	if(ul != null){
		ul.style.display = "none";
		a.onclick = function(){showSubMenu(id, a)}
		var img = a.firstChild;
		img.src = "/mysite/images/leftnav/add.png";
		img.alt = "+";
	}
}
/*Add Event*/
function addEvent (o, t, f) {
	if (o.attachEvent) o.attachEvent('on'+ t, f);
	else o.addEventListener(t, f, false);
}
/*Remove Event*/
function removeEvent (o, t, f) {
	if (o.detachEvent) o.detachEvent('on'+ t, f);
	else o.removeEventListener(t, f, false);
};

/*Cookie*/
function createCookie(name,value,ms) {
	if (ms) {
		var date = new Date();
		date.setTime(date.getTime() + ms);
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

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 c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function popper(url,name,wide,heigh) { 
 	newWindow = window.open(url,name,"resizable=no,scrollbars=yes,width="+wide+",height="+heigh+" left=0 top =0");
}
function popperChatLiveSales(){
	newWindow = window.open("http://server.iad.liveperson.net/hc/89082276/?cmd=file&file=visitorWantsToChat&site=89082276&byhref=1&imageUrl=http://www.avepoint.com/images/avepoint/liveperson","AvePop","resizable=no,scrollbars=yes,width=500,height=500 left=0 top =0");
}
function newpopper(url,name,features) { 
 	var newWindow = window.open("",name,"resizable=no,scrollbars=no,width=800,height=561 left=0 top =0");
	
	var string = '<html><title>'+name+'</title><body style="background-image:url('+url+');background-repeat:no-repeat"></body></html>';
	newWindow.document.write(string);
	newWindow.document.close() ;
}
function newpopper(url,name,wide,heigh) { 
 	var newWindow = window.open("",name,"resizable=yes,scrollbars=no,width="+wide+",height="+heigh+" left=0 top =0");

	var string = '<html><title>'+name+'</title><body style="background-image:url('+url+');background-repeat:no-repeat"></body></html>';
	newWindow.document.write(string);
	newWindow.document.close() ;
}
function newpopper(url,name1,name2,wide,heigh) { 
    name1 =  name1.replace(/-/g," ");  
	name2 =  name2.replace(/-/g," "); 
	
	var newWindow = window.open(name2,"POP","resizable=yes,scrollbars=no,width="+wide+",height="+heigh+" left=0 top =0");

	var string = '<html><title>'+name1+'</title><body style="background-image:url('+url+');background-repeat:no-repeat"></body></html>';
	newWindow.document.write(string);
	newWindow.document.close() ;
}
function showBigImg(url1,name1,name12,wide1,heigh1,url2,name2,name22,wide2,heigh2){
	if (screen.width==800||screen.height==600){
		newpopper(url1,name1,name12,wide1,heigh1);
	}else{
		newpopper(url2,name2,name22,wide2,heigh2);
	}

}
function emptyTheText(object,value){
	 if(object.value==value){
		 object.value="";
	 }
}
function addexternallinks(){
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "external" || (anchor.getAttribute("href").indexOf("pdf")>0 && anchor.getAttribute("href").indexOf(".pdf") ==  anchor.getAttribute("href").length -4 ))){
			anchor.target = "_blank";
		}
	}	
}
function TextForProduct(){
	var flag = 0;
	if(document.getElementById("productShow") && document.getElementById("productShow").innerHTML.length < 60){
		document.getElementById("productShow").style.display = "none";
		flag++;
	}	
	if(document.getElementById("TextForProduct") && document.getElementById("TextForProduct").innerHTML.length < 60){
		document.getElementById("TextForProduct").style.display = "none";
		flag++;
	}
	if(flag == 2 && document.getElementById('TabsTitle')){
		document.getElementById('TabsTitle').style.height = "4px";
		if(browser.isIE6){
			document.getElementById('TabsTitle').style.marginTop = "-11px";
		}
	}
}
function JumpTo  (id){
	var _select = document.getElementById(id);
	var _href = _select.options[_select.selectedIndex].value;
	window.location.href = _href;
}
function AddToOnload(func){
	var temp = _init;
	_init = function(){
		temp();
		func();
	}	
}

function swf() {
	if(document.getElementById("flashDiv")){
	var string = ""
	string ='<p><object type="application/x-shockwave-flash" data="/assets/player/player.swf" width="480" height="360" id="vcastr3"><param name="movie" value="/assets/player/player.swf"/><param name="allowFullScreen" value="true" /><param name="wmode" value="transparent" ><param name="FlashVars" value="xml={vcastr}{channel}{item}{source}http://video.avepoint.com.s3.amazonaws.com/en/Economic_Report/AvepointFINAL2.flv{/source}{duration}{/duration}{title}{/title}{/item}{/channel}{config}<isAutoPlay>false</isAutoPlay>{/config}{plugIns}{/plugIns}{/vcastr}"/>    "/>  </object></p>';
	document.getElementById("flashDiv").innerHTML=string;
	}
	if(document.getElementById("flashDiv2")){
	var string2 = ""
	string2 ='<p><object type="application/x-shockwave-flash" data="/assets/player/player.swf" width="480" height="270" id="vcastr3"><param name="movie" value="/assets/player/player.swf"/><param name="allowFullScreen" value="true" /><param wmode="transparent" value="true" /><param name="FlashVars" value="xml={vcastr}{channel}{item}{source}http://video.avepoint.com.s3.amazonaws.com/en/AvePointRAW.flv{/source}{duration}{/duration}{title}{/title}{/item}{/channel}{config}<isAutoPlay>false</isAutoPlay>{/config}{plugIns}{/plugIns}{/vcastr}"/>    "/>  </object></p>';
	document.getElementById("flashDiv2").innerHTML=string2;
	}
}  

if(browser.isIE6){
	AddToOnload(Ie6Pngs);
}
AddToOnload(addexternallinks);
AddToOnload(swf);
var mousePos;
function bindOnMouseMove(){
	document.onmousemove = mouseMove;
}
function mouseMove(ev){
	ev=ev||window.event;
	mousePos = mouseCoords(ev);
}
function mouseCoords(ev){
	if(ev.pageX || ev.pageY){
		return {x:ev.pageX, y:ev.pageY};
	}
	return {
		x:ev.clientX + document.documentElement.scrollLeft - document.body.clientLeft,y:ev.clientY + document.documentElement.scrollTop - document.body.clientTop
	};
}
function showpic(){
	testvalue = document.getElementById("test").value;
	for(var i=1; i<=13; i++){
		document.getElementById("div" + i ).className="notdisplay";
	}
	document.getElementById("div"+testvalue).className="block";
}

var myAjax= {};
var xmlhttp;
myAjax.InitAjax = function()
{
	try
	{
		return new ActiveXObject("Msxm12.XMLHTTP");
	}
	catch(e)
	{
		try{
			return new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e)
		{
			try{
				return new XMLHttpRequest();
			}
			catch(e){
				alert("Your browser does not support AJAX.");
				return null;
			}
		}
	}
}
myAjax.POST = function(s,URL,callback){    
    if(xmlhttp){
		xmlhttp.open("POST",URL,true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", s.length);
	    xmlhttp.onreadystatechange=callback;
		xmlhttp.send(s);
    }else{
        throw {"description":"create xmlhttp failed"};
    }    
}
myAjax.POST2 = function(s,URL,callback, xmlhttp){    
    if(xmlhttp){
		xmlhttp.open("POST",URL,true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", s.length);
	    xmlhttp.onreadystatechange=callback;
		xmlhttp.send(s);
    }else{
        throw {"description":"create xmlhttp failed"};
    }    
}
myAjax.GETF = function(s,URL,callback){
    s=s?"?"+s:"";
    if(xmlhttp){
        xmlhttp.open("GET",URL+s,true);
        xmlhttp.onreadystatechange=callback;
        xmlhttp.send(""); 
    }else{
        throw {"description":"create xmlhttp failed"};
    }
}

function makeShowtext(){
	var obj;
	if(document.getElementById('productShowtext')){
		obj = document.getElementById('productShowtext');
		
	}else if(document.getElementById('solutionShowtext')){
		obj = document.getElementById('solutionShowtext');
	}else{
		return;
	}
	var top = Math.round((213 - obj.scrollHeight) / 2);
	obj.style.top = top + "px";
}
AddToOnload(makeShowtext);

var xmlbreadCrumbs;
function getBreadCrumbs(){
	xmlbreadCrumbs = myAjax.InitAjax();
	myAjax.POST2("url=" + window.location.href, '/toolkit/getBreadcrumbs.php', c_getBreadCrumbs, xmlbreadCrumbs);	
}

function c_getBreadCrumbs(){
	if (xmlbreadCrumbs.readyState == 4 && xmlbreadCrumbs.status == 200){
		document.getElementById('Breadcrumbs').innerHTML = xmlbreadCrumbs.responseText;
	}
}
function newsLetterSubmit(){
	var content = document.getElementById('email').value;
	var url = '/resources/avepoint-newsletter/#'+content;
	window.location.href= url ;
}
var xmlGovt;
function getGovtEvents(){
	xmlGovt = myAjax.InitAjax();
	myAjax.POST2("govt=1", '/toolkit/homeEvent.php', c_getGovtEvents, xmlGovt);	
}

var scrollObj;
function c_getGovtEvents(){
	if (xmlGovt.readyState == 4 && xmlGovt.status == 200){
		var govtDiv = document.getElementById('govtEvent');
		var e = document.createElement('div');
		e.id = 'govtEvent1';
		var govtDiv1 = govtDiv.appendChild(e);
		govtDiv1.innerHTML = xmlGovt.responseText;
		if(govtDiv1.scrollHeight > 270){
			scrollFlagGovt = true;
			e = document.createElement('div');
			e.id = 'govtEvent2';
			var govtDiv2 = govtDiv.appendChild(e);
			govtDiv2.innerHTML = govtDiv1.innerHTML;
			scrollObj = setInterval(function(){scrollEvent(govtDiv1, govtDiv2, govtDiv);}, 40);
			//govtDiv.onmouseover = function(){scrollFlagGovt = false;}
			//govtDiv.onmouseout = function(){scrollFlagGovt = true;}
			govtDiv.onmouseover = function(){clearInterval(scrollObj);}
			govtDiv.onmouseout = function(){scrollObj = setInterval(function(){scrollEvent(govtDiv1, govtDiv2, govtDiv);}, 40);};
		}
	}
}

function scrollEvent(govtDiv1, govtDiv2, govtDiv){
	if(govtDiv2.offsetHeight-govtDiv.scrollTop <= 0){
		govtDiv.scrollTop -= govtDiv1.offsetHeight;
		govtDiv.scrollTop ++ ; 
	}else{
		govtDiv.scrollTop ++;
	}

}
function initSQLrestorecontrol(){
	document.getElementById('aSQLRCtrlButton').onmouseover = function(){
		ChangeSrc('SQLRCtrlButton');
		};
	document.getElementById('aSQLRCtrlButton').onmouseout = function(){
		ChangeSrc('SQLRCtrlButton');
		};
	}

var tab_focus_level4 = "FundamentalsCourseI";
function showCommon2 (id){
	document.getElementById(tab_focus_level4 + "_tab").className = "hiddeningCommon";
	document.getElementById(tab_focus_level4 + "_div").className = "tab_hidden";
	tab_focus_level4 = id;
	document.getElementById(tab_focus_level4 + "_tab").className = "showingCommon";
	document.getElementById(tab_focus_level4 + "_div").className = "tab_show";
}
/* Change rel=external to target_blank    */
function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href") &&
anchor.getAttribute("rel") == "external")
anchor.target = "_blank";
}
}
window.onload = externalLinks; 