<!--

/*
 * MAP FUCTIONS
 *
 */
var blockNextClick = false;
function rowClick(oEvent,url){
	if(blockNextClick == true){
		blockNextClick = false;
		return;
	}
	if (oEvent.altKey) {
		window.open(url);
		return;
	}if (oEvent.ctrlKey) {
		window.open(url);
		return;
	}
	window.location = url;
}

var geocode = '';

function setFormMapPositionChange(latlong){
	$("#editform input[name=gps_lat]").val(latlong.lat().toFixed(7));
	$("#editform input[name=gps_long]").val(latlong.lng().toFixed(7));
	$("#editform input[name=geocode_accuracy]").val(100);

	$("div#lat_long_display").html(latlong.lat().toFixed(7)+', '+latlong.lng().toFixed(7));
	$("div#lat_long_desc").html('<b>Position manually adjusted</b>');
}


function checkAddressChange(){
	var street = $("#editform input[name=address]").val();
	var suburb = $("#editform input[name=suburb]").val();
	var city = $("#editform input[name=city]").val();
	if(address_temp != street+suburb+city){
		geoEncode(false);
		updatePinPosition();
	}
}

function updatePinPosition(){
	var pin_pos = new GLatLng($("#editform input[name=gps_lat]").val(),$("#editform input[name=gps_long]").val());
	marker.setLatLng(pin_pos);
	if($("#editform input[name=geocode_accuracy]").val() != '' && $("#editform input[name=geocode_accuracy]").val() > 1){
		var latlngbounds = new GLatLngBounds( );
		latlngbounds.extend(pin_pos);
		if (typeof mobi_point!="undefined"){
			latlngbounds.extend(mobi_point);
			map.setCenter( latlngbounds.getCenter( ), map.getBoundsZoomLevel( latlngbounds ) );
		}else if($("#editform input[name=geocode_accuracy]").val() < 6){
			map.setCenter( latlngbounds.getCenter( ), 11);
		}else{
			map.setCenter( latlngbounds.getCenter( ), map.getBoundsZoomLevel( latlngbounds ) );
		}
	}
}

function geoEncode(force) {
	if($("#editform input[name=geocode_accuracy]").val() == 100 && !force){
		return;
	}

	var street = $("#editform input[name=address]").val();
	var suburb = $("#editform input[name=suburb]").val();
	var city = $("#editform input[name=city]").val();
	if(suburb !='' || city != ''){
		var address = street +' '+ suburb +' '+ city;
		geo.getLocations(address, function (result){
			if(result.Status.code == G_GEO_SUCCESS && result.Placemark.count > 1 && result.Status.code == G_GEO_SUCCESS){
				document.getElementById("lat_long_desc").innerHTML = '<b>Multiple address matches</b>';
			}else if (result.Status.code == G_GEO_SUCCESS) {

				geocode = result.Placemark[0].Point.coordinates;
				$("#editform input[name=gps_lat]").val(geocode[1]);
				$("#editform input[name=gps_long]").val(geocode[0]);
				$("div#lat_long_display").html(geocode[1].toFixed(7)+', '+geocode[0].toFixed(7));
				$("#editform input[name=geocode_accuracy]").val(result.Placemark[0].AddressDetails.Accuracy);
				$("div#lat_long_desc").html(accuracy[result.Placemark[0].AddressDetails.Accuracy]);
				updatePinPosition();
				//savePoint(geocode);
			} else {
				var reason="Code "+result.Status.code;
				if (reasons[result.Status.code]) {
					reason = reasons[result.Status.code]
				}
				$("#add-point.geo_error").html(reason).fadeIn();
				geocode = false;
			}
		});
	}
}

function savePoint(geocode) {
    var data = $("#editform :input").serializeArray();
    data[data.length] = { name: "lng", value: geocode[0] };
    data[data.length] = { name: "lat", value: geocode[1] };
    $.post($("#add-point").attr('action'), data, function(json){
        $("#add-point .error").fadeOut();
        if (json.status == "fail") {
            $("#add-point .error").html(json.message).fadeIn();
        }
        if (json.status == "success") {
            $("#add-point :input[name!=action]").val("");
            var location = json.data;
            addLocation(location);
            zoomToBounds();
        }
    }, "json");
}

function fitMap(points ) {
   var bounds = new GLatLngBounds();
   for (var i=0; i< points.length; i++) {
      bounds.extend(points[i]);
   }
   map.setZoom(map.getBoundsZoomLevel(bounds));
   map.setCenter(bounds.getCenter());
}

function customerAddressCheck(has_address){
	var test_address = 	$("#"+has_address.id).attr('has_address');
	if(test_address != ''){
		$("#get_address_link").show(0);
		$("#no_address_link").hide(0);
	}else{
		$("#get_address_link").hide(0);
		$("#no_address_link").show(0);
	}
}

/*
 *
 * END MAP FUNCTIONS
 */


function loadLeftColIframeSize() {
	var theFrame = $("#leftCol", parent.document.body);
	theFrame.height($('#tabs').height() + 60);
	theFrame.height(880);
}

/*
 * OTP MESSAGE SENDER
 */

function fireOTPMessage(utype, id){
	var mobile = $("#editform input[name=mobile]").val();
	var country = $("#editform select[name=country_code]").val();
	var name_first = $("#editform input[name=name_first]").val();

	eval(doQuery('','console.php?s=ajax&a=userOTPsend&mobile='+mobile+'&country_code='+country+'&name_first='+name_first+'&utype='+utype+'&id='+id, '',true));
}

function confirmOTP(){
	var click_conf = $("#confirmMobile input[name=click_conf]").val();
	var utype = $("#confirmMobile input[name=utype]").val();
	var id = $("#confirmMobile input[name=gid]").val();
	var mobile = $("#confirmMobile input[name=mobile]").val();
	if(click_conf != ''){
		$.ajax({
			url: '/console.php?s=ajax&a=confirmOTP&click_conf='+click_conf+'&utype='+utype+'&id='+id+'&mobile='+mobile,
			dataType:'script',
			error: function(XMLHttpRequest, textStatus, errorThrown){}
		});
	}
	//eval(doQuery('','console.php?s=ajax&a=confirmOTP&click_conf='+click_conf+'&utype='+utype+'&id='+id, '',true));
}

function toggleClickDiv(show){
	if(show == 'reg'){// show clickatel registration form
		$('#click_conf').hide(1000);
        $('#click_done').show(1000);
	}else{// show okay status
		toggle_login_display = true;
        $('#click_conf').hide(1000);
		$('#click_done').show(1000);
	}
		
}


function checkMobileChange(){
	var mobile = $("#editform input[name=mobile]").val();
	var old_mobile= $("#editform input[name=old_mobile]").val();
	var click_reged= $("#editform input[name=click_reged]").val();
	if(mobile != old_mobile){// show okay status
		$('#click_done').hide(1000);
        $('#click_conf').show(1000);
	}else if(click_reged == 'true'){
		$('#click_conf').hide(1000);
		$('#click_done').show(1000);
	}

}

/*
 * END OTP MESSAGE SENDER
 *
 * START FORM FUNCTIONS
 */
function toggleCRM_hider(){
	$('.CRM_hider').toggle();
	/*alert($("input#crm_active").val());
	if($("input#crm_active").val()){
		$('.CRM_hider').show();
	}else{
		$('.CRM_hider').hide();
	}*/
}



var mobiinputs = 1;
function AddMobiUserInput() {
	mobiinputs++;
	tmp = addUserSnippet.replace(/\|/g, mobiinputs);
	//document.getElementById('mobileusers'+mobiinputs).innerHTML = document.getElementById('mobileusers'+mobiinputs).innerHTML + tmp;
	$("#pricingTableContent > tbody").append(tmp);
}

function hideMobiUserInput(r) {
    rowID = 'phoneRow_'+r;
    document.getElementById(rowID).style.display = 'none';
    $('#mobi_'+r).val('xxxx');
}





function mobileNumberValidation(element){
	if(element.value.indexOf('+') >= 0 ){
		$("#countryWarning").html('Please exclude the +Country Code from all your phone numbers.');
	}else{
		$("#countryWarning").html('');
	}
}

var isMozilla = (document.all) ? 0 : 1;


function hover(obj) {
	UL = obj.getElementsByTagName('ul');
    if (UL.length > 0) {
		stubMenu = UL[0].style;
		if (stubMenu.display == 'none' || stubMenu.display == '') stubMenu.display = 'block';
		else stubMenu.display = 'none';
	}
}

function setHover() {
	obj = document.getElementById('menu');
	if (!obj) return ;
	LI = document.getElementById('menu').getElementsByTagName('li');
	for(i=0; i < LI.length; i++) {
		LI[i].onmouseover = function() { hover(this) };
		LI[i].onmouseout = function() { hover(this); }
	}
}


function CheckAll(formobj) {
	for (i=0; i < formobj.length; i++) if (formobj.elements[i].name.substr(0,8) == 'checked_') formobj.elements[i].checked = formobj.checkall.checked;
}

function GetCheckedIDs(formobj) {
	res = '';
	for (i=0; i < formobj.length; i++) if ((formobj.elements[i].name.substr(0,8) == 'checked_') && formobj.elements[i].checked) res += formobj.elements[i].value+'|';
	return res;
}

function CheckAllSpecial(formobj, fldall, prefix) {
	for (i=0; i < formobj.length; i++) if (formobj.elements[i].name.substr(0,prefix.length) == prefix) formobj.elements[i].checked = document.getElementById(fldall).checked;
}


function ConfirmDelete(form, msg) {
	var godel = window.confirm(msg);
	if (godel) {
		form.elements['suredelete'].value = 1;
		form.submit();
	}
}


function SwitchEditor(fldname) {
	ShowHideLayer('edsimple_'+fldname);
	ShowHideLayer('edrich_'+fldname);
	img = document.getElementById('editorimage_'+fldname);
	stub = img.src;
	if (stub.indexOf('edsimple.gif') == -1) {
		img.src='images/edsimple.gif';
		document.getElementById('goedit_'+fldname).style.display='none';
	}
	else {
		img.src='images/edrich.gif';
		document.getElementById('goedit_'+fldname).style.display='inline';
	}
	content = document.getElementById(fldname).value;
	document.getElementById('edrich_'+fldname).innerHTML = content;
}	
	


function popup( url, winname, width, height ) {
	if (winname == "") winname = "popup";
	if (width == "") width = "400";
	if (height == "") height = "300";
	var top = (screen.height) / 2 - (height / 2);
	var left = (screen.width) / 2 - (width / 2);
	var win_arg = "scrollbars=yes,status=yes,resizable=yes,location=no,toolbar=no,width=" + width + ",height=" + height + ",top=" + top + ",left=" + left;
	window.open(url,winname,win_arg);
}



function ShowPageLayer(num, count) {
	for (i=1; i<=count; i++) {
		document.getElementById('pagediv_'+i).style.display = 'none';
		document.getElementById('cell_'+i).className = 'switchcell_off';
	}
	document.getElementById('pagediv_'+num).style.display = 'block';
	document.getElementById('cell_'+num).className = 'switchcell_on';
}

function HideSelects() {
    tmp = document.getElementsByTagName('select');
    for (i=0; i<tmp.length; i++) tmp[i].style.visibility = 'hidden';
}

function ShowSelects() {
    tmp = document.getElementsByTagName('select');
    for (i=0; i<tmp.length; i++) tmp[i].style.visibility = 'visible';
}




function SubRows(prefix, disp) {
	tmp = document.getElementsByTagName('tr');
    for (i=0; i<tmp.length; i++) 
		if (tmp[i].id.indexOf(prefix) == 0) tmp[i].style.display = disp;
	if (disp == 'none') setto = 0;
	else setto = 1;
}


function ShowHideSubRows(prefix) {
	img = document.getElementById(prefix+'expander');
	if (!img) return;
	stub = img.src;
	if (stub.indexOf('expand.gif') == -1) {
		img.src = 'images/expand.gif';
		img.title = 'expand';
		SubRows(prefix, 'none');
	}
	else {
		img.src = 'images/contract.gif';
		img.title = 'contract';
		if (isMozilla) disp = 'table-row';
		else disp = 'block';
		SubRows(prefix, disp);
	}
}


function ShowHideSubRows2(prefix) {
	tmp = document.getElementsByTagName('tr');
    for (i=0; i<tmp.length; i++) {
		if (tmp[i].style.display == 'none') {
			if (isMozilla) disp = 'table-row';
			else disp = 'block';
		}
		else disp = 'none';
		if (tmp[i].id.indexOf(prefix) == 0) tmp[i].style.display = disp;
	}
}



function AllSubRows(prefix, disp) {
    tmp = document.getElementsByTagName('tr');
    for (i=0; i<tmp.length; i++) {
		id = tmp[i].id;
		if (id.indexOf(prefix) == 0) tmp[i].style.display = disp;
	}
    tmp = document.getElementsByTagName('img');
    for (i=0; i<tmp.length; i++) {
		id = tmp[i].id;
		if (id.indexOf(prefix) == 0) {
			if (disp == 'none') {
				tmp[i].src = 'images/expand.gif';
				tmp[i].title = 'expand';
			}
			else {
				tmp[i].src = 'images/contract.gif';
				tmp[i].title = 'contract';
			}
		}
	}
}


function ShowHideAllSubRows(prefix) {
	img = document.getElementById(prefix+'_expander');
	stub = img.src;
	if (stub.indexOf('expand.gif') == -1) {
		img.src = 'images/expand.gif';
		AllSubRows(prefix, 'none');
		img.title = 'expand all';
	}
	else {
		img.src = 'images/contract.gif';
		if (isMozilla) disp = 'table-row';
		else disp = 'block';
		AllSubRows(prefix, disp);
		img.title = 'contract all';
	}
}


function stub() {
}


function UpdatePackPrices(prefix) {
	price = parseFloat(document.getElementById('base'+prefix).value);
	prefix = prefix+'_';
    tmp = document.getElementsByTagName('input');
    for (i=0; i<tmp.length; i++)
		if (tmp[i].id.indexOf(prefix) == 0) {
			multy = parseFloat(tmp[i].id.replace(prefix, ''));
			val = parseFloat(multy*price);
			val = val.toFixed(2);
			tmp[i].value = val;
		}
}


function SumMatQuant(matid, fld, limitto, needq, accuracy) {
	if (fld.value > limitto) fld.value = limitto;
    tmp = document.getElementsByTagName('input');
	sum = 0;
    for (i=0; i<tmp.length; i++) if (tmp[i].name.indexOf('qantmat_'+matid) == 0) sum += parseFloat(tmp[i].value);
	fldsum = document.getElementById('qantsum_'+matid);
	sum = sum.toFixed(accuracy);
	fldsum.value = sum;
	if (sum == needq) fldsum.style.color = 'green';
	else fldsum.style.color = 'red';
}


function LimiTo(obj, limito) {
	if (obj.value > limito) obj.value = limito;
}



function findPosX(e) {
	var posx = 0;
	if (!e) var e = window.event;
	if (e.pageX) 	posx = e.pageX;
	else if (e.clientX) posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
	return posx;
}

function findPosY(e) {
	var posx = 0;
	if (!e) var e = window.event;
	if (e.pageY) posy = e.pageY;
	else if (e.clientY) posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	return posy;
}


function ShowLayerAtPos(e, divname, offsetX, offsetY) {
	if (!offsetX) offsetX = 0;
	if (!offsetY) offsetY = 0;
	var div = document.getElementById(divname);
	x = findPosX(e);
	y = findPosY(e);
	div.style.left = x+offsetX+'px';
	div.style.top = y+offsetY+'px';
	if (div.style.display == 'block') div.style.display = 'none';
	else  div.style.display = 'block';
}

function HideLayer(divname) {
	document.getElementById(divname).style.visibility = "hidden";
}



var whichDog = 0;

function ddInit(e, divname) {
	whichDog = document.getElementById(divname);  
	offsetx = findPosX(e);
	offsety = findPosY(e);
	nowX = parseInt(whichDog.style.left);
	nowY = parseInt(whichDog.style.top);
	ddEnabled=true;
	document.onmousemove = dd;
}

function dd(e) {
	if (!ddEnabled) return;
	whichDog.style.left = nowX+findPosX(e)-offsetx; 
	whichDog.style.top = nowY+findPosY(e)-offsety;
	return false;  
}

document.onmouseup = Function("ddEnabled=false");

function ChangePaid(val) {
	stub = document.getElementById('changepaid'); stub.value = val; stub.form.submit();
}


function SumSellTotal() {
    tmp = document.getElementsByTagName('input');
	sum = 0;
    for (i=0; i<tmp.length; i++) if (tmp[i].name.indexOf('pricepaynum_') == 0) sum += parseFloat(tmp[i].value);
	fldsum = document.getElementById('sellpaytotal');
	sum = sum.toFixed(2);
	fldsum.value = sum;
}


function SwitchRefuseRows(val) {
	if (isMozilla) disp = 'table-row';
	else disp = 'block';
	document.getElementById('refuserow_2').style.display = 'none';
	document.getElementById('refuserow_3').style.display = 'none';
	if (val == 2) document.getElementById('refuserow_2').style.display = disp;
	if (val == 3) document.getElementById('refuserow_3').style.display = disp;
}


function HideRow(id) {
	document.getElementById(id).style.display = 'none';
}

function ShowRows(prefix) {
	if (isMozilla) disp = 'table-row';
	else disp = 'block';
	tmp = document.getElementsByTagName('tr');
    for (i=0; i<tmp.length; i++)  if (tmp[i].id.indexOf(prefix) == 0) tmp[i].style.display = disp;
}


function MarkCheckbox(fldname) {
	tmp = document.getElementsByName(fldname);
	for (i=0; i<tmp.length; i++) {
		if (tmp[i].checked) tmp[i].checked = false;
		else tmp[i].checked = true;
	}
}


function editor_insertHTML(myValue, fld) {
	if (fld == '') fld = 'message';
	myField = document.getElementById(fld);
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
	}
	else {
		myField.value += myValue;
	}
}



function ShowSubDivs(id) {
	tmp = document.getElementsByTagName('div');
    for (i=0; i<tmp.length; i++) {
		if (tmp[i].id.indexOf('div_'+id+'_') == 0) {
			if (tmp[i].style.display == 'block') tmp[i].style.display = 'none';
			else tmp[i].style.display = 'block';
		}
	}
}




function SwitchAllDivs(disp) {
	tmp = document.getElementsByTagName('div');
    for (i=0; i<tmp.length; i++) {
		if ((tmp[i].id.indexOf('div_') == 0) && (tmp[i].id.indexOf('div_0') == -1)) {
			tmp[i].style.display = disp;
		}
	}
}




function CopyToSubFlds(id, parent) {
	val = 0;
	tmp = document.getElementsByTagName('input');
    for (i=0; i<tmp.length; i++) {
		if ((tmp[i].id.indexOf('disc_'+parent+'_'+id) == 0)) {
			val = tmp[i].value;
			break;
		}
	}
    for (i=0; i<tmp.length; i++) if (tmp[i].id.indexOf('disc_'+id+'_') == 0) tmp[i].value = val;
}


function ShowSubPage(num, count) {
	for (i=1; i<=count; i++) {
		document.getElementById('subpage'+i).style.display = 'none';
		document.getElementById('pglink'+i).style.color = '#000066';
	}
	document.getElementById('subpage'+num).style.display = 'block';
	document.getElementById('pglink'+num).style.color = '#000000';
	if (document.getElementById('errbox')) document.getElementById('errbox').innerHTML = '';
}



function sortNumber(a, b) {
	a = parseInt(a);
	b = parseInt(b);
	return a-b;
}


function ReOrderPropPhotos(prefix) {
	tmp = document.getElementsByTagName('div');
	arr = new Array();
	counter = 0;
    for (i=0; i<tmp.length; i++) {
		if ((tmp[i].id.indexOf(prefix+'_') == 0)) {
			arr[counter] = tmp[i].style.top+'-'+tmp[i].id;
			counter++;
		}
	}
	arr.sort(sortNumber);
	ctop = 0;
	for (i=0; i<counter; i++) {
		stub = arr[i].split('-');
		id = stub[1];
		stop = ctop*110+20;
		document.getElementById(id).style.top = stop+'px';
		document.getElementById(id).style.left = '20px';
		stub = id.split('_');
		id = 'ord_'+stub[1];
		document.getElementById(id).value = ctop;
		ctop++;
	}
}

function ReOrderPages() {
	tmp = document.getElementsByTagName('div');
	arr = new Array();
	counter = 0;
	for (i=0; i<tmp.length; i++) {
		if ((tmp[i].id.indexOf('col_') == 0)) {
			arr[counter] = tmp[i].style.top+'-'+tmp[i].id;
			counter++;
		}
	}
	arr.sort(sortNumber);
	ctop = 0; parl = 10;
	for (i=0; i<counter; i++) {
		stub = arr[i].split('-');
		id = stub[1];
		stub2 = id.split('_');
		pid = stub2[1];
		stop = ctop*25+10;
		document.getElementById(id).style.top = stop+'px';
		l = parseInt(document.getElementById(id).style.left);
		for (j=0; j<10; j++) {
			if (i == 0) {
				document.getElementById(id).style.left = '10px';
				document.getElementById('lvl_'+pid).value = 0;
				break;
			}
			if ((l >= 10+30*j) && (l < 10+30*(j+1))) {
				stubl = (10+30*j);
				if (stubl > parl+30) stubl = parl+30;
				parl = stubl;
				document.getElementById(id).style.left = parl+'px';
				document.getElementById('lvl_'+pid).value = parseInt((parl-10)/30);
				break;
			}
		}
		document.getElementById('ord_'+pid).value = ctop+1;
		ctop++;
	}
}

function ReOrderPagePhotos() {
	tmp = document.getElementsByTagName('div');
	arr = new Array();
	counter = 0;
    for (i=0; i<tmp.length; i++) {
		if ((tmp[i].id.indexOf('photo_') == 0)) {
			arr[counter] = tmp[i].style.top+'-'+tmp[i].id;
			counter++;
		}
	}
	arr.sort(sortNumber);
	ctop = 0;
	for (i=0; i<counter; i++) {
		stub = arr[i].split('-');
		id = stub[1];
		stop = ctop*110+20;
		document.getElementById(id).style.top = stop+'px';
		document.getElementById(id).style.left = '20px';
		stub = id.split('_');
		id = 'ord_'+stub[1];
		document.getElementById(id).value = ctop;
		ctop++;
	}
}

function ReOrderPageHeads() {
	tmp = document.getElementsByTagName('div');
	arr = new Array();
	counter = 0;
    for (i=0; i<tmp.length; i++) {
		if ((tmp[i].id.indexOf('head_') == 0)) {
			arr[counter] = tmp[i].style.top+'-'+tmp[i].id;
			counter++;
		}
	}
	arr.sort(sortNumber);
	ctop = 0;
	for (i=0; i<counter; i++) {
		stub = arr[i].split('-');
		id = stub[1];
		stop = ctop*110+20;
		document.getElementById(id).style.top = stop+'px';
		document.getElementById(id).style.left = '20px';
		stub = id.split('_');
		id = 'hord_'+stub[1];
		document.getElementById(id).value = ctop;
		ctop++;
	}
}

function ScrollToElement(el) {
	if (!document.getElementById(el)) return ;
	y = document.getElementById(el).offsetTop;
	window.scrollTo(0, y);
}

function MapPartChange(val) {
	document.getElementById('vmobiusers').style.display = 'none';
	document.getElementById('vcustomers').style.display = 'none';
	document.getElementById('vjobs').style.display = 'none';
	if (val == '1') document.getElementById('vcustomers').style.display = 'block';
	if (val == '2') document.getElementById('vmobiusers').style.display = 'block';
	if (val == '3') document.getElementById('vjobs').style.display = 'block';
	doQuery(0, 'console.php?s=ajax&a=selpins&type='+val);
}

function SwitchCustomerSearch(val) {
	if (val =='1') document.getElementById('customersearch').style.display = 'none';
	if (val == '2') document.getElementById('customersearch').style.display = 'block';
}

function SwitchMobiUserSearch(val) {
	if (val =='1') document.getElementById('mobiusersel').style.display = 'none';
	if (val == '2') document.getElementById('mobiusersel').style.display = 'block';
}

function Reload() {
	document.location = document.location;
}

// get date to display in copyright section of the footer.
function showYear()
{
	var theDate = new Date();
	document.write(theDate.getFullYear());
}

// reset search field
function clearSearch()
{
	document.getElementById('searchField').value = '';
}

// populate search field
function addSearchTxt()
{
	var srchFld = document.getElementById('searchField').value;
	if (srchFld == ''){
		document.getElementById('searchField').value = 'Site search...';
	}
}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters))
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }
}


// plxeditor stuff
function editor_insertHTML(myValue) {
	myField = document.getElementById('ta_message');
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
	}
	else {
		myField.value += myValue;
	}
	CountChars();
}


function CountChars() {
	if (!document.getElementById('ta_message')) return;
	chars = document.getElementById('ta_message').value.length;
	if (chars > 140) document.getElementById('numchars').innerHTML = "<font color='red'>"+chars+"</font>";
	else document.getElementById('numchars').innerHTML = chars;
	//if (chars > 160) document.getElementById('ta_message').value = document.getElementById('ta_message').value.substring(0, 160)
}

// PLX FORMS stuff
// dateFld Functions

function SetDay(fldname, seldate, selshow) {
	HidePLayer('layer_'+fldname, true);
	whichDog = parent.document.getElementById(fldname);
	whichDog.value = seldate;
	whichDog = parent.document.getElementById('show_'+fldname);
	whichDog.value = selshow;
}

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y) curtop += obj.y;
	return curtop;
}

function HidePLayer(divname) {
	whichDog = parent.document.getElementById(divname);
	whichDog.style.display = "none";
}

function ChangeStyle(el, newclass) {
	el.className = newclass;
}

function SetFrSrc(fld) {
	whichDog = document.getElementById(fld);
	fr = document.getElementById('if_'+fld);
	fr.src = 'plxforms.php?s=calendar&fld='+fld+'&sel='+whichDog.value;
}





// numField Functions

var stubfld, stublimit, stoptimer, chcounter, stupstep;

function CheckNumLimit(fld, from, to) {
	whichDog = document.getElementById(fld);
	val = whichDog.value;
	if ((to!=0) && (val>to)) whichDog.value = to;
	if (val<from) whichDog.value = from;
}

function numeralsOnly(evt) {
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ?
	evt.keyCode : ((evt.which) ? evt.which : 0));
	if (charCode > 31 && (charCode < 48 || charCode > 57)) return false;
	return true;
}

function NumUp() {
	whichDog = document.getElementById(stubfld);
	val = parseInt(whichDog.value)+stupstep;
	if ((stublimit!=0) && (val>stublimit)) return;
	 whichDog.value = val;
}

function FastNumUp() {
	if (!stoptimer) {
		NumUp();
		chcounter++;
		tm = 1;
		if (chcounter < 1000) tm = 10;
		if (chcounter < 500) tm = 15;
		if (chcounter < 100) tm = 20;
		if (chcounter < 50) tm = 50;
		if (chcounter < 30) tm = 100;
		setTimeout('FastNumUp()', tm);
	}
}

function StartNumUp(fld, to, step) {
	stubfld = fld;
	stublimit = to;
	stupstep = step;
	stoptimer = false;
	chcounter = 1;
	NumUp();
	setTimeout('FastNumUp()', 1000);
}

function EndTimer() {
	stoptimer = true;
}

function NumDown() {
	whichDog = document.getElementById(stubfld);
	val = parseInt(whichDog.value)-stupstep;
	if (val<stublimit) return;
	 whichDog.value = val;
}

function FastNumDown() {
	if (!stoptimer) {
		NumDown();
		chcounter++;
		tm = 1;
		if (chcounter < 1000) tm = 10;
		if (chcounter < 500) tm = 15;
		if (chcounter < 100) tm = 20;
		if (chcounter < 50) tm = 50;
		if (chcounter < 30) tm = 100;
		setTimeout('FastNumDown()', tm);
	}
}

function StartNumDown(fld, from, step) {
	stubfld = fld;
	stublimit = from;
	stupstep = step;
	stoptimer = false;
	chcounter = 1;
	NumDown();
	setTimeout('FastNumDown()', 1000);
}





// Misc Functions

function ShowFloatLayer(divname) {
	document.getElementById(divname).style.visibility = "visible";
}
function HideFloatLayer(divname) {
	document.getElementById(divname).style.visibility = "hidden";
}
function ShowHideLayer(divname) {
	whichDog = document.getElementById(divname);
	if (whichDog.style.display == "none") whichDog.style.display = "block";
	else  whichDog.style.display = "none";
}


function ShowLayer(divname) {
	document.getElementById(divname).style.display = "block";
}
function HideLayer(divname) {
	document.getElementById(divname).style.display = "none";
}
function ShowHideFloatLayer(divname) {
	whichDog = document.getElementById(divname);
	if (whichDog.style.visibility == "hidden") whichDog.style.visibility = "visible";
	else  whichDog.style.visibility = "hidden";
}


// Form Validation Functions

function checkPassword (strng, lenfrom, lento) {
	var error = "";
	if (strng == "") error = "You didn't enter a password.";
    var illegalChars = /[\W_]/; // allow only letters and numbers
    if ((strng.length < lenfrom) || (strng.length > lento)) error = "The password is the wrong length.";
    else if (illegalChars.test(strng)) error = "The password contains illegal characters.";
	//else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/))))  error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.";
	return error;
}

function checkUsername(strng, lenfrom, lento) {
	var error = "";
	if (strng == "") error = "You didn't enter a username.";
	else {
		var illegalChars = /[\W_]/;
		if ((strng.length < lenfrom) || (strng.length > lento)) error = "The username is the wrong length.";
		else if (illegalChars.test(strng)) error = "The username contains illegal characters.";
		//else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/))))  error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.";
	}
	return error;
}

function checkEmail(strng) {
	var error = "";
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(strng))) error = "Please enter a valid email address.";
	else {
		var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
		if (strng.match(illegalChars))  error = "The email address contains illegal characters.";
	}
	return error;
}


function checkPhone(strng, maxlength) {
	var error = "";
	var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
	if (isNaN(parseInt(stripped))) error = "The phone number contains illegal characters.";
	else if (!(stripped.length > maxlength)) error = "The phone number is the wrong length.";
	return error;
}


function checkDropdown(choice) {
    var error = "";
    if (choice == 0) error = "You didn't choose an option from the drop-down list.";
	return error;
}


function isEmpty(strng) {
	// use with [combo].selectedIndex
	var error = "";
	if (strng.length == 0) error = "The mandatory text area has not been filled in."
	return error;
}


/**********************************************************************************
 *
 *********************************************************************************/
var xmlHttp;

function getXMLHTTP() {
	var A = null;
	try {
		A = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e) {
		try {
			A = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc) {
			A = null;
		}
	}
	if (!A && typeof XMLHttpRequest != "undefined") {
		A = new XMLHttpRequest();
	}
  return A;
}


function doQuery(e, queryString, senddata, showloading) {
	if (senddata) {
		senddata = senddata.split(' ')
		stub = '';
		for (var i=0;i < senddata.length;i++) {
			var fld = senddata[i];
			stub += fld + '=' + encodeURIComponent(document.getElementById(fld).value) + '&';
		}
	}
	$.ajax({
		url: queryString,
		data:stub,
		dataType:'script',
		type :'POST',
		error: function(XMLHttpRequest, textStatus, errorThrown){}
	});
	return;
	if (showloading) Loading(e);
	searching = true;
	if (xmlHttp && xmlHttp.readyState != 0) {
		xmlHttp.abort()
	}
	xmlHttp=getXMLHTTP();
	if (xmlHttp) {
		xmlHttp.open("POST", queryString, true);
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4 && xmlHttp.responseText && searching) {
	      		try {
	      			eval(xmlHttp.responseText);
	      		}
	      		catch(e) {
					/*alert(xmlHttp.responseText + ' test ' + e);
					errorWindow=window.open("", "", "height=500, width=600,toolbar=no,scrollbars=yes,menubar=no,resizable=yes");
	      			errorWindow.document.write('test test '.xmlHttp.responseText);*/
	      		}
	      		searching = false;
			}
		}
		if (senddata) {
			senddata = senddata.split(' ')
			stub = '';
			for (var i=0;i < senddata.length;i++) {
				var fld = senddata[i];
				stub += fld + '=' + encodeURIComponent(document.getElementById(fld).value) + '&';
			}
			xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
			xmlHttp.send(stub);
		}
		else xmlHttp.send(null);
	}
}


function Loading(e) {
	if (e) {
		var position = e.position();
		$('#loading').css("left", position.left);
		$('#loading').css("right", position.right);
		$('#loading').show();
		$('#ajaxpop').css("left", position.left);
		$('#ajaxpop').css("right", position.right);
	}
	else {
		$('#loading').css("left",$(document).width()/2-50);
		$('#loading').css("top",$(document).height()/2-50);
		$('#loading').show();
	}
}


function MoveAjax(e) {
	d = document.getElementById('ajaxpop');
	x = findPosX(e)+15;
	y = findPosY(e)+5;
	d.style.left =  x+'px';
	d.style.top =  y+'px';
}

function Reposition() {
	$('#loading').css("left",$(document).width()/2-200);
	$('#loading').css("top",$(document).height()/2-50);
}

/*
function findPosX(e) {
	var posx = 0;
	if (!e) var e = window.event;
	if (e.pageX) 	posx = e.pageX;
	else if (e.clientX) posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
	return posx;
}

function findPosY(e) {
	var posx = 0;
	if (!e) var e = window.event;
	if (e.pageY) posy = e.pageY;
	else if (e.clientY) posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	return posy;
}

}*/

function URLencode(sStr) {
    return escape(sStr).replace(/\+/g, '%2B').replace(/\"/g,'%22').replace(/\'/g, '%27');
  }


whichDog = 0;

function ddInit(e, divname) {
	whichDog = document.getElementById(divname);
	offsetx = findPosX(e);
	offsety = findPosY(e);
	nowX = parseInt(whichDog.style.left);
	nowY = parseInt(whichDog.style.top);
	ddEnabled=true;
	document.onmousemove = dd;
}

function dd(e) {
	if (!ddEnabled) return;
	whichDog.style.left = (nowX+findPosX(e)-offsetx)+'px';
	whichDog.style.top = (nowY+findPosY(e)-offsety)+'px';
	return false;
}

document.onmouseup = Function("ddEnabled=false");

function HideAjax() {
	document.getElementById('ajaxpop').style.visibility='hidden';
}


function right(e) {
	return false;
	if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2)) return false;
	else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) {
		alert("Sorry, you do not have permission to right click.");
		return false;
	}
	return true;
}


function PhotoNav(e, dom, prev, next) {
	w = parseInt(document.getElementById('ajaxpop').style.width);
	onethird = parseInt(w/3);
	x = e.clientX-parseInt(document.getElementById('ajaxpop').style.left)
	if ((x < onethird) && prev) doQuery(0, dom+'/admin/index.php?s=ajax&a=popphoto&norepos&photoid='+prev, '');
	if ((x > 2*onethird) && next) doQuery(0, dom+'/admin/index.php?s=ajax&a=popphoto&norepos&photoid='+next, '');
	if ((x > onethird) && (x < 2*onethird)) HideAjax();
}


-->
