var isInternetExplorer = (window.navigator.userAgent.indexOf("MSIE") > 0);

if (!isInternetExplorer) {
HTMLElement.prototype.__defineGetter__("innerText", 
function () { return(this.textContent); });
HTMLElement.prototype.__defineSetter__("innerText", 
function (txt) { this.textContent = txt; });
}

function changeImages() {
	if (document.images) {
		for (var i=0; i<changeImages.arguments.length; i += 2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i + 1];
		}
	}
}

function openPopupScroll(name, page, w, h)
{
  popupwindow = window.open(page, name, 'width=' + w + ', height=' + h + ', left='+(screen.width-w)/2+', top='+(screen.height-h)/2+', resizable=no, scrollbars=yes, toolbars=no, location=no, directories=no, status=no, menubar=no, copyhistory=no');
  if (window.focus) 
  {
    popupwindow.focus()
  }
}


function openNotes(id)
{
  w = 400;
  h = 250;
  notes_page = 'style-notes.asp?id=' + id;
  noteswindow = window.open(notes_page, 'noteswin', 'width=' + w + ', height=' + h + ', left='+(screen.width-w)/2+', top='+(screen.height-h)/2+', resizable=no, scrollbars=no, toolbars=no, location=no, directories=no, status=no, menubar=no, copyhistory=no');
  
  if (window.focus) 
  {
    noteswindow.focus()
  }
  if (!noteswindow.opener)
    noteswindow.opener = self;
}

function rot13(string) {
  var aCode = 'a'.charCodeAt();
  var zCode = 'z'.charCodeAt();
  var ACode = 'A'.charCodeAt();
  var ZCode = 'Z'.charCodeAt();
  var result = '';
  for (var c = 0; c < string.length; c++) {
    var charCode = string.charCodeAt(c);
    if (charCode >= aCode && charCode <= zCode) {
      charCode = aCode + (charCode - aCode + 13) % 26;
    } else if (charCode >= ACode && charCode <= ZCode) {
      charCode = ACode + (charCode - ACode + 13) % 26;
    }
    result += String.fromCharCode(charCode);
  }
  return result;
}

function DisplayEmail(doc, name) {
  doc.write('<a href=\"mailto:' + rot13(name) + '\">');
  doc.write(rot13(name));
  doc.write('</a>');
}

function emailcheck(str) 
{
  var at="@";
  var dot=".";
  var lat=str.indexOf(at);
  var lstr=str.length;
  // var ldot=str.indexOf(dot);
  
  if (str.indexOf(at) == -1)
  {
   alert("Invalid E-mail Address");
   return false;
  }
  
  if (str.indexOf(at) == -1 || str.indexOf(at) === 0 || str.indexOf(at) == lstr)
  {
   alert("Invalid E-mail Address");
   return false;
  }
  
  if (str.indexOf(dot) == -1 || str.indexOf(dot) === 0 || str.indexOf(dot) == lstr)
  {
    alert("Invalid E-mail Address");
    return false;
  }
  
  if (str.indexOf(at, (lat + 1)) != -1)
  {
    alert("Invalid E-mail Address");
    return false;
  }
  
  if (str.substring(lat - 1, lat) == dot || str.substring(lat+1, lat+2) == dot)
  {
    alert("Invalid E-mail Address");
    return false;
  }
  
  if (str.indexOf(dot, (lat + 2)) == -1)
  {
    alert("Invalid E-mail Address");
    return false;
  }
  
  if (str.indexOf(" ") != -1)
  {
    alert("Invalid E-mail Address");
    return false;
  }
  
  return true;
}

function fullScreen(theURL) {
  window.open(theURL, '', 'fullscreen=yes, scrollbars=auto');
}

var newwindow;
function openPopupImage(img, w, h)
{
  /*
  if (newwindow) {
    newwindow.close();
  }
  */
  newwindow = window.open('', 'newwin', 'width=' + w + ', height=' + h + ', left='+(screen.width-w)/2+', top='+(screen.height-h)/2+', resizable=no, scrollbars=no, toolbars=no, location=no, directories=no, status=no, menubar=no, copyhistory=no');

  newwindow.document.write('<html><head><title>Albi Homes</title></head>');
  newwindow.document.write('<body background="' + img + '" style="margin-left: 0; margin-right: 0; margin-top: 0;">');
  newwindow.document.write('<a href="javascript:self.close()"><img alt="Click window to close." src="' + img + '" width="' + w + '" height="' + h + '" border="0"></a>');
  newwindow.document.write('</body></html>');
  newwindow.document.close();

  if (window.focus) 
  {
    newwindow.focus()
  }
}

function openFloorPlan(img, w, h)
{
  fp_page = 'fp.asp?image=' + img + '&w=' + w + '&h=' + h;
  window.open(fp_page, '', 'width=' + w + ', height=' + h + ', left='+(screen.width-w)/2+', top='+(screen.height-h)/2+', resizable=no, scrollbars=no, toolbars=no, location=no, directories=no, status=no, menubar=no, copyhistory=no');
}

function openPopup(name, page, w, h)
{
  popupwindow = window.open(page, name, 'width=' + w + ', height=' + h + ', left='+(screen.width-w)/2+', top='+(screen.height-h)/2+', resizable=no, scrollbars=no, toolbars=no, location=no, directories=no, status=no, menubar=no, copyhistory=no');
  if (window.focus) 
  {
    popupwindow.focus()
  }
}

function openNewWindow(URLtoOpen, windowName, windowFeatures) {
	var newWindow = window.open(URLtoOpen, windowName, windowFeatures);
}

function zeroPad(num, count) { 
	var numZeropad = num + '';
	while(numZeropad.length < count) {
	
	numZeropad = "0" + numZeropad; 
	}
	return numZeropad;
}

function getCheckedValue(radioObj) {
	if(!radioObj) {
		return "";
	}
	var radioLength = radioObj.length;
	if(radioLength === undefined) {
		if(radioObj.checked) {
			return radioObj.value;
		}	else {
			return "";
		}
	}
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


/*************************/

function GetXmlHttpObject() {
	var xmlHttp = null;
	try {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp = new XMLHttpRequest();
	}
	catch (e) {
	  // Internet Explorer
	  try {
	    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	    }
	  catch (e) {
			try {
	      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");      
      }
	    catch (e) {
	      alert("Your browser does not support AJAX!");
	      return false;      
	    }
	  }
	}
	return xmlHttp;
}

/**********************/

function hSetCookie(name,value,expires){var cookie_string=name+"="+escape(value);if(expires){expires=new Date(expires);cookie_string+=";expires="+expires.toGMTString();}document.cookie=cookie_string+";path=/";} 
function hGetCookie(cookie_name){var regexp=new RegExp(cookie_name +"=(.*?)(;|$)","i");var results=regexp.exec(document.cookie);if(results){return(unescape(results[1]));}else{return null;}} 
function hasSubKeys(cookieName){var ret=false;var cookie=unescape(hGetCookie(cookieName));var subKeys=cookie.split("&");if(subKeys.length>=2){ret=true;}else{var subKeys=cookie.split("=");if(subKeys.length>=1){ret=true;}}return ret;}

function getCookieData(cookie){
	var ret=[];
	var subKeys=cookie.split("&");
	for (var i=0;i<subKeys.length;i++){
		//alert(subKeys[i]);
		var pos=subKeys[i].indexOf("=");
		if(pos!==0){
			//alert("cookieData["+subKeys[i].substring(0,pos)+']='+subKeys[i].substring(pos+1));
			ret[subKeys[i].substring(0,pos)]=subKeys[i].substring(pos+1);
		}
	}
	return ret;
}

function getCookie(cookieName,keyName){
	var ret;
	var cookie=unescape(hGetCookie(cookieName));
	//alert(cookie);
	if(keyName && hasSubKeys(cookieName)===true){
		var cookieData=getCookieData(cookie);
		ret=cookieData[keyName];
	}else{
		ret=cookie;
	}
	return ret;
}

function SetCookie(cookieName,keyName,value,expires){
	var thisCookie=unescape(hGetCookie(cookieName));
	if(thisCookie){
		if(keyName){
			//alert(keyName);
			var cookieData=getCookieData(thisCookie);
			cookieData[keyName]=value;
			value="";
			for (var cookie in cookieData){
				value +=cookie+"="+cookieData[cookie]+"&";
			}
			if(value.charAt(value.length-1)=="&") {
				value=value.substring(0,value.length-1);
			}
		}
	}
	//alert(cookieName+"\n"+value);
	hSetCookie(cookieName,value,expires);
}

function deleteCookie(name, path, domain)
{
  if (getCookie(name)){
    document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

