﻿//////// FIELDS /////////////
var d=document;

//temp object
d.tmp=new Object();
d.tmp.cust=0;
d.tmp.debuggers=null;
d.tmp.range=new Array();

//image object
d.img=new Object();

//customers object
d.cust=new Object();

d.cust.arr=new Array();

d.cust.arr[0]=new Array();
d.cust.arr[0][0]="Nick Vitovitch, Program Manager, HP";
d.cust.arr[0][1]="Choosing Elementool made a lot of sense, given the distributed nature of the project, and the fact that we had several outside vendors involved. Elementool offers the flexibility we needed to create records and reports that met our needs.";

d.cust.arr[1]=new Array();
d.cust.arr[1][0]="Weston Morris, Project Manager, Unisys";
d.cust.arr[1][1]="Elementool has paid for itself in terms of savings of time and expense without even considering all the other benefits. The time we spend in the process of finding, tracking, correcting and reporting on defects is greatly reduced with Elementool.";

d.cust.arr[2]=new Array();
d.cust.arr[2][0]="Peter Jin, Director of IT, QA and Release, TicketsNow";
d.cust.arr[2][1]="TicketsNow tried various bug tracking tools but found them cumbersome and expensive. The thing that separates Elementool from the rest is the ease of use. This tool takes me just a few minutes to update issues, create new users, update forms and run reports.";

d.cust.arr[3]=new Array();
d.cust.arr[3][0]="James Kelleher, CEO, Generis Knowledge Management";
d.cust.arr[3][1]="Elementool has been integral in tracking which product releases new enhancements end up in. This detailed tracking and reporting allows us to accurately plan release timetables and keep our customers well informed.";

d.cust.arr[4]=new Array();
d.cust.arr[4][0]="Martin Weinberg, Senior Account Manager, eCity Interactive";
d.cust.arr[4][1]="Using Elementool has allowed eCity to improve their QA testing process. Nothing slips through the cracks. Because it’s all in a database, every issue is addressed in an organized way.";

d.cust.arr[5]=new Array();
d.cust.arr[5][0]="Tony Ricci, Quality Assurance Manager, Auto-Graphics, Inc.";
d.cust.arr[5][1]="Elementool's product, in comparison, is better than most we researched. We have faith in Elementool to continue improving the software; their track record shows that they have been responsive and professional.";



d.cust.timerObj;
d.tmp.cust=0;

////////////////////////////////////////////////////// CUSTOMER ROTATION TIME /////////////////////////////////////////
////// X000 == X seconds (for example 3000 == 3 sec)
d.cust.timerNum=3000;

//the number of logos
d.cust.logoscount=12;
d.img.logosimg=new Array();
d.cust.logospath="images/customerslogos/";

///////////  FUNCTION ///////////////////

//PROTOTYPE 

function setRange()
{

var r=100/this.length;

var tmpr=0;
	for(n=0;n<this.length;n++)
	{
		if(!this[n][0])
		{
		this[n]=new Array();
		this[n][0]="";
		}
	var tmp1=this[n].length;
	this[n][tmp1]=new Object();
	this[n][tmp1].min=tmpr;
	tmpr+=r;
	this[n][tmp1].cur=tmpr;
	this[n][tmp1].max=tmpr;
	
	}

}

Array.prototype.setRange=setRange;

function countArray()
{
var a = arguments[0];
	if(!isNaN(parseInt(a)))
	{
		for(na=0;na<a;na++)
		{
		this[na]=na;
		}
	}
	else
	{
	this[0]=0;
	}
}

Array.prototype.countArray=countArray;

//WINDOW

function getContactWin()
{
var strf="width=500,height=400,directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no";
var wincontact=window.open("../contact/contactusfloat.html","contactusfloat",strf);
wincontact.moveTo((screen.width/2-200),(screen.height/2-125));

}


// IMAGE BLOCK

//set image in buffer
function placeRollImages()
{
//var dbody=d.getElementsByTagName("BODY")[0];
var tmparr=d.getElementsByTagName("IMG");
	for(ia=0;ia<tmparr.length;ia++)
	{
	var tmpi=tmparr[ia];
	tmpi.roll=tmpi.getAttribute('roll');
		if(tmpi.roll)
		{
		d.img[tmpi.name]=new Array();
		d.img[tmpi.name][0]=new Image();
		d.img[tmpi.name][0].src=tmpi.src;
		d.img[tmpi.name][1]=new Image();
		d.img[tmpi.name][1].src=getNewSrc(tmpi.src,tmpi.roll);
		}
	}
}


//rollover image, over
function rollImgOver(arg)
{
	if(arg&&d.img&&d.img[arg.name]&&d.img[arg.name][1])
	arg.src=d.img[arg.name][1].src;
	//alert(arg.name);
	//alert(document.img[arg.name][1].src);
}

//rollover image, out
function rollImgOut(arg)
{
	if(arg&&d.img&&d.img[arg.name]&&d.img[arg.name][0])
	arg.src=d.img[arg.name][0].src;
	//alert(arg.name);
}


function getLogoSet()
{
var arClogo=new Array();
var tmparr1=new Array();
tmparr1.countArray(d.cust.logoscount);
var cn=0;
	while(arClogo.length<6)
	{
	var tmprand=Math.floor(Math.random()*d.cust.logoscount);
		if(tmparr1[tmprand]!=-1)
		{
		arClogo[cn]=tmparr1[tmprand];
		tmparr1[tmprand]=-1;
		cn++;
		}
	if(cn>5)
	break;
	}
return arClogo;
}


//preload images of customers logos
function preloadLogos() {
    return;
    var logosnum=getLogoSet();
	for(nca=0;nca<6;nca++)
	{
	d.img.logosimg[nca]=new Image();
	d.img.logosimg[nca].src=d.cust.logospath+"logos"+logosnum[nca]+".png";
	}
}

function setLogosImg()
{
var cd=0;
var strset=new Array();
	for(nd=0;nd<6;(nd=nd+3))
	{
	var str="";
	str+=formatStrLogosImg(nd)+"<br>";
	str+=formatStrLogosImg(nd+1)+"<br>";
	str+=formatStrLogosImg(nd+2);
	strset[cd]=str;
	cd++;
	}
d.getElementById("custlogol").innerHTML=strset[0];
d.getElementById("custlogor").innerHTML=strset[1];
}

function formatStrLogosImg(arg)
{
return "<img class='custlogoel' id='ilc"+arg+"'>";
}

//roll customer logotypes
function rollCustLogos()
{
	for(ncb=0;ncb<6;ncb++)
	{
	d.getElementById("ilc"+ncb).src=d.img.logosimg[ncb].src;
	}
preloadLogos();
}


// CALCULATE BLOCK

//function for calculate
function showCost()
{
var tmpcount = parseInt(d.getElementById("iTeamMembers").value);
	if(!isNaN(tmpcount))
	{
	tmpcount=Math.abs(tmpcount);
	d.getElementById('totalcost').innerHTML=(tmpcount*40*34);
	d.getElementById('totalhrs').innerHTML=(tmpcount*34);
	d.getElementById('dailycost').innerHTML=(tmpcount*40*34/20);
	d.getElementById('dailyhrs').innerHTML=(tmpcount*34/20);
	d.getElementById("iTeamMembers").value=tmpcount;
	}
	else
	{
	d.getElementById("iTeamMembers").value='number, please';
	//d.getElementById("iTeamMembers").focus();
	d.getElementById("iTeamMembers").select();
	}
}


////////////// CUSTOMERS ROTATION BLOCK


function setCustomer(arg)
{
	if(!arg)
	{
		d.getElementById("custName").innerHTML=d.cust.arr[arg][0];
		d.getElementById("custText").innerHTML=d.cust.arr[arg][1];
		d.tmp.cust=arg;
	}
}


function getCustomerNum(arg)
{
var tmpget=null;
	if(!isNaN(arg))
	{
	var tmpcur=d.cust.arr;
		for(n=0;n<tmpcur.length;n++)
		{
			if((n!=d.tmp.cust)&&(arg>=tmpcur[n][2].min)&&(arg<=tmpcur[n][2].cur))
			{
			tmpget=tmpcur[n];
			tmpcur[n][2].cur=tmpcur[n][2].min;
			d.tmp.cust=n;
			}
			else
			{
			
				if(tmpcur[n][2].cur<tmpcur[n][2].max)
				tmpcur[n][2].cur++;
			}
		}
	}
	if(!tmpget)
	return getCustomer();
	else
	return tmpget;
}


function getCustomer()
{
var tmpnum=Math.round(Math.random()*100);
var tmpget=getCustomerNum(tmpnum);
//debuggThis(tmpnum+"<br>"+tmpget);
return tmpget;
}


function rollCustomers()
{
var tmpcust=getCustomer();

	if((tmpcust)&&(d.getElementById("custName")))
	{
		d.getElementById("custName").innerHTML=tmpcust[0];
		d.getElementById("custText").innerHTML=tmpcust[1];
		rollCustLogos();
	}
}




function timerCustomers()
{
d.cust.timerObj=setInterval("rollCustomers()",d.cust.timerNum);
}



//function-helpers

function getNameFromSrc(arg)
{
	if((arg)&&(String(arg)!="undefined"))
	{
	var tmp1=String(arg).split("/");
	return tmp1[tmp1.length-1];
	}
return null;
}

//get src for image
function getNewSrc(arg1,arg2)
{
	if(((arg1)&&(String(arg1)!="undefined"))&&((arg2)&&(String(arg2)!="undefined")))
	{
	var tmp1=String(arg1).split("/");
	tmp1[tmp1.length-1]=String(arg2);
	return tmp1.join("/");	
	}
}

function debuggThis(arg)
{
	if((d.tmp.debuggers)&&(arg))
	d.tmp.debuggers.innerHTML=arg;
}

////////////  ONLOAD ////////////////

function UpdateLink() {
    if(d.getElementById("stumbleuponLink"))d.getElementById("stumbleuponLink").href += d.location.href;
	if(d.getElementById("deliciousLink"))d.getElementById("deliciousLink").href += d.location.href;
	if(d.getElementById("diggLink"))d.getElementById("diggLink").href += d.location.href;
}


            function GetReferral(){
                if(typeof(d.location.search)!='undefined'){
                    var tmp = d.location.search.replace("?", "").toLowerCase();
                    var params = tmp.split("&");
                    for(var i=0; i<params.length; i++){
                        if(params[i].indexOf("referral")==0){
                            var value = params[i].split("=");
                            if(value.length==2){
		                        var date = new Date();
		                        date.setTime(date.getTime()+(3650*24*60*60*1000));//10 years from now
		                        var expires = "; expires="+date.toGMTString();                               
                                d.cookie = "ReferralCode=" + value[1] + expires + "; path=/";                              
                                return;
                            }
                        }
                    }
                }
            }



function onLoadActionHome()
{
d.tmp.debuggers=d.getElementById("debugger");
placeRollImages();
d.cust.arr.setRange();
preloadLogos();
setLogosImg();
rollCustomers();
timerCustomers();
UpdateLink();
GetReferral();
ShowEbookPopUp();
}

function onLoadAction()
{
//placeRollImages();
//d.cust.arr.setRange();
UpdateLink();
GetReferral();
}

function convertToHTML1(arg)
{
arg=String(arg);
var strreturn="";
	if(arg!="undefined")
	{
	var ar1=arg.split("\r\n");
	var rd=1;
	//alert(ar1.length);
		for(ia=0;ia<ar1.length;ia++)
		{
		var ar2=ar1[ia].split("\t");
			if(ar2.length==1)
			{
			strreturn+="<div class='listHead'>"+ar2[0]+"</div>";
			}
			else
			{
			strreturn+="<div class='listTxt"+rd+"'><div class='listTxtEl1'>"+ar2[0]+"</div><div class='listTxtEl2'>"+ar2[1]+"</div></div>";
			rd++;
				if(rd>2)
				rd=1;
			}
		}
	}
return strreturn;
}

function outputHTML1()
{
var str=convertToHTML1(String(d.getElementById("inputtxt").value));
d.getElementById("outputdiv").innerHTML=str;
d.getElementById("outputtxt").value=str;
}

var contactUsPopup;
var freezeLayer;

function getDocHeight() {
    return Math.max(
        Math.max(d.body.scrollHeight, d.documentElement.scrollHeight),
        Math.max(d.body.offsetHeight, d.documentElement.offsetHeight),
        Math.max(d.body.clientHeight, d.documentElement.clientHeight)
    );
}

function CreateFreezeLayer(){
	if (!freezeLayer) {
		freezeLayer = document.createElement('div');
		freezeLayer.id = "freezeLayer";		
				
		freezeLayer.style.position = "absolute";
		freezeLayer.style.display = "none";
		freezeLayer.style.top = "0px";
		freezeLayer.style.left = "0px";
		freezeLayer.style.backgroundColor = "#000";
		freezeLayer.style.height = getDocHeight() + "px";
		freezeLayer.style.width = "100%";
		freezeLayer.style.filter = "alpha(opacity=80);";
		freezeLayer.style.opacity ="0.8";
		
		document.body.appendChild(freezeLayer);
	}
}

function InitContactUs(){
	CreateFreezeLayer();	
	if(!contactUsPopup){
		contactUsPopup = document.createElement('div');
		contactUsPopup.id = "contact_us_popup";
		
		//freezeLayer.appendChild(contactUsPopup);
		document.body.appendChild(contactUsPopup);
		
		var contactUsTop = document.createElement('div');
		contactUsTop.id = "contact_us_top";			
		contactUsPopup.appendChild(contactUsTop);
		
		
		var contactUsTopHref = document.createElement('a');
		contactUsTopHref.href = "javascript:HideContactUs()";
		contactUsTop.appendChild(contactUsTopHref);
						
		var contactUsTopHrefImg = document.createElement('img');
		contactUsTopHrefImg.src = "/images/contact_us_close_btn.png";		
		contactUsTopHref.appendChild(contactUsTopHrefImg);
		
		contactUsPopup.appendChild(document.createElement('br'));
		
		var contactUsCenter = document.createElement('center');
		contactUsPopup.appendChild(contactUsCenter);
		
		var contactUsContent = document.createElement('div');	
		contactUsContent.id = "contact_us_content";	
		contactUsCenter.appendChild(contactUsContent);					
		
		var contactUsContentSalesTitle = document.createElement('p');
		contactUsContentSalesTitle.className = "contact_us_title";		
		contactUsContentSalesTitle.innerHTML = "Sales";
		contactUsContent.appendChild(contactUsContentSalesTitle);
				
		var contactUsContentSales = document.createElement('p');
		contactUsContent.appendChild(contactUsContentSales);
		
		var contactUsContentFont = document.createElement('font');
		contactUsContentFont.className = "contact_us_cat";
		contactUsContentFont.innerHTML = "Toll free: ";
		contactUsContentSales.appendChild(contactUsContentFont);
		contactUsContentSales.appendChild(document.createTextNode("877.465.7230"));
		contactUsContentSales.appendChild(document.createElement('br'));
		
		var tempFont = contactUsContentFont.cloneNode(true);
		tempFont.innerHTML = "International: ";
		contactUsContentSales.appendChild(tempFont);
		contactUsContentSales.appendChild(document.createTextNode("1.646.688.2889"));
				
		var contactUsContentSupportTitle = document.createElement('p');
		contactUsContentSupportTitle.className = "contact_us_p contact_us_title";
		contactUsContentSupportTitle.innerHTML = "Support";
		contactUsContent.appendChild(contactUsContentSupportTitle);
		
		var contactUsContentSupport = document.createElement('p');
		contactUsContent.appendChild(contactUsContentSupport);
			
		tempFont = contactUsContentFont.cloneNode(true);
		tempFont.innerHTML = "Toll free: ";
		contactUsContentSupport.appendChild(tempFont);
		contactUsContentSupport.appendChild(document.createTextNode("877.425.9961"));
		contactUsContentSupport.appendChild(document.createElement('br'));
		
		tempFont = contactUsContentFont.cloneNode(true);
		tempFont.innerHTML = "International: ";
		contactUsContentSupport.appendChild(tempFont);
		contactUsContentSupport.appendChild(document.createTextNode("1.646.290.5550"));
		
		var contactUsContentEmailTitle = document.createElement('p');
		contactUsContentEmailTitle.className = "contact_us_p contact_us_title";
		contactUsContentEmailTitle.innerHTML = "E-mail";
		contactUsContent.appendChild(contactUsContentEmailTitle);
		
		var contactUsContentEmail = document.createElement('p');
		contactUsContentEmail.style.textAlign = "center";
		contactUsContent.appendChild(contactUsContentEmail);
		
		var contactUsContentEmailA = document.createElement('a');
		contactUsContentEmailA.href = "mailto:support@elementool.com";
		contactUsContentEmailA.innerHTML = "support@elementool.com";
		contactUsContentEmail.appendChild(contactUsContentEmailA);
	}
		
	SetPosition(contactUsPopup,514, 371);
}

function SetPosition(el, contactUsWidth, contactUsHeight) {
    var postop, posleft;

    // Get visible pagesize
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        // all without MSIE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        // IE6+
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        // IE4
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }

    // Scroll?
    var scrOfX = 0, scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        // Netscape ans other
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        // DOM
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        // IE6
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    
    postop = Math.round((myHeight - contactUsHeight) / 2) + scrOfY; 
    posleft = Math.round((myWidth - contactUsWidth) / 2) + scrOfX;
    
	el.style.left = posleft + "px";
    el.style.top = postop + "px";                    
    //adjust body height here to avoid IE bug.
}

function ShowContactUs(){
	InitContactUs();
	freezeLayer.style.display = "block";   
	contactUsPopup.style.display = "block";    
}

//function HideContactUs(){
//    freezeLayer.style.display = "none";
//}
function HideContactUs(){
    freezeLayer.style.display = "none";
    contactUsPopup.style.display = "none";  
}
