//INFO NAVIGATION ROLLOVER SCRIPT
function navHover(imgName,state,folder) {
	if(document.images) {
		var x;
		var imgArray = imgName.split(",");
		for (x in imgArray) {
			var imgID = imgArray[x];
			if (!folder) {
				imgSrc = "/images/"+imgID+"_"+state+".gif";
			}
			else {
				imgSrc = "/images/"+folder+imgID+"_"+state+".gif";
			}
			document.getElementById(imgID).src = imgSrc;
		}
	}
}

// HOVER BOX HIDE/SHOW SCRIPT
function hoverBox(boxId) {
	if (document.getElementById(boxId).style.display=="block") {
		document.getElementById(boxId).style.display="none";
	}
	else {
		document.getElementById(boxId).style.display="block";
	}
}

// CLICK ON INFO BOX
function clickBox(boxId, cls) {
	var divs = document.getElementsByTagName('div');
	for (var i=0; i<divs.length; i++) {
		if(divs[i].className == cls) {
			divs[i].style.display="none";
		}
	}
	if (document.getElementById(boxId).style.display=="block") {
		document.getElementById(boxId).style.display="none";
	}
	else {
		document.getElementById(boxId).style.display="block";
	}
}

// POP UP WINDOW
function popUp(content, width, height) {
  if (width && height) {
    mywindow = window.open (content,"mywindow","status=1,width="+width+",height="+height);
    mywindow.moveTo(0,0);
  }
  else {
    mywindow = window.open (content,"_blank");
  }
  
 } 
 
 // FORM VALIDATION CHECK
function checkform(of) {
  if(!document.getElementById || !document.createTextNode){return;}
  if(!document.getElementById('required')){return;}
  
  var errorID='errormsg';
  var errorClass='error'
  var errorMsg='Please fillout or change the fields highlighted with a ';
  var errorImg='images/alert_icon.gif';
  var errorAlt='Error';
  var errorTitle='This field has an error!';
  var reqfields=document.getElementById('required').value.split(',');
  
// Cleanup old mess
  // if there is an old errormessage field, delete it
  if(document.getElementById(errorID)) {
    var em=document.getElementById(errorID);
    em.parentNode.removeChild(em);
  }
  // remove old images and classes from the required fields
  for(var i=0;i<reqfields.length;i++) {
    var f=document.getElementById(reqfields[i]);
    if(!f){continue;}
    if(f.previousSibling && /img/i.test(f.previousSibling.nodeName)) {
      f.parentNode.removeChild(f.previousSibling);
    }
    f.className='';
  }
  
  // loop over required fields
  for(var i=0;i<reqfields.length;i++) {
// check if required field is there
    var f=document.getElementById(reqfields[i]);
    if(!f){continue;}
	
	// test if the required field has an error, 
// according to its type
    switch(f.type.toLowerCase()) {
      case 'text':
        if(f.value=='' && f.id!='email'){cf_adderr(f)}              
// email is a special field and needs checking
        if(f.id=='email' && !cf_isEmailAddr(f.value)){cf_adderr(f)}              
      break;
      case 'textarea':
        if(f.value==''){cf_adderr(f)}              
      break;
      case 'checkbox':
        if(!f.checked){cf_adderr(f)}              
      break;
      case 'select-one':
        if(!f.selectedIndex && f.selectedIndex==0){cf_adderr(f)}              
      break;
    }
  }
  if (!document.getElementById(errorID)) {
  	popUp("thankyou.html","300","200");
  }
  return !document.getElementById(errorID);
  
  //Tool methods
  function cf_adderr(o) {
  // create image, add to and colourise the error fields
    var errorIndicator=document.createElement('img');
    errorIndicator.alt=errorAlt;
    errorIndicator.src=errorImg;
    errorIndicator.title=errorTitle;
	errorIndicator.width=10;
	errorIndicator.height=10;
    o.className=errorClass;
    o.parentNode.insertBefore(errorIndicator,o);
	
	// Check if there is no error message
    if(!document.getElementById(errorID)) {
    // create errormessage and insert before submit button
      var em=document.createElement('div');
      em.id=errorID;
      var newp=document.createElement('p');
      newp.appendChild(document.createTextNode(errorMsg))
      // clone and insert the error image
      newp.appendChild(errorIndicator.cloneNode(true));
      em.appendChild(newp);
	  // find the submit button 
      for(var i=0;i<of.getElementsByTagName('input').length;i++) {
        if(/submit/i.test(of.getElementsByTagName('input')[i].type)) {
          var sb=of.getElementsByTagName('input')[i];
          break;
        }
      }
      if(sb) {
        sb.parentNode.insertBefore(em,sb);
      }  
    } 
  }
  function cf_isEmailAddr(str) {
  	return str.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/);
  }
}

//EMAIL TO A FRIEND SCRIPT
function emailPage() {
	var siteURL = "http://www.theuptown.net";
	var pageURL = window.location;
	var subject = "Uptown Oakland Luxury Apartments";
	var message = "I came across this site: "+siteURL+", featuring three luxury apartment buildings in downtown Oakland, and thought you might be interested. Check out the site, especially this page: "+pageURL+".";
	
	window.location="mailto:?SUBJECT="+subject+"&BODY="+message;
}

//FINISHES INFO BLURBS
//function finishBlurbs(building,finish) {
function finishBlurbs(buildingList) {
	var berkClassic = "<div class=\"fpfinishbox\" id=\"berkClassic\"><h3>The Thomas Berkley<br/>Classic Finish Package</h3><p>Whirlpool sleek black-on-black appliances, custom maple finish cabinetry with stainless steel accents, Absolute Black laminate counter tops in kitchen and bath, custom double stainless steel sinks in kitchens, upgraded fixtures and faucets. Updated woven Berber-style carpeting in living rooms and bedrooms, contemporary VCT tile in kitchens and baths. Designer pendant and track lighting. In-suite washer and dryer.</p></div>";
  var berkSignature = "<div class=\"fpfinishbox\" id=\"berkSignature\"><h3>The Thomas Berkley<br/>Signature Finish Package</h3><p>Whirlpool sleek black-on-black appliances, custom maple finish cabinetry with stainless steel accents, Absolute Black granite counter tops in kitchen and bath, custom top-mounted double stainless steel sinks in kitchens, upgraded fixtures and faucets. Dark cherry finish wood laminate flooring in living room and kitchen, updated woven Berber-style carpeting in bedrooms, ceramic tile in baths. Updated pendant and track lighting living rooms and bedrooms, contemporary VCT tile in kitchens and baths. Designer pendant and track lighting. In-suite washer and dryer.</p></div>";
  var berkName = "<h3>The Thomas Berkley</h3><a class=\"nolink\" onclick=\"clickBox('berkClassic','fpfinishbox');\">Classic</a> | <a class=\"nolink\" onclick=\"clickBox('berkSignature','fpfinishbox');\">Signature</a>";

  var willClassic = "<div class=\"fpfinishbox\" id=\"willClassic\"><h3>The William<br/>Classic Finish Package</h3><p>Whirlpool white-on-white appliances, custom white finish cabinetry with stainless steel accents, Moon Dust laminate counter tops in kitchen and bath, custom double stainless steel sinks in kitchens, upgraded fixtures and faucets. Updated woven Berber-style carpeting in living rooms and bedrooms, contemporary VCT tile in kitchens and baths. Designer pendant and track lighting. In-suite washer and dryer.</p></div>";
  var willSignature = "<div class=\"fpfinishbox\" id=\"willSignature\"><h3>The William<br/>Signature Finish package</h3><p>Whirlpool sleek white-on-white appliances, custom white finish cabinetry with stainless steel accents, Moon Dust granite counter tops in kitchen and bath, custom top-mounted double stainless steel sinks in kitchens, upgraded fixtures and faucets.  Natural maple finish wood laminate flooring in living room and kitchen, updated woven Berber-style carpeting in bedrooms, ceramic tile in baths. Designer pendant and track lighting. In-suite washer and dryer.</p></div>";
  var willName = "<h3>The William</h3><a class=\"nolink\" onclick=\"clickBox('willClassic','fpfinishbox');\">Classic</a> | <a class=\"nolink\" onclick=\"clickBox('willSignature','fpfinishbox');\">Signature</a>";

  var telClassic = "<div class=\"fpfinishbox\" id=\"telClassic\"><h3>The Telegraph<br/>Classic Finish Package</h3><p>Whirlpool white-on-white appliances, custom white finish cabinetry with stainless steel accents, Golden Garnet laminate counter tops in kitchen and bath, custom double stainless steel sinks in kitchens, upgraded fixtures and faucets. Updated woven Berber-style carpeting in living rooms and bedrooms, contemporary VCT tile in kitchens and baths. Designer pendant and track lighting. In-suite washer and dryer.</p></div>";
  var telSignature = "<div class=\"fpfinishbox\" id=\"telSignature\"><h3>The Telegraph<br/>Signature Finish Package</h3><p>Whirlpool sleek white-on-white appliances, custom white finish cabinetry with stainless steel accents, Golden Garnet granite counter tops in kitchen and bath, custom top-mounted double stainless steel sinks in kitchens, upgraded fixtures and faucets.  Natural maple finish wood laminate flooring in living room and kitchen, updated woven Berber-style carpeting in bedrooms, ceramic tile in baths. Designer pendant and track lighting. In-suite washer and dryer.</p></div>";
  var telPremier = "<div class=\"fpfinishbox\" id=\"telPremier\"><h3>The Telegraph<br/>Premier Finish Package</h3><p>Whirlpool stainless steel appliances, custom dark mocha cabinetry with stainless steel accents, Luna Pearl granite counter tops in kitchens and baths, custom top-mounted stainless steel sinks in kitchens, upgraded fixtures and faucets. Premier wood laminate flooring in living rooms and kitchens, updated woven Berber-style carpeting in bedrooms, ceramic tile in baths. Designer pendant and track lighting. In-suite washer and dryer.</p></div>";
  var telAName = "<h3>The Telegraph A</h3><a class=\"nolink\" onclick=\"clickBox('telClassic','fpfinishbox');\">Classic</a> | <a class=\"nolink\" onclick=\"clickBox('telSignature','fpfinishbox');\">Signature</a>";
	var telBName = "<h3>The Telegraph B</h3><a class=\"nolink\" onclick=\"clickBox('telPremier','fpfinishbox');\">Premier</a>";

	document.write ("<p><a href=\"javascript:popUp('finishes.html','638','359')\">View our designer finishes</a></p>");

	var buildingList = buildingList.split(',');

  for (var i=0; i<buildingList.length; i++) {
    var building = buildingList[i];

	if (building == "berk"){
    document.write (berkName);
    /*if (finish == "cla") {
      document.write (berkClassic);
    }
    else if (finish == "sig") {
      document.write (berkSignature);
    }*/
 }
 else if (building == "will"){
    document.write (willName);
    /*if (finish == "cla") {
      document.write (willClassic);
    }
    else if (finish == "sig") {
      document.write (willSignature);
    }*/
 }
 else if (building == "telA"){
    document.write (telAName);
    /*if (finish == "cla") {
      document.write (telClassic);
    }
    else if (finish == "sig") {
      document.write (telSignature);
    }*/
 }
 else if (building == "telB"){
    document.write (telBName);
    /*if (finish == "cla") {
      document.write (telClassic);
    }
    else if (finish == "sig") {
      document.write (telSignature);
    }
    else if (finish == "pre") {
      document.write (telPremier);
    }*/
 }}
 
for (var i=0; i<buildingList.length; i++) {
    var building = buildingList[i];

	if (building == "berk"){
    document.write (berkClassic);
    document.write (berkSignature);
 }
 else if (building == "will"){
    document.write (willClassic);
    document.write (willSignature);
 }
 else if (building == "telA"){
    document.write (telClassic);
    document.write (telSignature);
 }
 else if (building == "telB"){
   document.write (telPremier);
 }
 }
}


// Exterior Links
function externalLinks() {
  if (document.getElementsByTagName) {
    var allLinks = document.getElementsByTagName('a');
    for (var i=0; i<allLinks.length; i++) {
      var thisLink = allLinks[i];
      // Find all links with a rel of "external"
      if (thisLink.getAttribute('rel') == "external") {
        thisLink.setAttribute("target", "_blank");
      }
    }
  }
}
window.onload=externalLinks;

/* ************************************************************************* */
// EHO popup box

	function hud(){
		window.open('http://www.forestcitytimes.com/res/EHO/EHOwebstatement.html','EHOStatement','height=325,width=500');
	}
