// JAVASCRIPT PROGRAMMING BY SPHERE CONCEPTS LLC
// LOCATION: RENU.CITIZENRE.COM/WEBSITE
//=========================================================== GROUP DISPLAY FUNCTIONS

function findPosX(id) {
	var obj = document.getElementById(id);
	var curleft = 0;
	if(obj.offsetParent)
		while(1) 
		{
			curleft += obj.offsetLeft;
			if(!obj.offsetParent)
			break;
			obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

function hideGroup() {
	document.getElementById('groupMenu').style.visibility = 'hidden';
}

function showGroup() {
	if(document.getElementById('groupMenu') && document.getElementById('groupMenu').style.visibility == 'hidden') {
		newX = findPosX('group');
		//assign the Y coordinate
		document.getElementById('groupMenu').style.top = 71+'px';
		//assign the X coordinate
		document.getElementById('groupMenu').style.left = newX+'px';
		document.getElementById('groupMenu').style.visibility = 'visible';
	}
}

//========================================================== READ ASSOCIATE'S COOKIES

function readCookie() {
	var nameEQ = "associate_seller=";
	var ca = document.cookie.split(';');
	for(var i=0;i<ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

// CARRY COOKIE OVER TO THE .NET SITE 

function cenet() {
	var whois = readCookie();
	window.alert(whois);
}

//=========================================================== POPULATE COPYRIGHT LINE

function get_copyright() {
	document.write("&copy 2006 The Citizenr&#275; Corporation");
}

//==================================================================== POP-UP WINDOWS

function m(rp) {
	winH = Math.round((screen.height - 600)/3);
	winW = Math.round((screen.width - 600)/2);
	winprops = 'top='+winH+',left='+winW+',height='+600+',width='+600+',statusbar=0,toolbar=no,menubar=no,personalbar=no,location=no,locationbar=no,resizable=no,scrollbars=yes,screenX=0,screenY=0,directories=no';
	switch (rp) {
		//
		// RENU > SERVICE > HOW IT WORKS : EXTRA PAGES
		//-------------------------------------------- The Forward Rental Agreement
		case 'ren': tp = 'extras/svc_'+rp+'.htm'; tw=600; th=600; sc='yes'; win='new_win'; break
		//-------------------------------------------------------------------------------------- Rate Determination and Guarantees
		case 'rat': tp = 'extras/svc_'+rp+'.htm'; tw=600; th=600; sc='yes'; win='new_win'; break
		//-------------------------------------------------------------------------------------- Contract Period Options
		case 'per': tp = 'extras/svc_'+rp+'.htm'; tw=600; th=600; sc='yes'; win='new_win'; break
		//-------------------------------------------------------------------------------------- Security Deposit and Payment Options
		case 'dep': tp = 'extras/svc_'+rp+'.htm'; tw=600; th=600; sc='yes'; win='new_win'; break
		//-------------------------------------------------------------------------------------- The EPC Process
		case 'epc': tp = 'extras/svc_'+rp+'.htm'; tw=600; th=600; sc='yes'; win='new_win'; break
		//-------------------------------------------------------------------------------------- The O&M Process
		case 'oem': tp = 'extras/svc_'+rp+'.htm'; tw=600; th=600; sc='yes'; win='new_win'; break
		//-------------------------------------------------------------------------------------- Net-Metering
		case 'met': tp = 'extras/svc_'+rp+'.htm'; tw=600; th=600; sc='yes'; win='new_win'; break
		//-------------------------------------------------------------------------------------- Reporting and Billing
		case 'bil': tp = 'extras/svc_'+rp+'.htm'; tw=600; th=600; sc='yes'; win='new_win'; break
		//-------------------------------------------------------------------------------------- Contract Termination and Alternative Options
		case 'ter': tp = 'extras/svc_'+rp+'.htm'; tw=600; th=600; sc='yes'; win='new_win'; break
		//-------------------------------------------------------------------------------------- Decommissioning the REnU 
		case 'dec': tp = 'extras/svc_'+rp+'.htm'; tw=600; th=600; sc='yes'; win='new_win'; break
		//
		// RENU : VISUAL AIDS
		// System Video 
		case 'sys': tp = 'http://www.citizenre.net/extras/tutorial.htm'; tw=800; th=520; sc='no'; win='new_sys'; break
		// Map on Potential Customer Page
		case 'map': tp = 'http://www.citizenre.net/extras/map.htm'; tw=900; th=475; sc='no'; win='new_map'; break
		// Solar Benefits Calculator
		case 'cal': tp = 'http://www.citizenre.net/extras/calculator.htm'; tw=600; th=600; sc='no'; win='new_cal'; break
		// Solar Benefits Calculator
		case 'cus': tp = 'http://www.citizenre.net/extras/customer_map.htm'; tw=443; th=435; sc='no'; win='new_cus'; break
		//default
		default: alert('Coming Soon');
	}
	if (tp != 'unavailable') {
		winH = Math.round((screen.height - th)/3);
		winW = Math.round((screen.width - tw)/2);
		winprops = 'top='+winH+',left='+winW+',height='+th+',width='+tw+',statusbar=0,toolbar=no,menubar=no,personalbar=no,location=no,locationbar=no,resizable=no,scrollbars='+sc+',screenX=0,screenY=0,directories=no';
		new_win = window.open(tp,win, winprops)
		new_win.focus();
	} else {
		alert('We are sorry!\nThe file requested is temporarily unavailable');
	}
}

//===================================================================================
//================================================== BEGIN: IE ACTIVATE FLASH CONTENT

function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

//=================================================== END: IE ACTIVATE FLASH CONTENT

//========================================================= OLD FUNCTIONS REPOSITORY

var index_facts = Math.round(Math.random()*9);

all_facts = new Array();
all_facts[0] = "In half an hour, enough of the sun's energy reaches the Earth's surface to meet the World's energy demand for one year.";
all_facts[1] = "A 100 kW solar panel installed equals to planting 11,000 trees in the Northeast of the United States.";
all_facts[2] = "Photovoltaics ('PV') is one of the most benign methods of power generation known. They are silent, produce no emissions, and use no fuel other than sunlight!";
all_facts[3] = "A standard PV module will re-generate the energy used in its manufacturing process in 2 to 3 years and last over 25 years.";
all_facts[4] = "Solar panels normally generate 10-14 kWhs per square foot per year. This means that you can generate all of your electricity needs with just your roof area.";
all_facts[5] = "A 100 kW solar panel installed equals to removing over 30 cars off the road, permanently.";
all_facts[6] = "One of the largest solar markets in the world today is Germany, which receives less solar energy than Massachusetts.";
all_facts[7] = "In solar energy terms, Los Angeles, CA receives only 30% more solar energy than Boston, MA.";
all_facts[8] = "A typical solar module converts 13-16% of the Sun's energy into electricity.";
all_facts[9] = "Over 80% of solar panels are made from silicon, the second most common element on the earth's surface. As used in PV modules, silicon is non-toxic.";
all_facts[10] = "Solar panels make extensive use of recycled materials and use no heavy metals."; 
all_facts[11] = "Solar panels are interconnected directly into the utility grid. You won't even notice that the solar system is on your roof - other than that you'll see your utility bills go down!";

function facts() {
	document.getElementById('facts').firstChild.data = all_facts[index_facts];
	index_facts++; if (index_facts > 11) index_facts = 0;	
}

function checkForm() {
var FirstName = document.marketer.first_name.value;
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
	if (FirstName.match(illegalChars) || FirstName == "") {
		//alert("please enter your correct First Name");
		document.marketer.first_name.className = "form-alert";
		document.marketer.first_name.focus();
		document.marketer.first_name.select();
		return false;
	}
var LastName = document.marketer.last_name.value;
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
	if (LastName.match(illegalChars) || LastName == "") {
		document.marketer.last_name.className = "form-alert";
		document.marketer.last_name.focus();
		document.marketer.last_name.select();
		return false;
	}
var Phone = document.marketer.phone.value;
	var stripped = Phone.replace(/[\(\)\.\/\\\-\ ]/g, '');
	if (stripped.length < 10) {
		document.marketer.phone.className = "form-alert";
		document.marketer.phone.focus();
		document.marketer.phone.select();
		return false;
	}
var Email = document.marketer.email.value;
	var emailFilter=/^.+@.+\..{2,4}$/;
	if (!(emailFilter.test(Email)) || Email == "") { 
   		document.marketer.email.className = "form-alert";
		document.marketer.email.focus();
		document.marketer.email.select();
		return false;
	}
}