function resizeparentframe() {
parent.window.scrollTo(0,0);
var height = 100 + this.document.body.scrollHeight;
parent.document.getElementById('ifrm').style.height=height+"px"

}


function roll_over(img_name, img_src)
   {
   document[img_name].src = img_src;
   }
   
   
function loadIframe(iframeName, url, height) {
    if ( window.frames[iframeName] ) {
        window.frames[iframeName].location = url; 
          var theIframe = document.getElementById(iframeName);
          if (height > 0){
          	theIframe.style.height = height + 'px';
          }else{
          	theIframe.style.height = '800px';
          }
        return false;
    }
    return true;
}

function loadparentIframe(iframeName, url, height) {
	
    if (parent.document.getElementById(iframeName)) {
          if (height > 0){
          	parent.document.getElementById(iframeName).style.height = height + 'px';
          }else{
          	parent.document.getElementById(iframeName).style.height = '800px';
          }
          	window.frames[iframeName].location= url;
          	
        return false;
    }
    return true;
}

function searchbyId(){
	var id = stripNonNumeric(document.idsearch.propid.value);
		url = id + "/details.html";
		loadIframe("ifrm",url,"0");
	}

function calculateSavings(){
	var price = stripNonNumeric(document.savings.price.value);
	var percent = stripNonNumeric(document.savings.percent.value);
	var result = 0;
	result = price * percent /100;
	document.savings.save.value = numberFormat(result);
	
}

function stripNonNumeric( str ){
  str += '';
  var rgx = /^\d|\.|-$/;
  var out = '';
  for( var i = 0; i < str.length; i++ ){
    if( rgx.test( str.charAt(i) ) ){
      if( !( ( str.charAt(i) == '.' && out.indexOf( '.' ) != -1 ) ||
             ( str.charAt(i) == '-' && out.length != 0 ) ) ){
        out += str.charAt(i);
      }
    }
  }
  return out;
}

// This function formats numbers by adding commas
function numberFormat(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;
}
