var xmlhttp = null;
var nodeIndex = 0;
function createXMLHTTP()
{
    if (window.XMLHttpRequest)      // code for Mozilla, etc.
        return new XMLHttpRequest()
    else if (window.ActiveXObject)  // code for IE
        return new ActiveXObject("Microsoft.XMLHTTP")                                         
}

function offY(el) {
	var y;	
	// Return the y coordinate of an element relative to the page.
	y = el.offsetTop;
	if (el.offsetParent != null)
	  y += offY(el.offsetParent);
	return y;
}
function offX(el) {
	var x;	
	// Return the x coordinate of an element relative to the page.
	x = el.offsetLeft;
	if (el.offsetParent != null)
	  x += offX(el.offsetParent);
	return x;
}

function showAttachments(id,type)
{ 
  var showType = type!=null?type:"";
  windowPopup("../win/FilePicker.aspx?id=" + id + "&type="+showType,900,550,1,1)
}
function selectOption(id, value, selectByText) {
 var obj = qd(id);
 for(var i=0;i<obj.options.length;i++) {
  if((obj.options[i].value == value && !selectByText) || (obj.options[i].text == value && selectByText)) {
	obj.selectedIndex = i;
	return;
  }
}
}

function firstNum(s) 
{
 var ret = "";
 for(var i=0;i<s.length;i++) {
  if(!isNaN(s.substr(i,1))&&s.substr(i,1)!=" ") 
    ret += s.substr(i,1);
  else 
 	return ret;
  }
  return ret;
}

function between(source, startAt, endAt) {
 if(source=="") return "";
 var st, nd;
 if(startAt=="") {
	st = 0;
  } else {
	st = source.indexOf(startAt)
	if(st == -1) {
   	 st = source.length;
	} else {
	 st += startAt.length;
	}
  }
 if(endAt=="") {
	nd = source.length;
 } else {
  nd = source.indexOf(endAt,st)
 if(nd==-1) nd = source.length;
 }
 if(nd-st<0) return "";
	return source.substr(st,nd-st);
}
			
function qd(id) {
 if (document.getElementById(id) != null) 
    return document.getElementById(id)
 else
    return "";
}

function dv(id) {
 return qd(id).value
}

var errShown = new Array();
function showErr(id,txt) {
  var obj = document.getElementById(id);
  if(txt!=undefined) obj.innerText = txt;
  	obj.style.display = "inline";
	errShown.push(id);
	return 1;
  }

function hideAllErrors() {
  for(var i=0;i<errShown.length;i++) {
	qd(errShown[i]).style.display = "none";
	}
	errShown = new Array();
}

function regExVal(id, exp, canNull) {
  var value = qd(id).value;			
  if(canNull&&value=="") return true;
  var rx = new RegExp(exp);
  var matches = rx.exec(value);
  return (matches != null && value == matches[0] && value != "");
}

function hasIllegalChar(item, exp) {
 var re = new RegExp(exp);  
 if (item.match(re)) {
	return true;
 } 
 else {
    return false;
 }
}

function rightTrim(sString) {
  while (sString.substring(sString.length-1, sString.length) == ' ')
  {
   sString = sString.substring(0,sString.length-1);
  }
  return sString;
}

function Trim(val)
{
 return val.replace(/^\s*|\s*$/g,"");
}

function resDSok(res) {
 if(res!="") 
	return (res != null && res.tables != null && res.tables.length == 1);
}

function checkLeadZero(obj) {
 if(!isNaN(obj.value.substr(1,1))) {
	while(obj.value.substr(0,1)=="0"&&obj.value!="0") {
		obj.value = obj.value.substr(1)
		}
  }
}

function roundDecimal(nNumber, nDecimals) {
 var tenToPower;
 var newNumber;
 var numPad = 0;
 var curDecimal;
 var locDecimal;
 var i;

// round the number
 tenToPower = Math.pow(10, nDecimals);
 newNumber = String(Math.round(nNumber * tenToPower) / tenToPower);

 if (nDecimals > 0) {
   // see if we need to pad with 0's
   locDecimal = newNumber.indexOf(".");
   if (locDecimal == -1) {
     // no decimal at all
     newNumber += ".";
     numPad = nDecimals
   } else {
     // how much padding do we need?
     curDecimal = (newNumber.length - locDecimal) - 1;
     if (curDecimal < nDecimals) {
      numPad = nDecimals - curDecimal;
     }
   }
   // pad the end with 0's
   for (i = 0; i < numPad; i++) {
    newNumber += "0";               
    }
 }
 return String(newNumber);
}

function DMSToDD(dms) {
    if(dms=="" || dms==null) return "";
    var dmsArr = dms.split(".");
    var initialpointVal = dmsArr[0].length;
    if (initialpointVal > 3)
    {
	    var dmsArray = dms.split(" ");
	    var numElements = dmsArray.length;
	    if(dmsArray.length>3 || dmsArray.length==0)
	    {
		    msgbox("Enter correct degrees minutes seconds value","vbOkOnly or vbWarning","Warning");
		    return "";
	    }
	    else if(dmsArray.length==3)
	    {
		    d = dmsArray[0];
		    m = dmsArray[1];
		    s = dmsArray[2];
	    }
	    else if(dmsArray.length==2)
	    {
		    d = 0;
		    m = dmsArray[0];
		    s = dmsArray[1];
	    }
	    else if(dmsArray.length==1)
	    {
		    d = 0;
		    m = 0;
		    s = dmsArray[0];
	    }
	    if(dms.charAt(0) =="-")
		    dd = parseFloat(d) + (-m/60) + (-s/(60*60));
	    else
		    dd = parseFloat(d) + + m/60 + s/(60*60);
	    dd = roundDecimal(dd, 6)
	    }
	else{dd = dms;}
	return dd;
}

function wcAddItem(wcId) 
{
	var wc = ISGetObject(wcId);
	var id = 0;
	var txt = wc.TextObj.value;
	wc.AddItem(txt, id+"", new Array(txt));
	wc.LoadValue();
}

function SetLoadingOverlay(show,isProposalGen)
{
	if(isProposalGen==null || isProposalGen==undefined)
		isProposalGen = false;	
	var LoadingOuterBox = qd("LoadingOuterBox");
	
	if (document.body.scrollHeight > document.body.offsetHeight)
		LoadingOuterBox.style.height = document.body.scrollHeight; 
	else
	    LoadingOuterBox.style.height = document.body.offsetHeight;
		
	if(show)
	{
		LoadingOuterBox.style.display = "inline";
		window.scrollTo(0,0);
		showHideSelectBoxes(!show);
	}
	else
	{
		LoadingOuterBox.style.display = "none";
		showHideSelectBoxes(!show);
	}
	if(isProposalGen)
	{
		//invoicecontrol.showSelectBoxes(!show);
		//scheduleControl.showSelectBoxes(!show);
	}
	return show;
}

function showHideSelectBoxes(show,hideFlash) {
	var sel = document.getElementsByTagName("SELECT");
	sel.level = 0;
	for(var i=0;i<sel.length;i++) {
		if(show) {
			if(sel[i].level) sel[i].style.visibility="visible";
		} else {
			if(sel[i].style.visibility!="hidden") {
				sel[i].level = 1;
				sel[i].style.visibility="hidden";
			}
		}
	}

	//Now for the Flash
	if(show||hideFlash||hideFlash==null) {
		sel = document.getElementsByTagName("OBJECT");
		sel.level = 0;
		for(var i=0;i<sel.length;i++) {
			if(show) {
				if(sel[i].level) sel[i].style.visibility="visible";
			} else {
				if(sel[i].style.visibility!="hidden") {
					sel[i].level = 1;
					sel[i].style.visibility="hidden";
				}
			}
		}
	}
}

function windowPopupPercent(u,width,height,scrollbars,resizeable,name) {
	if(resizeable==null)
		resizeable = 1;
	if(name == null)
		name = "newWin";
	var screenX, screenY;
	width=(window.screen.width*width/100);
	height=(window.screen.height*height/100);
	screenX = (window.screen.width - width)/2;
	screenY = (window.screen.height - height)/4;
	var newWindow = window.open(u,name,'toolbar=0,scrollbars='+scrollbars+',location=0,statusbar=0,menubar=0,resizable='+resizeable+',width='+width+',height='+height+',left='+screenX+',top='+screenY);
	newWindow.focus();	
}
var newWindow;
function windowPopup(u,width,height,scrollbars,resizeable) {
    if(newWindow != null)
	{
	 try{
	newWindow.close();
	 }catch(err){}
	
	}
	var url = u.toLowerCase();
	var screenX, screenY;
	/*if(u.substr(0,1) >= "a" && u.substr(0,1) <= "z"){var winName = 'newWin'+u.substr(0,4)
	} else {var winName = 'newWinFix0redBizzug'}*/
	var winName="newWinFix0redBizzug";
	var indexSlash=url.lastIndexOf("/");
	var indexDot=url.lastIndexOf(".aspx");
	if(indexSlash!=-1 && indexDot!=-1)
	{
		var intFrom = url.lastIndexOf("/")+1;
		var intTo = url.lastIndexOf(".aspx")-url.lastIndexOf("/")-1;
		if(intTo > 0)
			winName = url.substr(intFrom,intTo);
	}	
	height=height-0;
	width=width-0;
	width=width+10;
	height=height+20;
	
	if (resizeable==undefined)resizeable=0;
	
	if(navigator.appName == 'Microsoft Internet Explorer') {
		screenY = document.body.offsetHeight;
		screenX = window.screen.availWidth;
	}
	else {
		screenY = window.outerHeight
		screenX = window.outerWidth
	}
	screenX = (screenX/2)-(width/2);
	screenY = (screenY/2)-(height/2);
	if(screenY<0)screenY=5;
	
	try
	{
	    newWindow = window.open(u,winName,'toolbar=0,scrollbars='+scrollbars+',location=0,statusbar=0,menubar=0,resizable='+ resizeable +',width='+width+',height='+height+',left='+screenX+',top='+screenY);
	}
	catch (err) 
	{
        window.showModalDialog(u,"", "maximize:yes;minimize:yes;dialogLeft:" + screenX +";dialogTop:" + screenY +";resizable:1;dialogWidth:" + width+ "px;dialogHeight:" + height+ "px");
    }
	//return newWindow; // remove by because it would hide parent page 
}

function windowPopupFullScreen(u,sName,width,height,scrollbars,resizeable,fullscreen) {
    if(newWindow != null)
	{
		try{newWindow.close();}catch(e){}
	}
	var url = u.toLowerCase();
	var screenX, screenY;
	var indexSlash=url.lastIndexOf("/");
	var indexDot=url.lastIndexOf(".aspx");
	if(indexSlash!=-1 && indexDot!=-1)
	{
		var intFrom = url.lastIndexOf("/")+1;
		var intTo = url.lastIndexOf(".aspx")-url.lastIndexOf("/")-1;
	}	
	height=height-0;
	width=width-0;
	width=width+10;
	height=height+20;
	
	if (resizeable==undefined)resizeable=0;
	
	if(navigator.appName == 'Microsoft Internet Explorer') {
		screenY = document.body.offsetHeight;
		screenX = window.screen.availWidth;
	}
	else {
		screenY = window.outerHeight
		screenX = window.outerWidth
	}
	screenX = (screenX/2)-(width/2);
	screenY = (screenY/2)-(height/2);
	if(screenY<0)screenY=5;
	try
	{
	    newWindow = window.open(u,sName,'toolbar=0,fullscreen='+fullscreen+',scrollbars='+scrollbars+',location=0,statusbar=0,menubar=0,resizable='+ resizeable +',width='+width+',height='+height+',left='+screenX+',top='+screenY);	
	}
	catch (err)
	{
	   newWindow= window.showModalDialog(u,"", "maximize:yes;minimize:yes;dialogLeft:" + screenX +";dialogTop:" + screenY +";resizable:1;dialogWidth:" + width+ "px;dialogHeight:" + height+ "px");
	}
	
}

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }   
}
//Check if < OR > Keypress than ignore it
function checkScriptKeycode(keyPressed)
{
  if (keyPressed.keyCode == 60 || keyPressed.keyCode ==62)
    keyPressed.keyCode=0;  
}
function removePotentially(obj)
{
  var strtmp;  
  strtmp=obj.value;  
  strtmp=strtmp.replace(/</g,"(");  
  strtmp=strtmp.replace(/>/g,")");  
  obj.innerText=strtmp;
  
}

function numbersOnly() {
	var key;
	var keychar;
	key = event.keyCode; 
	keychar = String.fromCharCode(key);
	var isnumber = false;
	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ){return true;}
	if (((".0123456789").indexOf(keychar) > -1)) {isnumber = true;}	
	return isnumber;
}

function integerNumbersOnly() {
	var key;
	var keychar;
	key = event.keyCode; 
	keychar = String.fromCharCode(key);
	var isnumber = false;
	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ){return true;}
	if ((("0123456789").indexOf(keychar) > -1)) {isnumber = true;}	
	event.cancelBubble=!isnumber;
	return isnumber;
}

function checkFormat(cntrl)
{	
	var value = cntrl.value;
	var s = new String();
	//check whether value has more than one .
	if(value.split(".").length > 2)
	{
		cntrl.value = "0.00";
	}
	value = value.toString().replace(/\$|\,/g,'');
	if(isNaN(value))
	value = "0";
	sign = (value == (value = Math.abs(value)));
	value = Math.floor(value*100+0.50000000001);
	cents = value%100;
	value = Math.floor(value/100).toString();
	if(cents<10)
	cents = "0" + cents;
	cntrl.value = (((sign)?'':'-')  + value + '.' + cents);
}
function messageWindow(title, msg)
{
  var ret = showModalDialog("../confirm.htm?msg="+ msg,title,"center:yes;edge:raised;status:no;resizable:no;scroll:no;unadorned:yes;dialogWidth:350px;dialogHeight:95px");  
  if (ret==undefined)
   ret=false;
  return ret;
}

////Centers the element with an ID of <id> on the screen////
function centerObj(id) {
	centerObjHelp(id);
}

function myResDsOk(res) {
	if(!resDSok(res)) {
		note("No data returned.","r");
	    return false;
	}
	return true;
}
function qsValue(qsKey)
 {
	qsKey=qsKey.toLowerCase();
	var keyLen = qsKey.length+1;
	var srch = window.location.search.toLowerCase();
	srch = srch.substr(srch.indexOf("?"));
	if(srch.indexOf(qsKey+"=") == -1) return ""
	srch = srch.substr(srch.indexOf(qsKey+"=")+keyLen);
	if(srch.indexOf("&") != -1) {
		srch = srch.substr(0,srch.indexOf("&"));
	}
	return unescape(srch)
}	
function qm_over(obj) {obj.style.backgroundColor = "#0053A6";}
function qm_out(obj) {obj.style.backgroundColor = "transparent";}
/*Browsercheck object*/
function cm_bwcheck(){
	//In theory we should use object detection, but this script needs work-arounds for almost every browser...
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent.toLowerCase()
	this.dom=document.getElementById?1:0
	this.ns4=(!this.dom && document.layers)?1:0;
	this.op=window.opera 
	this.moz=(this.agent.indexOf("gecko")>-1 || window.sidebar)
	this.ie=this.agent.indexOf("msie")>-1 && !this.op
	if(this.op){
		this.op5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1)
		this.op6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1)
		this.op7=this.dom&&!this.op5&&!this.op6 //So all higher opera versions will use it
	}else if(this.moz) this.ns6 = 1
	else if(this.ie){
		this.ie4 = !this.dom && document.all
  	this.ie5 = (this.agent.indexOf("msie 5")>-1)
  	this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1)
  	this.ie6 = this.dom && !this.ie4 && !this.ie5 && ! this.ie55
	}
	this.mac=(this.agent.indexOf("mac")>-1)
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6 || this.op7)
  this.usedom= this.ns6||this.op7//Use dom creation
  this.reuse = this.ie||this.op7||this.usedom //Reuse layers
  this.px=this.dom&&!this.op5?"px":""
	return this
}
var strGeoDisplayFormat=null;
var bw=new cm_bwcheck()
function FormatLatLon(strValue, type)
{ 
    if (strGeoDisplayFormat==null)
     strGeoDisplayFormat=SyncAjax(ActiveTextService.get_path() + "/GetSetting", "{settigsName:\"GeoDisplayFormat\"}");
	if(strGeoDisplayFormat== "DMS")
		return DDToDMS(strValue, type);
	else
		return strValue;
}

function ReFormatLatLon(strValue)
{
    if (strGeoDisplayFormat==null)
     strGeoDisplayFormat=SyncAjax(ActiveTextService.get_path() + "/GetSetting", "{settigsName:\"GeoDisplayFormat\"}");

	if(strGeoDisplayFormat == "DMS")
		return DMSToDD(strValue);
	else
		return strValue;
}
	
function DDToDMS(dd, type)
{
	dd = String(dd);
	if(dd=="" || dd==null) return "";
	var typeLength;
	if(type == "latitude")
		typeLength = 3;
	else
		typeLength = 4;
	var ddArray = dd.split(".");

	var degrees = ddArray[0];
	var minutes = ".0000";
	if (dd.indexOf(".") != -1)
	{
		minutes = (eval("." + ddArray[1])*60);
	}
	var temp = String(minutes);
	if (temp.indexOf(".") == -1) 
	{
		// no decimal at all
		temp += ".0000";
	}
	var mArray = temp.split(".");
	minutes = mArray[0];
	var seconds = (eval("." + mArray[1])*60);
	seconds = roundDecimal(seconds, 6)
	var a = new String();

	while((degrees.length < typeLength && degrees.charAt(0) == "-") || degrees.length < typeLength - 1)
	{
		if(degrees.charAt(0) == "-")
			degrees = "-0" + degrees.substring(1, degrees.length)
		else 
			degrees = "0" + degrees.substring(0, degrees.length)
	}

	while(minutes.length < 2)
	{
			minutes = "0" + minutes.substring(0, minutes.length)
	}

	while(seconds.split(".")[0].length < 2)
	{
			seconds = "0" + seconds.substring(0, seconds.length)
	}

	var dms = String(degrees) + " " + String(minutes) + " " + String(seconds);
	return dms
}
function GoToPersonalCal(isCompanyEvent)
{
	var cd = new Date();
	var m,d,y;
	m = cd.getMonth(); d=cd.getDate(); y=cd.getFullYear();
	m = m + 1; //get actual month and day
	var time = new Date();	
	
	if (isCompanyEvent == 0)
	    var strTemp = "../main/calendar.aspx?cd=" + m + "_" + d + "_" + y +"&hour="+ time.getHours();
	else if  (isCompanyEvent == 1)
	    var strTemp = "../main/calendar.aspx?CompanyEvent=1&cd=" + m + "_" + d + "_" + y +"&hour="+ time.getHours();
	
	windowPopupFullScreen(strTemp,'_blank',screen.width*97/100,screen.height*85/100,1,1,0);
}
function GoToJobCalendar()
{
    var ret ;
    ret=msgbox('This page may take several minuets to load, based on the amount of phases, tasks, and subtasks that are unassigned!','OK,Cancel,Warning','Warning');
    if(ret==1)
    {
        window.open("../main/JobCalendar.aspx",'_self');
    }
}

// Example:
// alert( readCookie("myCookie") );
function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}
// Example:
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}
function popVerbalRequest()
{
	windowPopup('../win/VerbalRequest.aspx',900,660,1);
}
function JobCycleReset()
{
	var frm = document.getElementById("frmJobCycle");
	frm.src = '';
	/*
	document.getElementById("LoadingOuterBox").style.display = "none";
	document.getElementById("loginScreen").style.display = "none";
	*/
	document.getElementById("dvJobCycle").style.display = "none";
	//ql_screenVisible = false;
	//showHideSelectBoxes(true);	
	document.body.scroll = "yes";	
}
function ShowJobCycleMap2()
{
//	document.Form1.onsubmit = function () 
//	{
//		return false;
//	}		
	document.body.scroll = "no";
	var lnScreen = document.getElementById("dvJobCycle");
	//var frm = document.getElementById("frmJobCycle");
	//frm.src = '../main/JobCycleMap.aspx';
	//document.getElementById("ql_userNameDiv").innerText = ql_userName;
	//document.getElementById("loginScreen").style.display = "inline";
	lnScreen.width = "100%";
	lnScreen.height = window.document.body.clientHeight;
	lnScreen.style.display = "inline";
	window.scrollTo(0,0);		
	//showHideSelectBoxes(false);		
}
function ShowJobCycleMap()
{
	/*
	document.Form1.onsubmit = function () 
	{ 
		return false;
	}		
	window.clearTimeout(ql_rTimer);
	window.clearTimeout(ql_timer);
	document.body.scroll = "no";
	var lnScreen = document.getElementById("dvJobCycle")
	*/	
	//document.getElementById("CycleOuterBox").style.display = "inline";
	var frm = document.getElementById("frmJobCycle");
	frm.src = '../main/JobCycleMap.aspx';
	window.setTimeout(ShowJobCycleMap2,400);
	/*
	document.getElementById("ql_userNameDiv").innerText = ql_userName;
	document.getElementById("loginScreen").style.display = "inline";
	lnScreen.width = "100%";
	lnScreen.style.display = "inline";
	window.scrollTo(0,0);	
	ql_screenVisible = true;	
	showHideSelectBoxes(false);	
	*/	
	
}
function centerObjHelp(id) {
	var screenX, screenY;
	var obj = document.getElementById(id);
	var width = obj.offsetWidth==0?obj.currentStyle.width.replace("px",""):obj.offsetWidth;
	var height = obj.offsetHeight==0?obj.currentStyle.height.replace("px",""):obj.offsetHeight;
	if(navigator.appName == 'Microsoft Internet Explorer') {
		screenY = document.body.clientHeight;
		screenX = document.body.clientWidth; //screen.availWidth-20;
	} else {
		screenY = window.outerHeight;
		screenX = window.outerWidth;
	}
	screenX = (screenX/2)-(width/2);
	screenY = (screenY/2)-(height/2);	
	screenY += document.body.scrollTop;	
	obj.style.left = screenX+"px";
	if(id == "dvHours" && screenY > 100)
	{
	    screenY = (screenY/2) - 20;
	}
	obj.style.top = screenY+"px";
}

function popEmails() 
{		
    try
    {
    window.open('../win/sendEmail.aspx','Email','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=640,height=620,left=190,top=50');
    }
	catch (err) 
	{
        window.showModalDialog('../win/sendEmail.aspx','Email', "maximize:yes;minimize:yes;dialogLeft:190;dialogTop:50;resizable:1;dialogWidth:640px;dialogHeight:620px");
    }
	noFocus = true;
}

function SyncAjax(strUrl, strParameters)
{
	var wRequest = new Sys.Net.WebRequest();
	// Set the request URL.
	wRequest.set_url(strUrl);
	// Set the request parameters.
	wRequest.set_body(strParameters);
	// Set the request verb.
	wRequest.set_httpVerb('POST');
	wRequest.get_headers()['Content-Type'] = 'application/json; charset=utf-8';

	var executor = new Sys.Net.XMLHttpSyncExecutor();
	wRequest.set_executor(executor);
	wRequest.invoke();
	var res;
	if (executor.get_responseAvailable())
	{
	    res = executor.get_object();
	}
	wRequest = null;
	executor = null;
	return res;
}
function popPhone() {
	windowPopup('../win/phoneMemo.aspx',555,490,1);
	noFocus = true;
}
function OnError(res)
{
    msgbox(res._message,'vbOkOnly or vbUnSuccessful','Unsuccessful');
}

function SelectByValue(id, value) 
{
    obj = document.getElementById(id);
    for (var i=0;i<obj.options.length;i++) 
    {
        if (obj.options[i].value == value) 
        {
            obj.options[i].selected = true;
            obj.options.selectedIndex = i;
            break;
        }
    }
}

function SelectByText(id, text) 
{
    obj = document.getElementById(id);
    for (var i=0;i<obj.options.length;i++) 
    {
        if (obj.options[i].text == text) 
        {
            obj.options[i].selected = true;
            obj.options.selectedIndex = i;
            break;
        }
    }
}
function isValidDate(dateStr) 
{
   var culture = SyncAjax(ActiveTextService.get_path() + "/GetApplicationSettings", "{name:'CultureName'}");
   var format = ""; 	
   if (culture.toLowerCase()=='en-us')
     format = "MDY";
   else
     format = "DMY";
	
   format = format.toUpperCase();
   if (format.length != 3) { format = "MDY"; }
   if ( (format.indexOf("M") == -1) || (format.indexOf("D") == -1) || (format.indexOf("Y") == -1) ) { format = "MDY"; }
   if (format.substring(0, 1) == "Y") { // If the year is first
      var reg1 = /^\d{2}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
      var reg2 = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
   } else if (format.substring(1, 2) == "Y") { // If the year is second
      var reg1 = /^\d{1,2}(\-|\/|\.)\d{2}\1\d{1,2}$/
      var reg2 = /^\d{1,2}(\-|\/|\.)\d{4}\1\d{1,2}$/
   } else { // The year must be third
      var reg1 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2}$/
      var reg2 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
   }
   // If it doesn't conform to the right format (with either a 2 digit year or 4 digit year), fail
   if ( (reg1.test(dateStr) == false) && (reg2.test(dateStr) == false) ) { return false; }
   var parts = dateStr.split(RegExp.$1); // Split into 3 parts based on what the divider was
   // Check to see if the 3 parts end up making a valid date
   if (format.substring(0, 1) == "M") { var mm = parts[0]; } else if (format.substring(1, 2) == "M") { var mm = parts[1]; } else { var mm = parts[2]; }
   if (format.substring(0, 1) == "D") { var dd = parts[0]; } else if (format.substring(1, 2) == "D") { var dd = parts[1]; } else { var dd = parts[2]; }
   if (format.substring(0, 1) == "Y") { var yy = parts[0]; } else if (format.substring(1, 2) == "Y") { var yy = parts[1]; } else { var yy = parts[2]; }
   if (parseFloat(yy) <= 50) { yy = (parseFloat(yy) + 2000).toString(); }
   if (parseFloat(yy) <= 99) { yy = (parseFloat(yy) + 1900).toString(); }
   var dt = new Date(parseFloat(yy), parseFloat(mm)-1, parseFloat(dd), 0, 0, 0, 0);
   if (parseFloat(dd) != dt.getDate()) { return false; }
   if (parseFloat(mm)-1 != dt.getMonth()) { return false; }
   return true;
}
function RemoveFilterFromWebGrid(wgGridName)
{
  var grid = ISGetObject(wgGridName);
  var intFilterCols = grid.RootTable.FilteredColumns.length;
  for (i=0;i<intFilterCols;i++)
    {
     grid.RootTable.FilteredColumns.Remove(grid.RootTable.FilteredColumns[i], true);
     grid.RootTable.FilteredColumns[i].FilterType = "";
     grid.RootTable.FilteredColumns[i].FilterText = "";      
    }
  grid.RootTable.UpdateUI();
  grid.Refresh();
} 

function AccountModule()
{
    window.open('http://web2srv.cvlsoft.net/cvlAccount/default.aspx','_blank');
    return;
}


function GetcurrentTime()
{
  var curDateTime = new Date()
  var curHour = curDateTime.getHours()
  var curMin = curDateTime.getMinutes()
  var curSec = curDateTime.getSeconds()
  var curAMPM = " AM"
  var curTime = ""
  if (curHour >= 12){
    curHour -= 12
    curAMPM = " PM"
    }
  if (curHour == 0) curHour = 12
  curTime = curHour + ":" 
    + ((curMin < 10) ? "0" : "") + curMin + ":" 
    + ((curSec < 10) ? "0" : "") + curSec 
    + curAMPM
  return curTime;
}
if(typeof(wsCommonService) != "undefined" && wsCommonService != null)
{
    wsCommonService.CheckIsLoggedIn(CheckIsLoggedIn_cb, OnError);
}
function CheckIsLoggedIn_cb(res)
{
if(res != "")
    window.location.href = res;
}
function getElementsByClassName(className, tag, elm){
	var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}