function focusOn(id){
    document.getElementById(id).focus();
}

function addslashes( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ates Goral (http://magnetiq.com)
    // +   improved by: marrtins
    // +   improved by: Nate
    // +   improved by: Onno Marsman
    // *     example 1: addslashes("kevin's birthday");
    // *     returns 1: 'kevin\'s birthday'

    return (str+'').replace(/([\\"'])/g, "\\$1").replace(/\0/g, "\\0");
}

function calcSqft(id){
  var x = document.getElementById("front_footageinput_box").value;
  var y = document.getElementById("depth_footageinput_box").value;
  if (x>0 &&y >0){
    document.getElementById(id).value=x*y;
    document.getElementById("acres").value= new Number(x*y/43560).toFixed(2);
  }
}

function listPrice(id){
  var x = document.getElementById("wholesale_priceinput_box").value;
  var y = document.getElementById("markup").value;
  if (x>0){
    document.getElementById("list_price").value= new Number(x*y).toFixed(0);
  }
  
}


function loadFields(){
  var x = document.getElementById("front_footageinput_box").value;
  var y = document.getElementById("depth_footageinput_box").value;
  if (x>0 &&y >0){
    document.getElementById("sqft").value=x*y;
    document.getElementById("acres").value= new Number(x*y/43560).toFixed(0);
  }

  x = document.getElementById("wholesale_priceinput_box").value;
  y = document.getElementById("markup").value;
  if (x>0){
    document.getElementById("list_price").value= new Number(x*y).toFixed(0);
  }
  loadSubdivisionInfo();
  loadCityInfo();
}

function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
  {alert(alerttxt);return false;}
else {return true}
}
}

function validate_form(thisform)
{
  with (thisform)
  {
  if (validate_required(idproperty,"Property Id must be completed!")==false)
    {idproperty.focus();return false;}
  }
}

function validate_form_mkt(thisform)
{
  with (thisform)
  {
  if (validate_required(idmarketing_partnerinput_box,"Marketing Partner Id must be completed!")==false)
    {idmarketing_partnerinput_box.focus();return false;}
  }
}

function showcenterdiv(Xwidth,Yheight,divid) {
// First, determine how much the visitor has scrolled

var scrolledX, scrolledY;
if( self.pageYoffset ) {
scrolledX = self.pageXoffset;
scrolledY = self.pageYoffset;
} else if( document.documentElement && document.documentElement.scrollTop ) {
scrolledX = document.documentElement.scrollLeft;
scrolledY = document.documentElement.scrollTop;
} else if( document.body ) {
scrolledX = document.body.scrollLeft;
scrolledY = document.body.scrollTop;
}

// Next, determine the coordinates of the center of browser's window

var centerX, centerY;
if( self.innerHeight ) {
centerX = self.innerWidth;
centerY = self.innerHeight;
} else if( document.documentElement && document.documentElement.clientHeight ) {
centerX = document.documentElement.clientWidth;
centerY = document.documentElement.clientHeight;
} else if( document.body ) {
centerX = document.body.clientWidth;
centerY = document.body.clientHeight;
}

// Xwidth is the width of the div, Yheight is the height of the
// div passed as arguments to the function:
var leftoffset = scrolledX + (centerX - Xwidth) / 2;
var topoffset = 60 + scrolledY + (centerY - Yheight) / 2;
// The initial width and height of the div can be set in the
// style sheet with display:none; divid is passed as an argument to // the function
var o=document.getElementById(divid);
var r=o.style;
r.position='absolute';
r.top = topoffset + 'px';
r.left = leftoffset + 'px';
r.display = "block";
if(divid=="login"){document.getElementById('username').focus();}
}

function showdeadcenterdiv(Xwidth,Yheight,divid) {
// First, determine how much the visitor has scrolled

var scrolledX, scrolledY;
if( self.pageYoffset ) {
scrolledX = self.pageXoffset;
scrolledY = self.pageYoffset;
} else if( document.documentElement && document.documentElement.scrollTop ) {
scrolledX = document.documentElement.scrollLeft;
scrolledY = document.documentElement.scrollTop;
} else if( document.body ) {
scrolledX = document.body.scrollLeft;
scrolledY = document.body.scrollTop;
}

// Next, determine the coordinates of the center of browser's window

var centerX, centerY;
if( self.innerHeight ) {
centerX = self.innerWidth;
centerY = self.innerHeight;
} else if( document.documentElement && document.documentElement.clientHeight ) {
centerX = document.documentElement.clientWidth;
centerY = document.documentElement.clientHeight;
} else if( document.body ) {
centerX = document.body.clientWidth;
centerY = document.body.clientHeight;
}

// Xwidth is the width of the div, Yheight is the height of the
// div passed as arguments to the function:
var leftoffset = scrolledX + (centerX - Xwidth) / 2;
var topoffset = scrolledY + (centerY - Yheight) / 2;
// The initial width and height of the div can be set in the
// style sheet with display:none; divid is passed as an argument to // the function
var o=document.getElementById(divid);
var r=o.style;
r.position='absolute';
r.top = topoffset + 'px';
r.left = leftoffset + 'px';
r.display = "block";
if(divid=="login"){document.getElementById('username').focus();}
} 

function hideit(id) {
document.getElementById(id).style.display='none';
}

function showitFull(id) {
document.getElementById(id).style.display='block';
}

function underline(id){
  id.style.textDecoration='underline';
}
function nounderline(id){
  id.style.textDecoration='none';
}

function openIFrame(iFrameId,winURL)
{
ifId=gmobj(iFrameId)
ifId.src=winURL
} 


function ismaxlength(obj){
  var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
  if (obj.getAttribute && obj.value.length>mlength){
    obj.value=obj.value.substring(0,mlength);
    alert("Maximum characters for this field is "+mlength+"!");
  }
}


function updateFileAssoc(id){
  //alert("test2");

  document.getElementById('iframeAudio').src="uploader_multiple_basic.php?id="+id+"&type=audio";
  document.getElementById('iframeVideo').src="uploader_multiple_basic.php?id="+id+"&type=video";
  document.getElementById('iframePhoto').src="uploader_multiple_basic.php?id="+id+"&type=photo";
  
  //openIFrame('iframeAudio',"uploader_multiple_basic.php?id="+id+"&type=audio");
  //openIFrame('iframePhoto',"uploader_multiple_basic.php?id="+id+"&type=photo");
  //openIFrame('iframeVideo',"uploader_multiple_basic.php?id="+id+"&type=video");
}

function checkEnter(e,formID){ //e is event object passed from function invocation
    var characterCode;// literal character code will be stored in this variable

    if(e && e.which){ //if which property of event object is supported (NN4)
        e = e
        characterCode = e.which //character code is contained in NN4's which property
    }
    else{
        e = event
        characterCode = e.keyCode //character code is contained in IE's keyCode property
    }

    if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
        validate_login(formID) //submit the form
        return false
    }
    else{
        return true
    }
    //USE <input type="text" onKeyPress="checkEnter(event)">
}

function highlight(x){
	document.getElementById(x).style.background="yellow";
}

function unHighlight(x){
	document.getElementById(x).style.background="white";
}

function codeIt(id){
    var str;
    if(id.type=="checkbox"){
        str = id.name+id.checked+"d|d";
        id.value=str;
    }
    else if(id.type=="radio"){
        str = id.name+id.value+"d|d";
        id.value=str;
    }
    else if(id.type=="text"){
        str = id.name+id.value+"d|d";
        //id.value=str;
    }
    else if(id.type=="button"){
        str = id.name+id.value+"d|d";
        id.value=str;
    }
    submitIt(str);
}