function popUp(URL, w, h) {
	day = new Date();
	id = day.getTime();
	var left = (screen.width - w)/2;
	var top = (screen.height - h)/2;

	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + w + ",height=" + h + ",left=" + left + ",top=" + top + "');");
}

function popUpFullscreen(URL, w, h) {
	day = new Date();
	id = day.getTime();
	var left = (screen.width - w)/2;
	var top = (screen.height - h)/2;

	eval("page" + id + " = window.open(URL, '" + id + "', 'fullscreen=true,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + w + ",height=" + h + ",left=" + left + ",top=" + top + "');");
}

function addToFavorites() { 
	var urlAddress = "http://www.gpsfleetsolutions.com/index.php"; 
	var pageName = "GPS Fleet Solutions"; 
	
	if (document.all) {
		window.external.AddFavorite(urlAddress,pageName); 
	} else if(window.sidebar) {
		window.sidebar.addPanel(pageName,urlAddress,'');
	}
}

function verify(fields) {
	var fail = 0;
	
	for (var i=0; i<fields.length; i++) {
		if (document.getElementById(fields[i]).value == "") {
			document.getElementById(fields[i]).style.backgroundColor = '#f8caca';
			fail++;
		} else {
			document.getElementById(fields[i]).style.backgroundColor = '#FFFFFF';
		}
	}
	
	if (fail > 0) {
		alert("All required fields are not filled out. Please review the highlighted fields.");
		return false;
	} else {
		return true;
	}
}

function addCommas(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

var needValidate = false;

var defaultVal2 = "Type your question here and click below...";
function  openchatwindow(cbForm,windowName) {
	var res = true;

	var msg = document.getElementById("lp_msgfield");

	if(needValidate){
		var validateMessage = "Before you start your chat, type in the following fields:\r\n ";

		if(msg.value.length==0 || msg.value==defaultVal2 ){
			validateMessage += "Your Question\r\n";
			res=false;
		}
		if(res==false){
			alert(validateMessage);
		}

	}

    var formurl = cbForm.action;
    if(formurl.indexOf('?')==-1)
        formurl += '?';
    var elemCol = cbForm.elements;
    for(var ie=0; ie<elemCol.length; ie++){
        var et = elemCol[ie].type;
        if(et=="text" || et=="hidden" || et=="radio" || et=="textarea"){
            formurl += elemCol[ie].name + "=" + escape(elemCol[ie].value) + "&" ;
        }
    }

    if(res==true) {
		window.open(formurl, windowName,'width=475,height=400,resizable=yes');
    }
	
	return res;
}

function small_live_chat(){
	lpButtonCTTUrl = 'https://server.iad.liveperson.net/hc/39421312/?cmd=file&file=visitorWantsToChat&site=39421312&imageUrl=https://server.iad.liveperson.net/hcp/Gallery/ChatButton-Gallery/English/Small/2a&referrer=' + escape(document.location);
	lpButtonCTTUrl = (typeof(lpAppendVisitorCookies) != 'undefined' ? lpAppendVisitorCookies(lpButtonCTTUrl) : lpButtonCTTUrl);
	lpButtonCTTUrl = ((typeof(lpMTag) != 'undefined' && typeof(lpMTag.addFirstPartyCookies) != 'undefined') ? lpMTag.addFirstPartyCookies(lpButtonCTTUrl) : lpButtonCTTUrl);
	window.open(lpButtonCTTUrl, 'chat39421312', 'width=475,height=400,resizable=yes');

	return false;
}