var ROOT = ""

function getTaxiPrices(regionId)
{
	ajaxResult = new sack();		
	ajaxResult.requestFile = ROOT + '/ajax/get-taxi-prices.asp?regionId=' + regionId;	// Specifying which file to get
	ajaxResult.onCompletion = function(){ eval(ajaxResult.response); };	// Specify function that will be executed after file has been found
	ajaxResult.runAJAX();		// Execute AJAX function	
}

function ie6MouseHover(obj, classId)
{
	if(isIE6())
	{
		obj.className = classId;
	}
}
function isIE6()
{	
	var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;
	
	if(navigator.appName == "Microsoft Internet Explorer" && !ie7)
		return true;
	else
		return false;
}	
function textCounter( field, countfield, maxlimit ) {
  if ( field.value.length > maxlimit )
  {
    field.value = field.value.substring( 0, maxlimit );
    return false;
  }
  else
  {
    countfield.value = maxlimit - field.value.length;
  }
}

function deleteRowControls(divId)
{
	var cell = document.getElementById(divId);
	if(cell.hasChildNodes())
	{
		while(cell.childNodes.length >= 1)
		{
			cell.removeChild(cell.firstChild);       
		} 
	}
}

function updateRowControl(divId, nameId)
{
	nameObj=document.getElementById(nameId);	
	nameObj.value = parseInt(nameObj.value);

	if(nameObj.value > 30)
	{
		alert("Your party size cannot contain more than 30 people");
		return false;
	}
	deleteRowControls(divId);
	
	div=document.getElementById(divId);
		
	for(var i = 1; i <= nameObj.value; i++)
	{	
		newitem='<label class="flabel" for="partyName_' + i + '">' + i + ') Name</label><input type="text" id="partyName_' + i + '" name="partyNameList" size="30" /> <span style="position:relative;top:-3px;">Age</span> <input type="text" id="partyAge_' + i + '" name="partyAgeList" size="5" />';	
		newnode=document.createElement("div");
		newnode.id = nameObj.value;
		newnode.innerHTML=newitem;
	
		div.appendChild(newnode);
	}
}


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;
}
function round(number,X)
{
	// rounds number to X decimal places, defaults to 2
    X = (!X ? 2 : X);
    return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}
function formatNo(obj)
{
	val = safeValue(obj.value);
	obj.value = addCommas(val);
}
function safeValue(units)
{
	units = units.replace(/[^0-9\.]/g,"");
	return (units == "") ? 0 : parseFloat(units);
}
function toggleDiv(divId, type)
{
	obj = document.getElementById(divId);
	if(obj)
	{
		if(obj.style.display == type)
			obj.style.display = "none";
		else
			obj.style.display = type;
	}
}
function showDiv(divId, type)
{
	obj = document.getElementById(divId);
	if(obj)
	{
		obj.style.display = type;
	}
}
function hideDiv(divId)
{
	obj = document.getElementById(divId);
	if(obj)
	{
		obj.style.display = "none";
	}
}
function toUpper(obj)
{
	obj.value = obj.value.toUpperCase();
}
function changePropertyImage(newSrc, newCaption)
{
	imageObj = document.getElementById('largePropertyImage');
	if(imageObj)
	{
		imageObj.src = newSrc;		
		imageObj.alt = newCaption;
	}
}
function moveUp(element) {
  for(i = 0; i < element.options.length; i++) {
    if(element.options[i].selected == true) {
      if(i != 0) {
        var temp = new Option(element.options[i-1].text,element.options[i-1].value);
        var temp2 = new Option(element.options[i].text,element.options[i].value);
        element.options[i-1] = temp2;
        element.options[i-1].selected = true;
        element.options[i] = temp;
      }
    }
  }
}
function moveDown(element) {
  for(i = (element.options.length - 1); i >= 0; i--) {
    if(element.options[i].selected == true) {
      if(i != (element.options.length - 1)) {
        var temp = new Option(element.options[i+1].text,element.options[i+1].value);
        var temp2 = new Option(element.options[i].text,element.options[i].value);
        element.options[i+1] = temp2;
        element.options[i+1].selected = true;
        element.options[i] = temp;
      }
    }
  }
}
function updateList(list, textBox) {
  textBox.value = '';
  for(i = 0; i < list.options.length; i++) {
    if (i == 0) {
      textBox.value += list.options[i].value;
    } else {
      textBox.value += ',' + list.options[i].value;
    }
  }
}
function swap(list) {
  var j = 0;
  for(i = 0; i < list.options.length; i++) {
    if(list.options[i].selected == true) {
      j++;
      switch (j) {
        case 1:
        var i1 = i;
        var temp = new Option(list.options[i].text, list.options[i].value);
        break;
        case 2:
        var i2 = i;
        var temp2 = new Option(list.options[i].text, list.options[i].value);
        break;
      }
    }
  }
  if (j != 2) {
    alert('Only 2 items can be swapped');
  } else {
    list.options[i1] = temp2;
    list.options[i1].selected = true;
    list.options[i2] = temp;
    list.options[i2].selected = true;
  }
}

function selectOther(value)
{
	if(value == "Other:")
	{
		showDiv("titleOtherContainer", "inline");
	}
	else
	{
		hideDiv("titleOtherContainer");
	}
}

var win=null;
function newWindow(mypage,w,h)
{
	LeftPosition=(screen.width)?(screen.width-w)/2:100;
	TopPosition=(screen.height)?(screen.height-h)/2:100;
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win=window.open(mypage,"new",settings);
	return false;
}

if(document.all)
{
try {
document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}
}
	
var kkeys = [], ad = "38,40,37,39,65,13";
$(document).keydown(function(e)
{
	kkeys.push(e.keyCode);
	if(kkeys.toString().indexOf(ad) >= 0 )
	{
		$(document).unbind('keydown',arguments.callee);
		document.location = ROOT + '/admin/';        
	}
});


var areaListCache = new Array();

function updateSubAreas(areaId, targetObj)
{
    var obj      = targetObj;
    var objAjax  = null;
    
    obj.options.length = 0;	// Empty track select box
    obj.options[obj.options.length] = new Option("Please Wait...","");
	
    if(areaListCache[areaId])
    {
	    obj.options.length = 0;
	    eval(areaListCache[areaId]);
	    
	    return;
    }
	
    objAjax = new sack();		
    objAjax.requestFile = ROOT + '/ajax/get-subAreas.asp?areaId=' + areaId;	
    objAjax.onCompletion = function(){ 
        areaListCache[areaId] = this.response; 
        
        obj.options.length = 0;
	    eval(areaListCache[areaId]);
    };	
    
    objAjax.runAJAX();
}
