 /*Ajax component Of JavaScript: used to get xml Response*/
  
function kz_alert(message) {
	//alert(message);
}

/*My core ajax class*/
//Global variables

var accountId=Get_Cookie("accountId");
var map = null;
var dayviewmap = null;
var geocoder = null;
var rgeocoder = null;
var dayviewgeocoder = null;
var posturlForStoringMap = null;
var postStringStoringMap = null;
var point = null;
var localSearch = null;
var rGeocodeSiteAddress = null;
var rGeocodeSitePostcode = null;

function CoreAjax(url, method, asyn, handler, isPublic)
{	
	
	isPublic = (typeof isPublic == 'undefined') ? 'False' : isPublic;
	
	var user = Get_Cookie("username");
	var pass = Get_Cookie("password");
	
	if ( ( user == null || pass == null || user == "" || pass == "") && isPublic == 'False'){
		alert("You haven't logged in or your login details has expired, please log in again!");
		
		window.top.location = "/console/login.php";
		
	} else {
		if(user == null || user == "") {
			user = 'guest';
			pass = 'guest';
		}

		if(url.indexOf('?') == -1) {
			url=url+ "?";	
		}
		
		var acctId = Get_Cookie("accountId");
		if(acctId != null && acctId != "") 
			url = url + "&accountId=" + acctId;
      	
		
		if( url =="dashboard.xml" || url =="1-live.xml" || url=="test.xml" || url=="visu/visuother/expense.xml"|| url=="visu/visuother/circlexml.xml"){				
				url=url;
		}
		
		url=url+ "&username="+user;
		
		var httpMethod = method;
		var async=asyn;
		var handleResp=handler;
		var responseFormat='xml';
		var mimeType='text/xml';
		
		var updating = false;
		var flag = true;
		
		kz_alert (user+"  "+pass);
		this.doReq=function(postData){
			
			if(updating==true) {
				return false;
			}
			updating=true;
			kz_alert('going into init');
			var req = this.init();
			
			if(!req || req==null){
				kz_alert('Could not create XMLHttpRequest object');
				return false;		
			}
			kz_alert('The current Url being dealt with is: '+url);
			
			kz_alert("start open");
				
			
			req.open(httpMethod,url,async);
			
			kz_alert("finish open");
			
			req.setRequestHeader('tcAPIPassword',pass);
			req.setRequestHeader("tcAPIAgent","mobibizlive.co.uk.TCConsole.1.0-FS");

			if(httpMethod=='POST') {
				kz_alert('in post');
				req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
				
				req.setRequestHeader("Content-length", postData);
				req.setRequestHeader("Connection", "close");
				
				kz_alert('after setting');
			}
			
	
			req.onreadystatechange=function()
			{
				var resp=null;
				kz_alert(req.readyState);
				if(req.readyState==4 || req.readyState=="complete")
				{
					//Handle the Response
					var accId = req.getResponseHeader("accountId");
					
					if (accId != null && accId != ""){
						kz_alert("Account Id is " + accId);
						//Set_Cookie("accountId",accId,24);
						var date = new Date();
						date.setTime(date.getTime()+(365*24*60*60*1000));
						var expires = "; expires="+date.toGMTString(); 
						document.cookie = "accountId="+accId+"; path=/;" +expires;
					}
					
					switch(responseFormat)
					{
						case 'text':
							resp=req.responseText;
							break;
						
						case 'xml':
							//we are expecting only xml
							resp=req.responseXML;
							if(resp==null) {
								// For Mozilla, if this happens then xml is null or not well formed
								kz_alert('returned xml is null or not well formed');
							} else if(resp.documentElement == null) {
								// For IE, if this happens then xml is null or not well formed
								kz_alert('returned xml is null or not well formed');
								resp = null;
							}
							break;
						
						case 'object':
							break;
					}
				
					if(req.status>=200) 
					{
						kz_alert(req.status);
						if(req.status<=299)
						{
							if(resp != null && handleResp != null)
								handleResp(resp);
						}
						if ((req.status >=400 && req.status <=500)||req.status == 1223 ){
							kz_alert ("Unauthorized or server error");
							flag =  false;
							
							var sPath = window.location.pathname;
							var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
							
							if(sPage == "login.php" || sPage == "" || sPage == null){
								alert("Login failed!");
								history.go();	
							}
						}
					}
					else 
					{
						kz_alert('error in response');
						handleErr(resp);
					}
					updating=false;
				}
			};	
			
			kz_alert("sending " + postData);
			
			
			req.send(postData);
			if (flag)
				return true;
			else
				return false;
		};
		
		this.init=function()
		{		
			//Mozilla ,Safari 
			//and IE7
			if(window.XMLHttpRequest)
			{				
				try{
					req=new XMLHttpRequest();					
				}catch(e){					
					return false;
				}			
			} 
			// IE 6 and earlier
			else if(window.ActiveXObject) {
				try{
					req=new ActiveXObject('MSXML2.XMLHTTP');
				}catch(e)	{
					try{
						req=new ActiveXObject('Microsoft.XMLHTTP');
					}catch(e){
						return false;
					}
				}
			}
			
			return req;
			
		}
	}
}

//loads google key dynamically to the page
function staticLoadScript(url){
	if(location.host=="www.mobibizlive.com" || location.host=="mobibizlive.com"){	//.com
		
		document.write('<script src="', 'http://maps.google.com/maps?file=api&amp;V=2.123&amp;key=ABQIAAAAkeslwGrPmK4w95ZCxn5EhxRpGBHbAe2iaSEgqpcxShcEYz9VZhQAHTkTnWam6ITyxRX2Melllv1GhA', '" type="text/JavaScript"><\/script>');
		document.write('<script src="', 'http://www.google.com/uds/api?file=uds.js&v=1.0&key=ABQIAAAAkeslwGrPmK4w95ZCxn5EhxRpGBHbAe2iaSEgqpcxShcEYz9VZhQAHTkTnWam6ITyxRX2Melllv1GhA', '" type="text/JavaScript"><\/script>');
	
	}else if(location.host=="ec2-174-129-23-54.compute-1.amazonaws.com"){	//aws US
		
		document.write('<script src="', 'http://maps.google.com/maps?file=api&amp;V=2.123&amp;key=ABQIAAAAkeslwGrPmK4w95ZCxn5EhxQJ86wAGajHYEpKUwweGlweFxEnPhThtErbzAvmUpqc9xlLTPRpSD1FYw', '" type="text/JavaScript"><\/script>');
		document.write('<script src="', 'http://www.google.com/uds/api?file=uds.js&v=1.0&key=ABQIAAAAkeslwGrPmK4w95ZCxn5EhxQJ86wAGajHYEpKUwweGlweFxEnPhThtErbzAvmUpqc9xlLTPRpSD1FYw', '" type="text/JavaScript"><\/script>');
	
	}else {	//.co.uk
		
		document.write('<script src="', 'http://maps.google.com/maps?file=api&amp;V=2.123&amp;key=ABQIAAAAqWryCG6JtZP37PvTJxC82BSJyHN-DKJjVdgl3riLhc__9DhjohSNTwPQBsIcuDCEnvlnn6TMYHBmzg', '" type="text/JavaScript"><\/script>');
		document.write('<script src="', 'http://www.google.com/uds/api?file=uds.js&v=1.0&key=ABQIAAAAqWryCG6JtZP37PvTJxC82BSJyHN-DKJjVdgl3riLhc__9DhjohSNTwPQBsIcuDCEnvlnn6TMYHBmzg', '" type="text/JavaScript"><\/script>');
	}
	
	/*old key
	<script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAqWryCG6JtZP37PvTJxC82BSJyHN-DKJjVdgl3riLhc__9DhjohSNTwPQBsIcuDCEnvlnn6TMYHBmzg" type="text/javascript"></script>
	<script src="http://www.google.com/uds/api?file=uds.js&v=1.0&key=ABQIAAAAplhVBNFkMmf-hgRmAxTUnRSJyHN-DKJjVdgl3riLhc__9DhjohRKNG5TlBGxAPbybR0AEboKN9Nvrg" type="text/javascript"></script>
	*/
}

function GetEmployeeCookie (){	
	var usern = Get_Cookie("username");	
	var empcook=Get_Cookie(usern+"EmployeeListCookie");
	
	return empcook;
}



function EmployeeVO()
{
 	this.emkz_alert ="";
	this.latitude=0.0;
	this.longitude=0.0;
	this.latEnd=0.0;
	this.longEnd=0.0;
	this.startTime=null;
	this.endTime=null;
	this.schedStartTime=null;
	this.schedEndTime=null;
	this.startRecordedAt = null;
	this.endRecordedAt = null;
	this.empId=-1;
	this.empPin=null;
	this.empEndPin=null;
	this.hide=0;
	this.attendanceDate=null;
	this.schedStDay=null;
	this.schedEdDay=null;
	this.startDay=null;
	this.endDay=null;
	this.attendanceType=null;
	this.status="No Data";
	this.statusEnd=null;
	this.firstName=null;
	this.lastName=null;
	this.projVO=null;
	this.note="";
	this.OT = 0;
	this.color=null;
	this.totalTime=null;
	this.state = null;
	this.crew = "";
	this.phone = null;
	this.operator = null;
	this.optIn = true;
	this.shiftUnverified = false;
	this.shiftAuthorized = false;
	this.accuracy = 0;
	this.endAccuracy = 0;
	this.startAttendanceId=-1;
	this.endAttendanceId=-1;
	this.shiftId = -1;
	this.badgeNumber = null;
}

function ProjectVO()
{
	this.id=-1;
	this.jobCode = "";
	this.jobName = "";
	this.jobId = -1;
	this.addressLine1="";
	this.addressLine2="";
	this.siteType=null;
	this.city="";
	this.postCode=null;
	this.country=null;
	this.name="";
	this.accId=-1;
	this.verified=null;
	this.status=null;
	this.cordX=0;
	this.cordY=0;
	this.cords=null;
	this.projPin=null;
	this.hide=0;
	this.hasCords=false;
	this.latitude=null;
	this.longitude=null;
	this.outOfZone = false;
	this.createdBy = "";
	this.taskCode = "";
	this.creationDate = "";
}



function getDateTime(ddtt){
 	var arr=ddtt.split('T');
	return arr;
}

/* Add two times of format HH:MM */
function addTimes(a,b)
{
	var hour = 0;
	var mins = 0;
	var st = a.split(":");
	var ed = b.split(":");
	var sthour = st[0];
	var stmin = st[1];
	var edhour = ed[0];
	var edmin = ed[1];
	hour = (+sthour) + (+edhour);
	mins = (+stmin) + (+edmin);
	while(mins >= 60) {
		mins = mins - 60;
		hour = hour + 1;
	} 

  if(hour < 10) {
    hour = "0" + parseInt(hour);
  }
  
  if(mins < 10) {
    mins = "0" + parseInt(mins);
  }
  
  return hour+":"+mins;
	
}


function diffDates(s, e){
  var st = new Date();
  var ed = new Date();
  var pArray = s[0].split("-");
  var pyear = pArray[0];
  var pmonth = pArray[1];
  var pdate = pArray[2];
  
  st.setFullYear((+pyear), (+pmonth), (+pdate));
  pArray = s[1].split(":");
  var phour = pArray[0];
  var pmin = pArray[1];
  var psec = pArray[2];
  st.setHours((+phour), (+pmin), (+psec));
  
  var nArray = e[0].split("-");
  pyear = nArray[0];
  pmonth = nArray[1];
  pdate = nArray[2];
  
  ed.setFullYear((+pyear), (+pmonth), (+pdate));
  nArray = e[1].split(":");
  phour = nArray[0];
  pmin = nArray[1];
  psec = nArray[2];
  ed.setHours((+phour), (+pmin), (+psec));
  
  var dif = ed.getTime() - st.getTime();
  var hour = dif/(1000*60*60);
  
  var mins = dif - (parseInt(hour)*(60*60*1000));
  mins = mins/(1000*60);
  hour = parseInt(hour);
  mins = parseInt(mins);
  
  if(hour < 10) {
    hour = "0" + parseInt(hour);
  }
  
  if(mins < 10) {
    mins = "0" + parseInt(mins);
  }
  
  return hour+":"+mins;
  
}

function changeDateFormat(dFormat){
	var pArray = dFormat.split(',');
	var pyear = pArray[1].substring(1);
	var md = pArray[0].split(' ');
	var pday = md[1];
	var pmonth;
	switch (md[0]){
		case 'Jan':
			pmonth = '01';
			break;
		case 'Feb':
			pmonth = '02';
			break;
		case 'Mar':
			pmonth = '03';
			break;
		case 'Apr':
			pmonth = '04';
			break;
		case 'May':
			pmonth = '05';
			break;
		case 'Jun':
			pmonth = '06';
			break;
		case 'Jul':
			pmonth = '07';
			break;
		case 'Aug':
			pmonth = '08';
			break;
		case 'Sep':
			pmonth = '09';
			break;
		case 'Oct':
			pmonth = '10';
			break;

		case 'Nov':
			pmonth = '11';
			break;
		case 'Dec':
			pmonth = '12';
			break;
	}
	if(pday.length==1)
		pday="0"+pday;
	return (pyear+'/'+pmonth+'/'+pday);
}

// change date format from dd/mm/yyyy to yyyy/mm/dd
function changeDateFormatToYYMMDD(dFormat){
	var pArray = dFormat.split('/');
	return (pArray[2]+'/'+pArray[1]+'/'+pArray[0]);
}

function Get_Cookie( name ) {
	
	var start = -1;
	start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( start == -1 ) return null;

	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function Set_Cookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

//show loading image on the MAIN page. 
//var state = 'none';
function showhideloading(layer_ref,state) {
	kz_alert("in showhideloading");	
	if (state == 'block') {
		top.document.getElementById(layer_ref).style.display="block";
			
	}else{ 
		top.document.getElementById(layer_ref).style.display="none";
		
	}	
}

//show loading image on the map sidebar
function showmaploading(layer_ref,state) {         
   if (state == 'block') {
		document.getElementById(layer_ref).style.display="block";		
	}else{ 
		document.getElementById(layer_ref).style.display="none";		
	}	
}

// set the current page on load, so that on reload iframe loads the same page
function setcurrentpage(pagename) {		
	document.cookie = "currentpage="+pagename+"; path=/;";
	
	//change daily tip in main page
	showdailytip();
}

//show daily tip box
function showdailytip(){
	var dailytip=new Array() // do not change this!
	//dailytip[0] = "Tip of the day: Click on the day in the left panel calendar to view activity on that day";
	
	//Dashboard
	if(Get_Cookie("currentpage")=="dashboard.php"){
		dailytip[0] = "Click on the day in the left panel calendar to view activity on that day";
	}
	//Job
	else if(Get_Cookie("currentpage")=="viewproject.php"){
		dailytip[0] = "Check Unverified entries and Select Job from the drop-down to verify with existing jobs.";
	}
	//Employees
	else if(Get_Cookie("currentpage")=="viewall.php"){
		dailytip[0] = "Doubleclick cells to change employees information. Un-tick employees if you would like to hide their information.";
	}
	//Dayview
	else if(Get_Cookie("currentpage")=="dayview.php"){
		dailytip[0] = "Click on the day in the left panel calendar to view activity on that day";
	}
	//Weekview
	else if(Get_Cookie("currentpage")=="weekview.php"){
		dailytip[0] = "Use Search Employee search box to load recorded data for the week.";
	 }
	//Payrollview
	else if(Get_Cookie("currentpage")=="payrollview.php"){
		dailytip[0] = "Expand payrollview to see more information. Doubleclick times to change them.";
		dailytip[1] = "Click Authorize to finalize and export timesheet.";
	}else
		dailytip[0] = "Click on the day in the left panel calendar to view activity on that day";
	
	
	var l = dailytip.length;
	var randomdailytip=Math.round(Math.random()*(l-1));
	
	var tipcookie= Get_Cookie("tipcookie")
	if(!tipcookie && tipcookie!=1)
		top.document.getElementById("dailytip").innerHTML="<a href='#' id='tipx' onclick='hidetip()' >x</a> Tip of the day: "+dailytip[randomdailytip];
	else
		top.document.getElementById("dailytip").style.display="none";
}
//hide daily tip box for a 24hours
function hidetip(){
	top.document.getElementById("dailytip").style.display="none";
	
	var date = new Date();
	date.setTime(date.getTime()+(24*60*60*1000));
	var expires = "; expires="+date.toGMTString(); 
	top.document.cookie = "tipcookie=1; path=/;" +expires;
}

// get the current page on refresh from a cookie and set it on iframe src
function currentpage() {						
	var currentpage = Get_Cookie ( "currentpage" );
	if (currentpage == null)
		document.getElementById('califrame').src="dashboard.php";
	else		
		document.getElementById('califrame').src=currentpage;		 
}

function makequick(qu0){
 	var user = Get_Cookie("username");
	var quick=Get_Cookie(user+"quick");

	if(quick != null){
		var qucookie = quick.split("^");		
	
		if( qucookie[0]!= null)
			var qu1 = qucookie[0];		
		else
			var qu1 = "";		
		if( qucookie[1]!= null)
			var qu2 = qucookie[1];
		else
			var qu2 = "";			
		if( qucookie[2]!= null)
			var qu3 = qucookie[2];
		else
			var qu3 = "";			
		if( qucookie[3]!= null)
			var qu4 = qucookie[3];
		else
			var qu4 = "";
		
		var qu5= qucookie[4];
	}
	else	{
		var qu1="";
		var qu2="";
		var qu3="";
		var qu4="";
	}
		
	if(qu0==qu1)
		var quall=qu1+"^"+qu2+"^"+qu3+"^"+qu4+"^"+qu5;
	else if(qu0==qu2)
		var quall=qu2+"^"+qu1+"^"+qu3+"^"+qu4+"^"+qu5;
	else if(qu0==qu3)
		var quall=qu3+"^"+qu1+"^"+qu2+"^"+qu4+"^"+qu5;
	else if(qu0==qu4)
		var quall=qu4+"^"+qu1+"^"+qu2+"^"+qu3+"^"+qu5;
	else
		var quall=qu0+"^"+qu1+"^"+qu2+"^"+qu3+"^"+qu4;
	
	document.cookie=user+"quick="+quall+";path=/";	
	
	//update quicklink links in the mainmenu
	getquick();	
}



//generate mainmenu  quicklink links
function getquick(){	
	
	var user = Get_Cookie("username");
	if(Get_Cookie(user+"quick")){var qu=Get_Cookie(user+"quick");
	
	var qu2 = qu.split("^");
				
	for(var p=0; p<qu2.length-1; p++){
		var qu3 = qu2[p].split(":");
		var pp=p+2;
		
		//dayview
		if(qu3[0] == "D"){	
			var day = qu3[1];
			var jo = qu3[2];
			var pro = qu3[4];	
			var rr1 ="<a href=\"#\"  title=\"Open "+ day+" on job:"+jo+" and site:"+pro+"\" onclick=\"quick('"+qu2[p]+"')\">";
			var rr2 =day;
			if(jo)
				rr2 +=", on "+jo +":"+ pro;			
			if(rr2.length > 27)
				rr2 = rr2.substr(0,27)+" ...";
			var rr =rr1+rr2+"</a>";
			parent.document.getElementById(pp).innerHTML=rr;
		}
		//weekview
		else if(qu3[0] == "W"){	
			var day = qu3[1];
			var jo = qu3[2];
			var pro = qu3[4];				
			var rr1 ="<a href=\"#\" title=\"Open week "+ day+" on job:"+jo+" and site:"+pro+"\" onclick=\"quick('"+qu2[p]+"')\">w/e ";				
			var rr2 =day;
			if(jo)
				rr2 +=", on "+jo +":"+ pro;			
			if(rr2.length > 23)
				rr2 = rr2.substr(0,23)+" ...";
			var rr =rr1+rr2+"</a>";
			parent.document.getElementById(pp).innerHTML=rr;
		}
		//monthview
		else if(qu3[0] == "M"){	
			var day = qu3[1];
			var day =day.split(",");
			var day =day[0].split(" ");
			var jo = qu3[2];
			var pro = qu3[4];
			var ena = qu3[5];				
			var rr1 ="<a href=\"#\" title=\"Open month "+ day[0]+" on job:"+jo+" and site:"+pro+" for emplyee:"+ena+"\" onclick=\"quick('"+qu2[p]+"')\">Month :";
			var rr2 =day[0];
			if(jo)
				rr2 +=", on "+jo +":"+ pro+","+ena;			
			if(rr2.length > 23)
				rr2 = rr2.substr(0,23)+" ...";
			var rr3 =rr1+rr2+"</a>";
			top.document.getElementById(pp).innerHTML=rr3;
		}
		//siteview
		else if(qu3[0] == "J"){					
			var jo = qu3[1];
			
			var pro = qu3[2];				
			var rr ="<a href=\"#\" title=\"Open jobs page\" onclick=\"quick('"+qu2[p]+"')\">View jobs</a>";
						
			top.document.getElementById(pp).innerHTML=rr;
		}
		//employee view
		else if(qu3[0] == "E"){	
			var rr ="<a href=\"#\" title=\"Open employees page\" onclick=\"quick('"+qu2[p]+"')\">View Employees</a>";				
			top.document.getElementById(pp).innerHTML=rr;
		}
		else if(qu3[0] == "B"){	
			var rr ="<a href=\"#\" title=\"Open dashboard page\" onclick=\"quick('"+qu2[p]+"')\">Dashboard</a>";				
			top.document.getElementById(pp).innerHTML=rr;
		}
		else if(qu3[0] == "C"){	
			var rr ="<a href=\"#\" title=\"Open customview page\" onclick=\"quick('"+qu2[p]+"')\">Custom view</a>";				
			top.document.getElementById(pp).innerHTML=rr;
		}
		//filter search
		else if(qu3[0] == "F"){	
			var rr ="<a href=\"#\" title=\"Open filter page\" onclick=\"quick('"+qu2[p]+"')\">Search Filter </a>";				
			top.document.getElementById(pp).innerHTML=rr;
		}
		else if(qu3[0] == "R"){	
			var rr ="<a href=\"#\" title=\"Open report page\" onclick=\"quick('"+qu2[p]+"')\">Export report </a>";				
			top.document.getElementById(pp).innerHTML=rr;
		}
		//vehicle view
		else if(qu3[0] == "V"){	
			var rr ="<a href=\"#\" title=\"Open Vehicle page\" onclick=\"quick('"+qu2[p]+"')\">View Vehicle</a>";				
			top.document.getElementById(pp).innerHTML=rr;
		}
		//payrollview
		else if(qu3[0] == "P"){	
			var day = qu3[1];
			var jo = qu3[2];
			var pro = qu3[4];				
			var rr1 ="<a href=\"#\" title=\"Open payroll "+ day+" on job:"+jo+" and site:"+pro+"\"onclick=\"quick('"+qu2[p]+"')\">Payroll w/e:";			
			var rr2 =day;
			if(jo)
				rr2 +=", on "+jo +":"+ pro;			
			if(rr2.length > 15)
				rr2 = rr2.substr(0,15)+" ...";
			var rr =rr1+rr2+"</a>";
			top.document.getElementById(pp).innerHTML=rr;
		}
		//excel download
		else if(qu3[0] == "Excel"){
			var task=qu3[1];
			var day=qu3[2];
			var url2=qu3[3];
			var rr ="<a href=\"#\" title=\"Export Excel:"+task+" "+day +"\" onclick=\"quick('"+qu2[p]+"')\">Excel:"+task+" "+day +"</a>";
			
			top.document.getElementById(pp).innerHTML=rr;
		}
		else{}
	}
	
	var rr1 ="<a href=\"payrollview.php\" target=\"abc\" title=\"Payroll View \">Payroll w/e:";			

	top.document.getElementById(1).innerHTML=rr1;
	}
}

// if coming from track/ create employer site, then go to create_updateEmployee.php
function checktracksite(){
	var srchString = unescape(window.location.href.substring(1, window.location.href.length));			
	
	if (srchString.length > 0) {		
		srchString=srchString.split("&");
		srchString[2]=srchString[2].split("=");
		
		if(srchString[2][0]=="pId"){	
			srchString[3]=srchString[3].split("/");
			srchString[3][0]=srchString[3][0].replace("date=","");		
			var a=numberToMonth(srchString[3][1]-1);					
			var b=srchString[3][2];			
			var c=srchString[3][0];	
			var result=a +' '+ b+', '+c;			
			document.cookie="evtDate="+result+";path=/";
						
			var date = new Date();
				date.setTime(date.getTime()+(365*24*60*60*1000));
			var expires = "; expires="+date.toGMTString(); 
						
			//account id
			srchString[1]=srchString[1].split("=");			
			document.cookie = "accountId="+srchString[1][1]+"; expires=" + expires;	
			
			//partnerid			
			document.cookie = "partnerid="+srchString[2][1]+"; path=/" + expires;
			
			document.cookie = "currentpage=dayview.php; path=/ ;expires=" + expires;			
			
			document.cookie = "username=autotime; path=/" +expires;
			document.cookie = "password=autotime; path=/" +expires;
			//get employee list cookie
			usern = Get_Cookie("username");
			if(!Get_Cookie(usern+"EmployeeListCookie"))
				createEmpList();
						
			top.frames['abc'].location.href = '/console/dayview.php';				
		}
		else{
			//if coming from mobibizlive.com login
			srchString[1]=srchString[1].split("=");
			if(srchString[1][0]=="ka"){	
				var kaurl=window.location.href;				
				kaurl=decodeURIComponent(kaurl);				
				kaurl=kaurl.split("&");				
				kaurl[1]=kaurl[1].split("=");
				kaurl[2]=kaurl[2].split("=");
				
				var ka0=kaurl[1][1];				
				var ka=jarjesta(ka0);
				
				var sa0=kaurl[2][1];
				var sa=jarjesta(sa0);
				
				createPostRequest(ka, sa)			
			}	
		}
	}	
}


//if coming from mobibizlive.com login
function jarjesta(theText){
	output = new String;
	Temp = new Array();
	Temp2 = new Array();
	TextSize = theText.length;
	for (i = 0; i < TextSize; i++) {
		Temp[i] = theText.charCodeAt(i);
		Temp2[i] = theText.charCodeAt(i + 1);
	}
		for (i = 0; i < TextSize; i = i+2) {
		output += String.fromCharCode(Temp[i] - Temp2[i]);
	}
	return output;
}

var username2="";
var password2="";
//send login info and set cookies
function createPostRequest(username, password) {
	var cookie_date = new Date ( );  // current date & time
	cookie_date.setTime ( cookie_date.getTime() - 10000000 );
	document.cookie = "accountId=; path=/; expires=" + cookie_date.toGMTString();	
	
	username2=username;
	password2=password;
		
	//alert(username+password);
	xmlheader = '<'+'?'+'xml version="1.0" encoding="UTF-8"'+'?'+'><postRequest xmlns="urn:mobibiz:tc:api:v1"><login  username = "'+ username+'" password = "'+ password+'"/></postRequest>';
	//kz_alert(xmlheader);
	var req = null;	
	var ajaxPost=new CoreAjax('/tc/TimeCollection/servlet/MyLogin?','POST',true,timezone,'True');
	
	//if command below is always true now
	if(ajaxPost.doReq("input="+xmlheader)) {
		
		//if login is failed and timezone is not activated in 10 sec then alert
		//setTimeout('removelogins()', 30000);
			//alert("NNN")	
	} else {
		//not used anymore
		var cookie_date = new Date ( );  // current date & time
		cookie_date.setTime ( cookie_date.getTime() - 1 );
		document.cookie = "username=; path=/ ;expires=" + cookie_date.toGMTString();
		document.cookie = "password=; path=/ ;expires=" + cookie_date.toGMTString();
		
		alert("login failed");
		
		if(document.getElementById("hideme"))
			document.getElementById("hideme").style.display="none";
			
		location.replace("/console/login.php");				
	}
}

function removelogins(){
	var cookie_date = new Date ( );  // current date & time
	cookie_date.setTime ( cookie_date.getTime() - 1 );
	document.cookie = "username=; path=/ ;expires=" + cookie_date.toGMTString();
	document.cookie = "password=; path=/ ;expires=" + cookie_date.toGMTString();
		
	alert("login failed!");
		
	location.replace("/console/login.php");
}

var newurl=""
var redirectURI=""
function timezone(xml){				
	//alert(xml.xml)
	var response = xml.getElementsByTagName('response');
	var resp = response.item(0);			
	redirectURI=resp.attributes.getNamedItem("redirectURI").value;			
	//newurl="http://"+redirectURI+"/console/main.php"
		
	var requestElement = xml.getElementsByTagName('employer');
				
	var employer = requestElement.item(0);			
	var timezone=employer.attributes.getNamedItem("timezone").value;
	var gpsCollectionOn=employer.attributes.getNamedItem("gpsCollectionOn").value;
	var accountId=employer.attributes.getNamedItem("id").value;
	
	var date = new Date();
	date.setTime(date.getTime()+(24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	
	document.cookie = "accountId="+accountId+"; path=/;" +expires;
	
	var date = new Date();
		date.setTime(date.getTime()+(365*24*60*60*1000));
	var expires = "; expires="+date.toGMTString(); 
		
	document.cookie = "bst="+timezone+"; path=/" +expires;
	document.cookie ="employerGPSEnabled="+gpsCollectionOn+"; path=/" +expires;	
	
	if(employer.getElementsByTagName('accountAlert')){
		var accountAlert = employer.getElementsByTagName('accountAlert');
	
		document.cookie ="accountAlert=; path=/" +expires;				
		for(var emp=0;emp<accountAlert.length;emp++){	
			var al=accountAlert.item(emp).attributes;
			
			var actionLink = al.getNamedItem('actionLink').value;
			var actionName=al.getNamedItem('actionName').value;
			var subject=al.getNamedItem('subject').value;
			var message=al.getNamedItem('body').value;
			
			document.cookie ="accountAlert="+Get_Cookie("accountAlert")+"|"+actionLink+"^"+actionName+"^"+subject+"^"+message+"^"+"; path=/" +expires;	
		}	
	}
	redirect();	
}


function redirect(ka, sa) {
	if(redirectURI==""){
			var date = new Date();
			var curDate = null;
			do { curDate = new Date(); }
			while(curDate-date < 3000);
	}
	
	if(Get_Cookie("accountId") && Get_Cookie("accountId")!=null){		
		var curloca=location.host
		var curloca2=curloca.search(/www./i)
		if(curloca2==-1);
			curloca="www."+curloca;
		if(location.host == redirectURI || redirectURI=="localhost"  || location.host=="localhost"){
			var date = new Date();
			date.setTime(date.getTime()+(24*60*60*1000));
			var expires = "; expires="+date.toGMTString(); 
			document.cookie = "username="+username2+"; path=/" +expires;
			document.cookie = "password="+password2+"; path=/" +expires;
			
			location.replace("/console/main.php")				
		}else{
			var date = new Date ( );
			var ka=sotke(username2);
			var sa=sotke(password2);
			if(redirectURI!="localhost")		
				location.replace("http://"+redirectURI+"/console/maindir.php?current=dgjryfhg&ka="+ka+"&sa="+sa+"&date="+date);	
			else
				location.replace("/console/main.php");
		}
	}else{
		var cookie_date = new Date ( );  // current date & time
		cookie_date.setTime ( cookie_date.getTime() - 1 );
		document.cookie = "username=; path=/ ;expires=" + cookie_date.toGMTString();
		document.cookie = "password=; path=/ ;expires=" + cookie_date.toGMTString();
		
		alert("login failed");
		//cookie check
		var cookieon=cookieCheck();	
		if(cookieon==true){
			//setTimeout(redirect(username, password),2250);
		}
		location.replace("/console/login.php");	
	}	
}
function sotke(theText){
	
	output = new String;Temp = new Array();	Temp2 = new Array();TextSize = theText.length;
	for (i = 0; i < TextSize; i++){rnd = Math.round(Math.random() * 122) + 68;Temp[i] = theText.charCodeAt(i) + rnd;Temp2[i] = rnd;	}
	for (i = 0; i < TextSize; i++) {output += String.fromCharCode(Temp[i], Temp2[i]);}
	return output;
}


function createEmpList(){
	kz_alert("in doreq");
	var ajaxCore=null;
	var timestamp = new Date();
	ajaxCore=new CoreAjax('/tc/TimeCollection/servlet/Employee?tmst=' + (timestamp*1), 'GET', true, responseViewAllQuery);
	
	ajaxCore.doReq(null);
}

var ifempcookie=0;
var EmployeeListCookie="";
var empArray=new Array();
function responseViewAllQuery(xmlString){	
	kz_alert("In responseViewAllQuery");
	
	var requestElement = xmlString.getElementsByTagName('*');
	var firstChild = requestElement.item(1);
	
	var accountid=firstChild.attributes.getNamedItem('id').value	
	//alert(accountid)
	var date = new Date();
	date.setTime(date.getTime()+(24*60*60*1000));
	var expires = "; expires="+date.toGMTString(); 
	document.cookie = "accountId="+accountid+"; path=/;" +expires;
	
	switch(firstChild.tagName){		
		case 'employer': {
			var employerAttrs = firstChild.attributes;			
			var isGPSEnabledOnAccount = employerAttrs.getNamedItem('gpsCollectionOn');
						
			if(isGPSEnabledOnAccount==null || isGPSEnabledOnAccount.value == 'false')						
				document.cookie ="employerGPSEnabled=false; path=/";
			if(isGPSEnabledOnAccount && isGPSEnabledOnAccount.value == 'true')
				document.cookie ="employerGPSEnabled=true; path=/";
			/*
			if(Get_Cookie("employerGPSEnabled")=="false")
				top.document.getElementById("vehicle2").style.display="none";		
			else
				top.document.getElementById("vehicle2").style.display="block";
				*/		
			var employees = firstChild.getElementsByTagName('employee');
			var empIndex = 0;
			
			//cookie for alphabetical sorting
			document.cookie="table_length="+employees.length+";path=/";
						
			for(var emp=0;emp<employees.length;emp++){	
				var attendances=employees.item(emp).getElementsByTagName('attendance');					
				var attributeNode=employees.item(emp).attributes;
				
				var id =attributeNode.getNamedItem('id').value;		
				var superv = attributeNode.getNamedItem('isSupervisor').value;
				var lgname = attributeNode.getNamedItem('lastname').value;
				var fsname = attributeNode.getNamedItem('firstname').value;
				var lsname = attributeNode.getNamedItem('lastname').value;
				var optInValue = attributeNode.getNamedItem('optIn').value;					
							
				kz_alert("no attendance");
				var estate = attributeNode.getNamedItem('state').value;
				var number = attributeNode.getNamedItem('mobilePhone').value;
				//var crew = attributeNode.getNamedItem('crew').value;
				var operator = attributeNode.getNamedItem('operator').value;
				var badgeNumber = attributeNode.getNamedItem('badgeNumber').value;
				
				var empVO=new EmployeeVO();
				empVO.empId = id;
				empVO.optIn = optInValue;				
				empVO.loginName = lgname;
				empVO.firstName = fsname;
				empVO.lastName = lsname;
				empVO.state = estate;
				//empVO.crew = crew;
				empVO.phone = number;
				empVO.operator = operator;
				empVO.badgeNumber = badgeNumber;
				empVO.employeenumber = employees.length;
								
				if(EmployeeListCookie=="")
					EmployeeListCookie = id + "," + fsname + "," + lsname+ "," + number;				
				else
					EmployeeListCookie = EmployeeListCookie + "/" + id + "," + fsname + "," + lsname+ "," + number;
				
				usern = Get_Cookie("username");

				if(!Get_Cookie(usern+"EmployeeListCookie"))
					ifempcookie=1;
								
				if( ifempcookie==1)
					document.cookie =usern+"EmployeeListCookie=" + EmployeeListCookie + ";path=/;expires=Fri, 17 Dec 2010 10:00:00 GMT";
				
				//for alphabetical list
				document.cookie =usern+"empCookie=" + EmployeeListCookie + "; path=/";
				//display supervisor if true
				if(superv=="true")
					empVO.superv = "<img src=\"./images/main/user.png\" title=\"Supervisor\"  />";
				else
					empVO.superv ="";
					
				kz_alert("finish add");
				empArray[emp] = empVO;					
			}			
			break;
		}
	}
	
	SortEmployeeCookie();
	
	//sort by firstname
	empArray=nameSort(empArray);
	
	if(Get_Cookie("currentpage")=="viewall.php")
		showEmploy();
}

//double array sort. sort firstname then lastname
function nameSort(A){
	//alert(A[i].firstName)
    var tem, alphaSort= function(a, b){
        a= a.toLowerCase();
        b= b.toLowerCase();
        if(a== b) return 0;
        return a> b? 1: -1;
    }
    A.sort(function(a, b){
        return alphaSort(a.firstName, b.firstName) || alphaSort(a.lastName, b.lastName);
    })   
    return A;	
}

//sort the emp cookie in first name alphabetical order
var emparray="";
function SortEmployeeCookie(){	
	var usern = Get_Cookie("username");	
	var empcook=Get_Cookie(usern+"EmployeeListCookie");
	var emp4=empcook.split("/");
	for(var i=0; i<emp4.length; i++){
		emp4[i]=emp4[i].split(",");
		
		emp4[i].push(emp4[i][0])
		emp4[i].shift();		
	}	
	emp4=emp4.sort();
	for(var i=0; i<emp4.length; i++){
		//make emp4[i][3] to emp4[i][2] if you remove phonenumber
		emp4[i].unshift(emp4[i][3]);
		emp4[i].pop();
		if(emparray=="")
			emparray=emp4[i]
		else
			emparray=emparray +"/"+ emp4[i]
	}
	document.cookie =usern+"EmployeeListCookie=" + emparray + ";path=/;expires=Fri, 17 Dec 2012 10:00:00 GMT";				
	
	emparray="";
}

//check if cookies are enabled
function cookieCheck(){
	if (!Get_Cookie("username")){
		var enablecookies ="<h3>Your browser doesn't accept cookies.</h3> Please follow the instructions below to change your browser settings<br/><br/>";
			enablecookies+="<ol><li> Click the Tools menu <br/>";			
			enablecookies+="<li> Select Internet Options<br/>";
			enablecookies+="<li> Click the Privacy tab<br/>";
			enablecookies+="<li> Click the Default button (or manually slide the bar down to 'Medium')<br/>";
			enablecookies+="<li> Click the OK button</ol>";
	
		document.getElementById("enablecookies").innerHTML +=enablecookies;
		document.getElementById("enablecookies").style.display="block";
	
		return false;
	}else
		return true;
}
function hideEnableCookie(){
	document.getElementById("enablecookies").style.display="none";	
}

function showchartgrid(view){
		var cookie_date = new Date ( );  // current date & time
			cookie_date.setTime ( cookie_date.getTime() - 1 );
		var user = Get_Cookie("username");		
		document.cookie = "dashboard="+view+";path=/";
		
		if(view=="chartview"){
			
			document.getElementById("chartview").className="chartgrid1";
			document.getElementById("gridview").className="chartgrid2";
			document.getElementById("timeview").className="chartgrid2";
			document.getElementById("travelview").className="chartgrid2";
			
			if(Get_Cookie("currentpage")=="dayview.php"){
				
				window.frames["abc"].document.getElementById("hideme2").style.display="none";
				window.frames["abc"].document.getElementById("visu").style.display="block";
				window.frames["abc"].document.getElementById("visu2").style.display="none";
				window.frames["abc"].document.getElementById("visu3").style.display="none";
				
				//window.frames["abc"].document.getElementById("alphalist").style.display="none";
				window.frames["abc"].document.getElementById("sites2").style.display="none";
				
				//load visus
				window.frames["abc"].loadDayVisus();
			}
			if(Get_Cookie("currentpage")=="weekview.php"){
				window.frames["abc"].document.getElementById("visu").style.display="block";
				window.frames["abc"].document.getElementById("hideme2").style.display="none";
				window.frames["abc"].document.getElementById("visu2").style.display="none";
				
				//load visus
				window.frames["abc"].loadWeekVisus(view);
			}
		}
		if(view=="gridview"){				
			document.getElementById("chartview").className="chartgrid2";
			document.getElementById("timeview").className="chartgrid2";
			document.getElementById("gridview").className="chartgrid1";
			document.getElementById("travelview").className="chartgrid2";
			
			if(Get_Cookie("currentpage")=="dashboard.php"){
				window.frames["abc"].location.href = '/console/dayview.php';
				
			}
			if(Get_Cookie("currentpage")=="dayview.php"){
				window.frames["abc"].document.getElementById("hideme2").style.display="block";
				window.frames["abc"].document.getElementById("visu").style.display="none";
				window.frames["abc"].document.getElementById("visu2").style.display="none";
				window.frames["abc"].document.getElementById("visu3").style.display="none";
				
				window.frames["abc"].document.getElementById("alphalist").style.display="block";
				window.frames["abc"].document.getElementById("sites2").style.display="block";
				
				//load table
				if(Get_Cookie("VehicleCookie")){
					window.frames["abc"].vehicle();   
				} else {
					window.frames["abc"].doReq(false) ;			
				}		
			}
			
			if(Get_Cookie("currentpage")=="weekview.php"){
				window.frames["abc"].document.getElementById("hideme2").style.display="block";
				window.frames["abc"].document.getElementById("visu").style.display="none";
				window.frames["abc"].document.getElementById("visu2").style.display="none";
			
				window.frames["abc"].loadWeekVisus(view);		
			}
		}
		
		if(view=="timeview"){				
			document.getElementById("chartview").className="chartgrid2";
			document.getElementById("gridview").className="chartgrid2";
			document.getElementById("timeview").className="chartgrid1";
			document.getElementById("travelview").className="chartgrid2";
			
			if(Get_Cookie("currentpage")=="dayview.php"){
				window.frames["abc"].document.getElementById("hideme2").style.display="none";
				window.frames["abc"].document.getElementById("visu").style.display="none";
				window.frames["abc"].document.getElementById("visu2").style.display="block";
				window.frames["abc"].document.getElementById("visu3").style.display="none";
				//window.frames["abc"].document.getElementById("alphalist").style.display="none";
				window.frames["abc"].document.getElementById("sites2").style.display="none";
				
				//load table
				if(Get_Cookie("VehicleCookie")){
					window.frames["abc"].vehicle();   
				} else {
					window.frames["abc"].doReq(false) ;			
				}		
			}
			
			if(Get_Cookie("currentpage")=="weekview.php"){
				window.frames["abc"].document.getElementById("hideme2").style.display="none";
				window.frames["abc"].document.getElementById("visu").style.display="none";
				window.frames["abc"].document.getElementById("visu2").style.display="block";
				
				
			}
			
			
		}
		if(view=="travelview"){
			document.getElementById("chartview").className="chartgrid2";
			document.getElementById("gridview").className="chartgrid2";
			document.getElementById("timeview").className="chartgrid2";
			document.getElementById("travelview").className="chartgrid1";
			
			if(Get_Cookie("currentpage")=="dayview.php"){
				window.frames["abc"].document.getElementById("hideme2").style.display="none";
				window.frames["abc"].document.getElementById("visu").style.display="none";
				window.frames["abc"].document.getElementById("visu2").style.display="none";				
				window.frames["abc"].document.getElementById("sites2").style.display="none";
				window.frames["abc"].document.getElementById("visu3").style.display="block";
				
				window.frames["abc"].visu13();
				
			}
		
		}
}

function setevday(){
	var evdate =  new Date();			
	var a =evdate.getMonth() ;
	a=numberToMonth(a);
	var b = evdate.getDate();
	var c = evdate.getUTCFullYear();
	var result=a +' '+ b+', '+c;
	document.cookie="evtDate="+result+";path=/";
}

//show week sun-sat date on week and payroll view
function showdate(){
	var evt= new Date(Get_Cookie("evtDate"));	
	var firstsunday= new Date(evt.getUTCFullYear(), evt.getMonth(), evt.getDate() - evt.getDay() );
	var lastsaturday= new Date(evt.getUTCFullYear(), evt.getMonth(), evt.getDate() - evt.getDay()+6 );
	
	var month=new Array(12);
		month[0]="January";
		month[1]="February";
		month[2]="March";
		month[3]="April";
		month[4]="May";
		month[5]="June";
		month[6]="July";
		month[7]="August";
		month[8]="September";
		month[9]="October";
		month[10]="November";
		month[11]="December";
	
	var firstsunday2="Sun, " + firstsunday.getDate()+" " + month[firstsunday.getMonth()]
	var lastsaturday2="Sat, " + lastsaturday.getDate()+" " + month[lastsaturday.getMonth()]
	
	if(document.getElementById("dateId"))
		document.getElementById("dateId").innerHTML=firstsunday2+"-"+lastsaturday2;
	
	//for the livefeed
	startDate=firstsunday.getUTCFullYear()+"/"+(firstsunday.getMonth()+1)+"/"+firstsunday.getDate();
	endDate=lastsaturday.getUTCFullYear()+"/"+(lastsaturday.getMonth()+1)+"/"+lastsaturday.getDate();
}

//convert month to number
function monthToNumber(cmonth){
	switch(cmonth){
		case 'Jan':
			cmonth = '0';
			break;
		case 'Feb':
			cmonth = '1';
			break;
		case 'Mar':
			cmonth = '2';
			break;
		case 'Apr':
			cmonth = '3';
			break;
		case 'May':
			cmonth = '4';
			break;
		case 'Jun':
			cmonth = '5';
			break;
		case 'Jul':
			cmonth = '6';
			break;
		case 'Aug':
			cmonth = '7';
			break;
		case 'Sep':
			cmonth = '8';
			break;
		case 'Oct':
			cmonth = '9';
			break;
		case 'Nov':
			cmonth = '10';
			break;
		case 'Dec':
			cmonth = '11';
			break;
	}
	return cmonth;

}
function numberToMonth(a){
	if(a.length==2 && a.charAt(0)==0)
		a=a.charAt(1)		
	a=a*1	
	switch(a){
		case 0:
		a = 'Jan';
		break;
		case 1:
		a = 'Feb';
		break;
		case 2:
		a = 'Mar';
		break;
		case 3:
		a = 'Apr';
		break;
		case 4:
		a = 'May';
		break;
		case 5:
		a = 'Jun';
		break;
		case 6:
		a = 'Jul';
		break;
		case 7:
		a = 'Aug';
		break;
		case 8:
		a = 'Sep';
		break;
		case 9:
		a = 'Oct';
		break;
		case 10:
		a = 'Nov';
		break;
		case 11:
		a = 'Dec';
		break;
	}
	return a;
}


//open map into full window
var fullpage=0;
var origwidth=0;
var origheight=0;
var version=0;
function fullwindow(){
    if(origwidth==0){
        origwidth= document.documentElement.clientWidth;
        origheight= document.documentElement.clientHeight;
    }
    if(fullpage==0){
        top.document.getElementById("califrame").style.position="absolute";
        top.document.getElementById("califrame").style.margin="0 0 0 -225px";
       
        if (navigator.appVersion.indexOf("MSIE")!=-1){
            temp=navigator.appVersion.split("MSIE")
            version=parseFloat(temp[1])
            //if ie6 then change width               
            if (version<=6.5){
                var winwidth= top.document.documentElement.clientWidth;               
                winwidth=winwidth-50;
                top.document.getElementById("califrame").style.width=winwidth;
                document.getElementById("myMap").style.width=winwidth-35;
				
            }else{
                top.document.getElementById("califrame").style.width="98%";
				
			}
        }
        var winheight= top.document.documentElement.clientHeight;
        winheight=winheight-40;               
        top.document.getElementById("califrame").style.height=winheight;
        document.getElementById("myMap").style.height=winheight-55;       
        document.getElementById("fullmap").innerHTML="Minimise map";
        fullpage=1;
    }else{
        top.document.getElementById("califrame").style.position="";
        top.document.getElementById("califrame").style.margin="0 0 0 0";
        
		top.document.getElementById("califrame").style.width="100%"; 
        top.document.getElementById("califrame").style.height="740px";
		
		if(Get_Cookie("currentpage")=="dashboard.php")
        	document.getElementById("myMap").style.height="400";
		else
			document.getElementById("myMap").style.height="655";
        document.getElementById("fullmap").innerHTML="Maximise map";
        fullpage=0;
		
    }
}

//on unload remove all dayview and return default menus
function block() {   
    top.document.getElementById("califrame").style.position="";
    top.document.getElementById("califrame").style.margin="2px 0 0 0";
    top.document.getElementById("menu").style.display="block";
    top.document.getElementById("sidemenu").style.display="block";
    top.document.getElementById("daymenu").style.display="none";
	if(document.getElementById("allcurrentrefresh"))
    	document.getElementById("allcurrentrefresh").checked==false;
	else{
		if(document.getElementById("table_div2"))
			document.getElementById("table_div2").style.display="block";
		if(document.getElementById("imageBox0"))
			document.getElementById("imageBox0").style.display="block";	
	}
	top.document.getElementById("dashview").style.display="none";
	top.document.getElementById("chartview").innerHTML="Chart view";
	top.document.getElementById("gridview").innerHTML="Recorded Times";
	top.document.getElementById("timeview").style.display="";
	top.document.getElementById("travelview").style.display="";
}

//sort job and site dropdown
function sortlist() {   
    for(var sortco=0;sortco<2;sortco++){   
        if(sortco==0)
            var lb = document.forms['sites'].job;
        else{
			if(document.forms['sites'].sites2)
             	var lb = document.forms['sites'].sites2;
			else
				break;
        }
        arrTexts = new Array(); 		
		
        for(i=0; i<lb.length; i++) {
            var text= lb.options[i].text;       
            var val= lb.options[i].value;
            arrTexts[i] = text.substr(0, 1).toUpperCase()+text.substr(1)+':'+val;
        }
       
        arrTexts.sort();
       
        lb.options.length=lb.length+2;
		var prevel="";
		
        for(i=0; i<lb.length-1; i++) {
            var j=i+2;
            if(arrTexts[i]){
           	 	el = arrTexts[i].split(':');
			
				if(prevel!=el[0]){
					if(el[1]!= "all"){
						//alert(el[0] +"_"+j +"_"+i)
						lb.options[j].innerHTML = el[0];						
						lb.options[j].value = el[1];
					}else{
						lb.options[1].innerHTML = el[0];						
						lb.options[1].value = el[1];
					}
					
					prevel==el[0]
				}
            }
        }
       
    }
}

function remove2(){
	if(Get_Cookie("currentpage")=="weekview.php"){
		top.document.getElementById("week").style.backgroundColor = "#2F64BB";
		top.document.getElementById("week").style.color = "#ffffff";		
	}
	if(Get_Cookie("currentpage")=="customview.php"){		
		top.document.getElementById("custom").style.backgroundColor = "#2F64BB";
		top.document.getElementById("custom").style.color = "#ffffff";
	}
}


var siteid=new Array();
// align job dropdown in jobpage and under dayview verify site button
function alignjobsites(){	 
	if(Get_Cookie("currentpage")=="dayview.php"){
		showhide('hideme');
		document.getElementById('alignform').style.display='none'
	}
	var jobname = document.forms['align'].jobs.options[document.forms['align'].jobs.selectedIndex].value;
	jobname=jobname.split("^");
	document.cookie = "prjId=; path=/; ";
	document.cookie = "prjName=; path=/; ";
	document.cookie = "jobId="+jobname[1]+"; path=/; ";
	document.cookie = "jobName="+jobname[0]+"; path=/; ";
			
	var siteCount = 0;
	sitepoints=[];
	
	for(var i=0; i<projPushpins.length; i++) {
		kz_alert(projPushpins[i].jobId + " " + jobname[1]);
		
		if(projPushpins[i].jobId == jobname[1] && projPushpins[i].verified == "true") {			
			sitepoints[i]=projPushpins[i].latitude+">"+projPushpins[i].longitude+">"+projPushpins[i].name+">"+projPushpins[i].addressLine1+">"+projPushpins[i].postCode+">"+projPushpins[i].id+">"+projPushpins[i].jobName+">"+projPushpins[i].jobId;
					
			siteCount++;
		}
	}
	showCurrentSiteAddressOnMap();	
	
	var xmlbody = '<'+'?'+'xml version="1.0" encoding="UTF-8"'+'?'+'><postRequest xmlns="urn:mobibiz:tc:api:v1" actionType="UPDATE">';
	for(var r=0; r<siteid.length; r++){
		
		xmlbody = xmlbody + '<align verifiedSite ="true" country ="UK" type="WORK" verifiedJobId="'+jobname[1] ;
		if(Get_Cookie("currentpage")=="dayview.php")
			xmlbody = xmlbody + '" unverifiedId="'+siteid +'" />';
		else
			xmlbody = xmlbody + '" unverifiedId="'+projPushpins[siteid[r]].id +'" />';
	}
	if(siteid.length == 0) {
		xmlbody = xmlbody + '<align verifiedSite ="true" country ="UK" type="WORK" verifiedJobId="'+jobname[1] ;
		xmlbody = xmlbody + '" unverifiedId="-1" />';
	}
	xmlbody = xmlbody + '</postRequest>';
	kz_alert(xmlbody);
	
	addveri=1;
	var posturl = '/tc/TimeCollection/servlet/AlignSite?';			
	showAddressOnSiteViewMap("", xmlbody, posturl);
	
	//bug fix for older browsers- unselects the job dropdown
	document.forms['align'].jobs.selectedIndex=-1;
}

function createAlignRequest(pId){
	
	if(siteid.length==0){
		alert("Please check one or more sites first");		
	}else{
	
		kz_alert(pId);
		columnumber = 6;
		var count = 0;
		
		for(var r=0; r<siteid.length; r++){
			var xmlbody = '<'+'?'+'xml version="1.0" encoding="UTF-8"'+'?'+'><postRequest xmlns="urn:mobibiz:tc:api:v1" actionType="UPDATE"><align verifiedId="'+pId;
			if(Get_Cookie("currentpage")=="dayview.php")
				xmlbody = xmlbody + '" unverifiedId="'+siteid +'" /></postRequest>';
			else
				xmlbody = xmlbody + '" unverifiedId="'+projPushpins[siteid[r]].id +'" /></postRequest>';
			
			
			kz_alert(xmlbody);
			var req = null;
			var ajaxPost=new CoreAjax('/tc/TimeCollection/servlet/AlignSite?','POST',true,null);
	
			if(ajaxPost.doReq("input="+xmlbody)) {
				//stickyhide();
				count++;
				kz_alert("aligned successfully");
			} else {
				//stickyhide();
				kz_alert("align failed");
			}
	
		}
	
		alert(count + ' out of ' + siteid.length + ' sites verified successfully');
		
		deleteJobSiteCookie();
		
		document.cookie = "hid="+pId+"; path=/; ";
		if(Get_Cookie("currentpage")=="dayview.php")
			location.replace("/console/dayview.php?");
		else
			location.replace("/console/viewproject.php?");
	}
}

function deleteJobSiteCookie(){
	var cookie_date = new Date ( );  // current date & time
    cookie_date.setTime ( cookie_date.getTime() - 1 );
	
	document.cookie = "jobName=; path=/; expires=" + cookie_date.toGMTString();
    document.cookie = "jobId=; path=/; expires=" + cookie_date.toGMTString();
    document.cookie = "prjId=; path=/; expires=" + cookie_date.toGMTString();
    document.cookie = "prjName=; path=/; expires=" + cookie_date.toGMTString();
}

//create jobpage job details and in dayview verify job list
function jobdoReq(){
	showhideloading('hideme2','block');
	kz_alert("start");
	var timestamp = new Date();
	var viewprojectURL = '/tc/TimeCollection/servlet/JobRequest?';
	viewprojectURL = viewprojectURL + 'tmst=' + (timestamp*1);
	
	ajaxCore=new CoreAjax(viewprojectURL,'GET',true,createjoblist);
	//ajaxCore=new CoreAjax("jobxml.xml",'GET',true,createjoblist);
	ajaxCore.doReq();
}

var projPushpins=new Array();
function createjoblist(xmlString){
	if(xmlString==null) {
		return;
	}
	projPushpins=[];
	var jobElement = xmlString.getElementsByTagName('job');
	var jobIndex = 0;
	
	for (var index=0; index<jobElement.length; index++){		
		var siteElements = jobElement.item(index);
		var siteAttr  =  siteElements.attributes;
		var jobId = siteAttr.getNamedItem("id").value;
		if(jobId != 1)	{			
			var code = siteAttr.getNamedItem("code");						
			if(code != null  ) {
				if(siteAttr.getNamedItem("name")){
					//document.forms['align'].jobs.options[jobIndex+1] = new Option(siteAttr.getNamedItem("name").value+", "+siteAttr.getNamedItem("code").value,siteAttr.getNamedItem("name").value+"^"+siteAttr.getNamedItem("id").value);
					if(Get_Cookie("currentpage")=="viewproject.php")
						document.forms['renamesite'].jobs.options[jobIndex+1] = new Option(siteAttr.getNamedItem("name").value+", "+siteAttr.getNamedItem("code").value,siteAttr.getNamedItem("name").value+"^"+siteAttr.getNamedItem("id").value);
				
				
				}var jobcode =siteAttr.getNamedItem("code").value;			
			} else {
				//document.forms['align'].jobs.options[jobIndex+1] = new Option(siteAttr.getNamedItem("name").value,siteAttr.getNamedItem("name").value+"-"+siteAttr.getNamedItem("id").value);	
				if(Get_Cookie("currentpage")=="viewproject.php")
					document.forms['renamesite'].jobs.options[jobIndex+1] = new Option(siteAttr.getNamedItem("name").value,siteAttr.getNamedItem("name").value+"-"+siteAttr.getNamedItem("id").value);	
				
			}
			jobIndex++;			
		}
	
		var requestElement = siteElements.getElementsByTagName('site');
		var earlierjobname="";
		var earlierjobcode="";
		
		for(var i=0;i<requestElement.length;i++)
		{
			kz_alert("in the loop");
			var project=new ProjectVO();

			project.jobId   = siteAttr.getNamedItem("id").value;
			
			if(siteAttr.getNamedItem("code") != null)
				project.jobCode = siteAttr.getNamedItem("code").value;
			
			if(siteAttr.getNamedItem("name"))
				project.jobName = siteAttr.getNamedItem("name").value;
			
			if(index==0){
				document.cookie = "alljobs=; path=/";
				document.cookie = "alljobcodes=; path=/";
			}
			if(Get_Cookie("alljobs")){
				var prevjob=Get_Cookie("alljobs");
				if(project.jobName!=earlierjobname)
					var alljob=prevjob+"^"+project.jobName;
			}else
				var alljob=project.jobName;
			document.cookie = "alljobs="+alljob+"; path=/";
			earlierjobname=project.jobName;
		
			if(Get_Cookie("alljobcodes")){
				var prevjobcode=Get_Cookie("alljobcodes");
				if(project.jobCode!=earlierjobcode)
					var alljobcode=prevjobcode+"^"+project.jobCode;
			}else
				var alljobcode=project.jobCode;
			if(alljobcode!=null)
				document.cookie = "alljobcodes="+alljobcode+"; path=/";
			earlierjobcode=project.jobCode;
			
			
			var projAttr=requestElement.item(i).attributes;
			if(projAttr.getNamedItem('id') != null) {
				project.id=projAttr.getNamedItem('id').value;
				kz_alert(project.id);
				//project.accId=projAttr.getNamedItem('accountId').value;
				project.name=projAttr.getNamedItem('name').value;
				project.type=projAttr.getNamedItem('type').value;
				
				if(projAttr.getNamedItem('addressLine1')!=null)
					project.addressLine1=projAttr.getNamedItem('addressLine1').value;
				else
					project.addressLine1=" ";
					
				if(projAttr.getNamedItem('addressLine2')!=null)
					project.addressLine2=projAttr.getNamedItem('addressLine2').value;
				else
					project.addressLine2 = " ";

				if(projAttr.getNamedItem('city')!=null)
					project.city=projAttr.getNamedItem('city').value;
				else
					project.city = " ";
				kz_alert(project.city);
				if(projAttr.getNamedItem('postCode')!=null)
					project.postCode=projAttr.getNamedItem('postCode').value;
				else
					project.postCode = " ";
				
				if(projAttr.getNamedItem('country')!=null)
					project.country=projAttr.getNamedItem('country').value;
				else
					project.country= " ";
				project.siteType=projAttr.getNamedItem('type').value;
				project.verified=projAttr.getNamedItem('verifiedSite').value;
				if(projAttr.getNamedItem('taskCode') != null)
					project.taskCode=projAttr.getNamedItem('taskCode').value;
				project.status=projAttr.getNamedItem('archiveStatus').value;
				project.outOfZone = projAttr.getNamedItem('outOfZone').value;

				var createdByElement = requestElement.item(i).getElementsByTagName('createdBy');
				if(createdByElement != null && createdByElement.length > 0) {
					var createdBy = createdByElement.item(0);
					project.createdBy = createdBy.attributes.getNamedItem('firstname').value + ' ' + createdBy.attributes.getNamedItem('lastname').value;
				}
				
				if(projAttr.getNamedItem('creationDate')!=null) {
					project.creationDate = projAttr.getNamedItem('creationDate').value;
				}
				
				if(projAttr.getNamedItem('latitude') != null) {
					project.latitude = projAttr.getNamedItem('latitude').value;
				}
				if(projAttr.getNamedItem('longitude') != null)
					project.longitude = projAttr.getNamedItem('longitude').value;
				if(project.status=="true")
					continue;
			}
			projPushpins[projIndex]=project;
			kz_alert(projIndex + "::: " + project.id);
			projIndex++;
		}
	}
	kz_alert('value of projIndex is: '+projIndex);
	//loadProjDetail();
	projIndex=0;
	
	if(Get_Cookie("currentpage")=="viewproject.php"){
		//drawProTable();
		drawProTable2();
	}
}

function bstcodes(){
	document.form1.isdcodes.options[1] = new Option('1','1');
	document.form1.isdcodes.options[2] = new Option('7','7');
	
	document.form1.isdcodes.options[3] = new Option('20','20');
	document.form1.isdcodes.options[4] = new Option('27','27');
		
	document.form1.isdcodes.options[5] = new Option('30','30');
	document.form1.isdcodes.options[6] = new Option('31','31');
	document.form1.isdcodes.options[7] = new Option('32','32');
	document.form1.isdcodes.options[8] = new Option('33','33');
	document.form1.isdcodes.options[9] = new Option('34','34');
	document.form1.isdcodes.options[10] = new Option('36','36');
	document.form1.isdcodes.options[11] = new Option('39','39');
	
	document.form1.isdcodes.options[12] = new Option('40','40');
	document.form1.isdcodes.options[13] = new Option('41','41');
	document.form1.isdcodes.options[14] = new Option('43','43');
	document.form1.isdcodes.options[15] = new Option('44','44')
	document.form1.isdcodes.options[16] = new Option('45','45');
	document.form1.isdcodes.options[17] = new Option('46','46');
	document.form1.isdcodes.options[18] = new Option('47','47');
	document.form1.isdcodes.options[19] = new Option('48','48');
	document.form1.isdcodes.options[20] = new Option('49','49');
		
	document.form1.isdcodes.options[21] = new Option('51','51');
	document.form1.isdcodes.options[22] = new Option('52','52');
	document.form1.isdcodes.options[23] = new Option('53','53');
	document.form1.isdcodes.options[24] = new Option('54','54');
	document.form1.isdcodes.options[25] = new Option('55','55');
	document.form1.isdcodes.options[26] = new Option('56','56');
	document.form1.isdcodes.options[27] = new Option('57','57');
	document.form1.isdcodes.options[28] = new Option('58','58');
	
	document.form1.isdcodes.options[29] = new Option('60','60');
	document.form1.isdcodes.options[30] = new Option('61','61');
	document.form1.isdcodes.options[31] = new Option('62','62');
	document.form1.isdcodes.options[32] = new Option('63','63'); 
	document.form1.isdcodes.options[33] = new Option('64','64');
	document.form1.isdcodes.options[34] = new Option('65','65');
	document.form1.isdcodes.options[35] = new Option('66','66');
	
	document.form1.isdcodes.options[36] = new Option('81','81');
	document.form1.isdcodes.options[37] = new Option('82','82');
	document.form1.isdcodes.options[38] = new Option('84','84');
	document.form1.isdcodes.options[39] = new Option('86','86');
	document.form1.isdcodes.options[40] = new Option('90','90');
	document.form1.isdcodes.options[41] = new Option('91','91');
	document.form1.isdcodes.options[42] = new Option('92','92');
	document.form1.isdcodes.options[43] = new Option('93','93');
	document.form1.isdcodes.options[44] = new Option('94','94');
	document.form1.isdcodes.options[45] = new Option('95','95');
	document.form1.isdcodes.options[46] = new Option('98','98');
		
	document.form1.isdcodes.options[47] = new Option('212','212');
	document.form1.isdcodes.options[48] = new Option('213','213');
	document.form1.isdcodes.options[49] = new Option('216','216');
	document.form1.isdcodes.options[50] = new Option('218','218');
	
	document.form1.isdcodes.options[51] = new Option('220','220');
	document.form1.isdcodes.options[52] = new Option('221','221');
	document.form1.isdcodes.options[53] = new Option('222','222');
	document.form1.isdcodes.options[54] = new Option('223','223');
	document.form1.isdcodes.options[55] = new Option('224','224'); 
	document.form1.isdcodes.options[56] = new Option('225','225');
	document.form1.isdcodes.options[57] = new Option('226','226');
	document.form1.isdcodes.options[58] = new Option('227','227');
	document.form1.isdcodes.options[59] = new Option('228','228');
	document.form1.isdcodes.options[60] = new Option('229','229');
	document.form1.isdcodes.options[61] = new Option('230','230');
	document.form1.isdcodes.options[62] = new Option('231','231');
	document.form1.isdcodes.options[63] = new Option('232','232');
	
	document.form1.isdcodes.options[64] = new Option('233','233');
	document.form1.isdcodes.options[65] = new Option('234','234');
	
	document.form1.isdcodes.options[66] = new Option('235','235');
	document.form1.isdcodes.options[67] = new Option('236','236');
	document.form1.isdcodes.options[68] = new Option('237','237');
	document.form1.isdcodes.options[69] = new Option('238','238');
	document.form1.isdcodes.options[70] = new Option('239','239');
	 
	document.form1.isdcodes.options[71] = new Option('240','240');
	document.form1.isdcodes.options[72] = new Option('241','241');
	document.form1.isdcodes.options[73] = new Option('242','242');
	document.form1.isdcodes.options[74] = new Option('243','243');
	document.form1.isdcodes.options[75] = new Option('244','244');
	document.form1.isdcodes.options[76] = new Option('245','245');
	document.form1.isdcodes.options[77] = new Option('246','246');
	document.form1.isdcodes.options[78] = new Option('247','247');
	document.form1.isdcodes.options[79] = new Option('248','248');
	document.form1.isdcodes.options[80] = new Option('249','249');
	
	document.form1.isdcodes.options[81] = new Option('250','250');
	document.form1.isdcodes.options[82] = new Option('251','251');
	document.form1.isdcodes.options[83] = new Option('252','252');
	document.form1.isdcodes.options[84] = new Option('253','253');
	document.form1.isdcodes.options[85] = new Option('254','254');
	document.form1.isdcodes.options[86] = new Option('255','255');
	document.form1.isdcodes.options[87] = new Option('256','256');
	document.form1.isdcodes.options[88] = new Option('257','257');
	document.form1.isdcodes.options[89] = new Option('258','258');
	
	document.form1.isdcodes.options[90] = new Option('260','260');
	document.form1.isdcodes.options[91] = new Option('261','261');
	document.form1.isdcodes.options[92] = new Option('262','262');
	document.form1.isdcodes.options[93] = new Option('263','263');
	document.form1.isdcodes.options[94] = new Option('264','264');
	document.form1.isdcodes.options[95] = new Option('265','265');
	document.form1.isdcodes.options[96] = new Option('266','266');
	document.form1.isdcodes.options[97] = new Option('267','267');
	document.form1.isdcodes.options[98] = new Option('268','268');
	document.form1.isdcodes.options[99] = new Option('269','269');
	
	document.form1.isdcodes.options[100] = new Option('284','284'); 
	
	document.form1.isdcodes.options[101] = new Option('290','290');
	document.form1.isdcodes.options[102] = new Option('291','291');
	document.form1.isdcodes.options[103] = new Option('297','297');
	document.form1.isdcodes.options[104] = new Option('298','298');
	document.form1.isdcodes.options[105] = new Option('299','299'); 
	
	document.form1.isdcodes.options[106] = new Option('345','345');
	
	document.form1.isdcodes.options[107] = new Option('350','350');
	document.form1.isdcodes.options[108] = new Option('351','351');
	document.form1.isdcodes.options[109] = new Option('352','352');
	document.form1.isdcodes.options[110] = new Option('353','353');
	document.form1.isdcodes.options[111] = new Option('354','354');
	document.form1.isdcodes.options[112] = new Option('355','355');
	document.form1.isdcodes.options[113] = new Option('356','93');
	document.form1.isdcodes.options[114] = new Option('357','357');
	document.form1.isdcodes.options[115] = new Option('358','358');
	document.form1.isdcodes.options[116] = new Option('359','359');
	
	document.form1.isdcodes.options[117] = new Option('370','370');
	document.form1.isdcodes.options[118] = new Option('371','371');
	document.form1.isdcodes.options[119] = new Option('372','372');
	document.form1.isdcodes.options[120] = new Option('373','373');
	document.form1.isdcodes.options[121] = new Option('374','374');
	document.form1.isdcodes.options[122] = new Option('375','375');
	document.form1.isdcodes.options[123] = new Option('376','376');
	document.form1.isdcodes.options[124] = new Option('377','377');
	document.form1.isdcodes.options[125] = new Option('378','378');
		
	document.form1.isdcodes.options[126] = new Option('380','380');
	document.form1.isdcodes.options[127] = new Option('381','381');
	document.form1.isdcodes.options[128] = new Option('385','385');
	document.form1.isdcodes.options[129] = new Option('386','386');
	document.form1.isdcodes.options[130] = new Option('387','387');
	document.form1.isdcodes.options[131] = new Option('389','389');
		
	document.form1.isdcodes.options[132] = new Option('420','420');
	document.form1.isdcodes.options[133] = new Option('421','421');
	document.form1.isdcodes.options[134] = new Option('441','441');
	document.form1.isdcodes.options[135] = new Option('473','473');
		
	document.form1.isdcodes.options[136] = new Option('500','500');
	document.form1.isdcodes.options[137] = new Option('501','501');
	document.form1.isdcodes.options[138] = new Option('502','502');
	document.form1.isdcodes.options[139] = new Option('503','503');
	document.form1.isdcodes.options[140] = new Option('504','504');
	document.form1.isdcodes.options[141] = new Option('505','505');
	document.form1.isdcodes.options[142] = new Option('506','506');
	document.form1.isdcodes.options[143] = new Option('507','507');
	document.form1.isdcodes.options[144] = new Option('508','508');
	document.form1.isdcodes.options[145] = new Option('509','509');
	
	document.form1.isdcodes.options[146] = new Option('590','590');
	document.form1.isdcodes.options[147] = new Option('591','591');
	document.form1.isdcodes.options[148] = new Option('592','592');
	document.form1.isdcodes.options[149] = new Option('593','593');
	document.form1.isdcodes.options[150] = new Option('594','594');
	document.form1.isdcodes.options[151] = new Option('595','595');
	document.form1.isdcodes.options[152] = new Option('596','596');
	document.form1.isdcodes.options[153] = new Option('597','597');
	document.form1.isdcodes.options[154] = new Option('598','598');
	document.form1.isdcodes.options[155] = new Option('599','599');
		
	document.form1.isdcodes.options[156] = new Option('649','649');
	document.form1.isdcodes.options[157] = new Option('664','664');
	 
	document.form1.isdcodes.options[158] = new Option('670','670');
	document.form1.isdcodes.options[159] = new Option('672','672');
	document.form1.isdcodes.options[160] = new Option('673','673');
	document.form1.isdcodes.options[161] = new Option('674','674');
	document.form1.isdcodes.options[162] = new Option('675','675');
	document.form1.isdcodes.options[163] = new Option('676','676');
	document.form1.isdcodes.options[164] = new Option('677','677');
	document.form1.isdcodes.options[165] = new Option('678','678');
	document.form1.isdcodes.options[166] = new Option('679','679');
	
	document.form1.isdcodes.options[167] = new Option('680','680');
	document.form1.isdcodes.options[168] = new Option('681','681');
	document.form1.isdcodes.options[169] = new Option('682','682');
	document.form1.isdcodes.options[170] = new Option('683','683');
	document.form1.isdcodes.options[171] = new Option('684','684');
	document.form1.isdcodes.options[172] = new Option('685','685');
	document.form1.isdcodes.options[173] = new Option('686','686');
	document.form1.isdcodes.options[174] = new Option('687','687');
	document.form1.isdcodes.options[175] = new Option('688','688');
	document.form1.isdcodes.options[176] = new Option('689','689');
	
	document.form1.isdcodes.options[177] = new Option('690','690');
	document.form1.isdcodes.options[178] = new Option('692','692');
	
	document.form1.isdcodes.options[179] = new Option('758','758');
	document.form1.isdcodes.options[180] = new Option('767','767');
	document.form1.isdcodes.options[181] = new Option('787','787');
	
	document.form1.isdcodes.options[182] = new Option('809','809');
	document.form1.isdcodes.options[183] = new Option('850','850');
	document.form1.isdcodes.options[184] = new Option('852','852');
	document.form1.isdcodes.options[185] = new Option('853','853');
	document.form1.isdcodes.options[186] = new Option('855','855');
	document.form1.isdcodes.options[187] = new Option('856','856');
	document.form1.isdcodes.options[188] = new Option('868','868');
	document.form1.isdcodes.options[189] = new Option('869','869');
	document.form1.isdcodes.options[190] = new Option('876','876');
	document.form1.isdcodes.options[191] = new Option('880','880');
	document.form1.isdcodes.options[192] = new Option('886','886');
		
	document.form1.isdcodes.options[193] = new Option('960','960');
	document.form1.isdcodes.options[194] = new Option('961','961');
	document.form1.isdcodes.options[195] = new Option('962','962');
	document.form1.isdcodes.options[196] = new Option('963','963');
	document.form1.isdcodes.options[197] = new Option('964','964');
	document.form1.isdcodes.options[198] = new Option('965','965');
	document.form1.isdcodes.options[199] = new Option('966','966');
	document.form1.isdcodes.options[200] = new Option('967','967');
	document.form1.isdcodes.options[201] = new Option('968','968');
	
	document.form1.isdcodes.options[202] = new Option('971','971');
	document.form1.isdcodes.options[203] = new Option('972','972');
	document.form1.isdcodes.options[204] = new Option('973','973');
	document.form1.isdcodes.options[205] = new Option('974','974');
	document.form1.isdcodes.options[206] = new Option('975','975');
	document.form1.isdcodes.options[207] = new Option('976','976');
	document.form1.isdcodes.options[208] = new Option('977','977');
	
	document.form1.isdcodes.options[209] = new Option('993','993');
	document.form1.isdcodes.options[210] = new Option('994','994');
	document.form1.isdcodes.options[211] = new Option('995','995');
	document.form1.isdcodes.options[212] = new Option('996','996');
	document.form1.isdcodes.options[213] = new Option('998','998');
	
	document.form1.isdcodes.options[214] = new Option('5399','5399');
	
}

function populateTimeZone(){
	var temp = new Date(); 
	
	var timeZoneUrl = "/tc/APIFS/GetTimezoneServlet?q="+document.form1.isdcodes.value+'&tst='+temp;
	//alert(timeZoneUrl)
	var ajaxCore=new CoreAjax(timeZoneUrl, 'GET', true, handleTimeZone, 'True');
    ajaxCore.doReq(null);
}

function handleTimeZone(resp){
	//alert(resp.xml)
	var elSel = document.getElementById('timeZone');
  	for (var i = elSel.length - 1; i>0; i--) {
    	elSel.remove(i);    	
  	}
	
	var timeZone = resp.getElementsByTagName('timeZone');
    var len = timeZone.length;
    var i = 0;
    while(i<len)
    {
    	var str = timeZone[i].firstChild.nodeValue;
        document.form1.timeZone.options[i+1] = new Option (str, str);
        i++;
	}
	
}

//autocomplete
function clearfeild(){
	var str = document.sites.autocomplete_parameter.value;
	if (str == 'Search employee ...')
		document.sites.autocomplete_parameter.value = '';
	return true;
}


//firefox workaround for outerHTML command, used for editing the table values
function outerhtmlfix(){
	try{
		
			HTMLElement.prototype.__defineGetter__("outerHTML", function () {
			  var attrs = this.attributes;
			  var str = "<" + this.tagName;
			  for (var i = 0; i < attrs.length; i++)
				 str += " " + attrs[i].name + "=\"" + attrs[i].value + "\"";
			
			  if (_emptyTags[this.tagName])
				 return str + ">";
			
			  return str + ">" + this.innerHTML + "</" + this.tagName + ">";
			});
			HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) {
			  var r = this.ownerDocument.createRange();
			  r.setStartBefore(this);
			  var df = r.createContextualFragment(sHTML);
			  this.parentNode.replaceChild(df, this);
			});
		
	}catch(err){}
}

function features(){

var features='';

}



function notice(){	
	
	if(Get_Cookie("accountAlert") && Get_Cookie("accountAlert")!=null){
		var accountAlert=Get_Cookie("accountAlert");
		accountAlert=accountAlert.split("|");
		for(var i=0 ; i<accountAlert.length; i++){			
			if(accountAlert[i].length>4){
				accountAlert[i]=accountAlert[i].split("^");			
			
				document.getElementById('messageheader').innerHTML=accountAlert[i][2];
				document.getElementById('message').innerHTML=accountAlert[i][3];
				document.getElementById('notice').innerHTML="<a href='#' style='color:red' onclick='document.getElementById(\"alertbox\").style.display=\"block\"'>"+accountAlert[i][2]+"</a>";
				//document.getElementById('alertbox').style.display='block';
				var alertbut='<form name="alertform" action="">	';	
					alertbut+='<input id="button" class="rebtn" type="button" value="'+accountAlert[i][1]+'" onclick="location.href=\''+accountAlert[i][0]+'\'" />	'	;
					alertbut+='<input id="button" class="rebtn" type="button" value="Cancel" onclick="document.getElementById(\'alertbox\').style.display=\'none\'" />';		
					alertbut+='</form>';
				 
				document.getElementById('alertbutton').innerHTML+=alertbut;
				
				if(!Get_Cookie("firstlogin")){
					var date = new Date();
						date.setTime(date.getTime()+(16*60*60*1000));
					var expires = "; expires="+date.toGMTString(); 
						
					document.cookie = "firstlogin=1; path=/" +expires;
					
					document.getElementById("alertbox").style.display="block";
				}
			}
		}
	}
			
}

function createEmpList2(){
	kz_alert("in doreq");
	var ajaxCore=null;
	var timestamp = new Date();
	//ajaxCore=new CoreAjax('/tc/TimeCollection/servlet/Employee?tmst=' + (timestamp*1), 'GET', true, responseViewAllQuery2);
	ajaxCore=new CoreAjax('http://localhost/console/visu/visuother/Employees.xml', 'GET', true, responseViewAllQuery2);
	
	ajaxCore.doReq(null);
}

var ifempcookie=0;
var EmployeeListCookie="";
var empArray=new Array();
function responseViewAllQuery2(xmlString){	
	kz_alert("In responseViewAllQuery");
	//alert(xmlString.xml)
	var requestElement = xmlString.getElementsByTagName('*');
	var firstChild = requestElement.item(1);
	
	var accountid=firstChild.attributes.getNamedItem('id').value	
	
	var date = new Date();
	date.setTime(date.getTime()+(24*60*60*1000));
	var expires = "; expires="+date.toGMTString(); 
	document.cookie = "accountId="+accountid+"; path=/;" +expires;
	
	switch(firstChild.tagName){		
		case 'employer': {
			var employerAttrs = firstChild.attributes;			
			var isGPSEnabledOnAccount = employerAttrs.getNamedItem('gpsCollectionOn');
						
			if(isGPSEnabledOnAccount==null || isGPSEnabledOnAccount.value == 'false')						
				document.cookie ="employerGPSEnabled=false; path=/";
			if(isGPSEnabledOnAccount && isGPSEnabledOnAccount.value == 'true')
				document.cookie ="employerGPSEnabled=true; path=/";
			/*
			if(Get_Cookie("employerGPSEnabled")=="false")
				top.document.getElementById("vehicle2").style.display="none";		
			else
				top.document.getElementById("vehicle2").style.display="block";
				*/		
			var employees = firstChild.getElementsByTagName('employee');
			var empIndex = 0;
			
			//cookie for alphabetical sorting
			document.cookie="table_length="+employees.length+";path=/";
						
			for(var emp=0;emp<employees.length;emp++){	
				var attendances=employees.item(emp).getElementsByTagName('attendance');					
				var attributeNode=employees.item(emp).attributes;
				
				var id =attributeNode.getNamedItem('id').value;		
				var superv = attributeNode.getNamedItem('isSupervisor').value;
				var lgname = attributeNode.getNamedItem('lastname').value;
				var fsname = attributeNode.getNamedItem('firstname').value;
				var lsname = attributeNode.getNamedItem('lastname').value;
				var optInValue = attributeNode.getNamedItem('optIn').value;					
							
				kz_alert("no attendance");
				var estate = attributeNode.getNamedItem('state').value;
				var number = attributeNode.getNamedItem('mobilePhone').value;
				//var crew = attributeNode.getNamedItem('crew').value;
				var operator = attributeNode.getNamedItem('operator').value;
				var badgeNumber = attributeNode.getNamedItem('badgeNumber').value;
				
				var subscription="";
				var subStartDate="";
				var subStatus="";
				var subNextInvoiceDate="";
				var subName="";

				if(employees.item(emp).getElementsByTagName('subscription').length!=0){
					var subscription=employees.item(emp).getElementsByTagName('subscription');
					var subStartDate=subscription.item(0).attributes.getNamedItem('startDate').value;
					var subStatus=subscription.item(0).attributes.getNamedItem('status').value;
					var subNextInvoiceDate=subscription.item(0).attributes.getNamedItem('nextInvoiceDate').value;
					var subName=subscription.item(0).attributes.getNamedItem('name').value;
					var itemId=subscription.item(0).attributes.getNamedItem('itemId').value;
				}
				var empVO=new EmployeeVO();
				empVO.empId = id;
				empVO.optIn = optInValue;				
				empVO.loginName = lgname;
				empVO.firstName = fsname;
				empVO.lastName = lsname;
				empVO.state = estate;
				empVO.phone = number;
				empVO.operator = operator;
				empVO.badgeNumber = badgeNumber;
				empVO.employeenumber = employees.length;
				
				empVO.subStartDate=subStartDate;
				empVO.subStatus=subStatus;
				empVO.subNextInvoiceDate=subNextInvoiceDate;
				empVO.subName=subName;				
				empVO.itemId=itemId;
				
				if(EmployeeListCookie=="")
					EmployeeListCookie = id + "," + fsname + "," + lsname+ "," + number;				
				else
					EmployeeListCookie = EmployeeListCookie + "/" + id + "," + fsname + "," + lsname+ "," + number;
				
				usern = Get_Cookie("username");

				if(!Get_Cookie(usern+"EmployeeListCookie"))
					ifempcookie=1;
								
				if( ifempcookie==1)
					document.cookie =usern+"EmployeeListCookie=" + EmployeeListCookie + ";path=/;expires=Fri, 17 Dec 2010 10:00:00 GMT";
				
				//for alphabetical list
				document.cookie =usern+"empCookie=" + EmployeeListCookie + "; path=/";
				//display supervisor if true
				if(superv=="true")
					empVO.superv = "<img src=\"./images/main/user.png\" title=\"Supervisor\"  />";
				else
					empVO.superv ="";
					
				kz_alert("finish add");
				empArray[emp] = empVO;					
			}			
			break;
		}
	}
	
	SortEmployeeCookie();
	
	//sort by firstname
	empArray=nameSort(empArray);
	
	if(Get_Cookie("currentpage")=="viewall.php")
		showEmploy();
}