// Green is Universal

// general js
function logoon(obj,logo) {
	document.getElementById(obj).src = '/images/networks/'+logo+'_green.png';
}

function logooff(obj,logo) {
	document.getElementById(obj).src = '/images/networks/'+logo+'_color.png';
}

//ad random number
var randDARTNumber=0;
function genSetRandDARTNumber(){
	randDARTNumber = Math.round(Math.random()*1000000000000);
}
genSetRandDARTNumber();

$(document).ready(function(){
	
	



// this section starting with "$(document).ready(function(){" requires the jQuery js library 
	$("#logo").click(function () {
		window.location.href = 'index.php';
	});
	
	//<input type="submit" value="Preview" id="comment-preview" name="preview" accesskey="v"/>
	$('input:submit').each(function(){
		var this_value = $(this).attr('value');
		var this_id = $(this).attr('value');
		var this_name = $(this).attr('value');
		var this_accesskey = $(this).attr('value');
		$(this).replaceWith('<button type="submit" id="'+this_id+'" name="'+this_name+'" accesskey="'+this_accesskey+'"><span>'+this_value+'</span></button>');
	});
	

	$(".inner_btn").wrapInner('<span></span>');
	$(".inner_btn").addClass('button_style');
	
	$(".split_box_right dl").hover(
		function(){
			$(this).addClass('hover');
		},
		function(){
			$(this).removeClass('hover');
		}
	);
	
	$('#featuredProgramming').addClass('box_style_two');
	



});

function getDocWidth() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {

    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return myWidth;
}
function displayGrass(){
	//297x173
	var d, imgWidth = 153, imgHeight = 184, leftPos = 0;
	var docWidth = getDocWidth(), g = document.getElementById('grassContainer');
	g.innerHTML=''; //Clear the Wrapper each time
	var divs = Math.floor( docWidth / imgWidth );
	var getGrassDiv = function(){
		var d = document.createElement('DIV');
		d.className = "grass";
		g.appendChild(d);
		return d;
	}
	for ( var i=0;i<divs;i++){
		d = getGrassDiv();
		d.style.left = leftPos;
		leftPos += imgWidth;
	}
	// Add the final piece with the remaining width	
	d = getGrassDiv();
	d.style.left = leftPos;
	d.style.width = docWidth % imgWidth;
}

function sendEmail () {
	var e = document.getElementById('errormsg');
	var f = document.getElementById('fff');

	e.innerHTML = '';

	var name  = document.getElementById('name').value;
	var email = document.getElementById('email').value;
	var msg   = document.getElementById('message').value;
	
	if (name == '' || email == '' || msg == '') {
		e.innerHTML = 'All fields are required';
		return false;
	}
	
	if (!validate_email(email)) {
		e.innerHTML = 'email must be a valid address';
		return false;
	}

	f.submit();
}

function validate_email(field) {
	apos=field.indexOf("@")
	dotpos=field.lastIndexOf(".")
	if (apos<1||dotpos-apos<2) {
		return false
	} else {
		return true
	}
}
function sendEcard (preview) {
        var e = document.getElementById('errormsg');
        var f = document.getElementById('fff');

        e.innerHTML = '';

        var et  = document.getElementById('to').value;
        var ef  = document.getElementById('from').value;
        var ete = document.getElementById('email_to').value;
        var efe  = document.getElementById('email_from').value;
        var em  = document.getElementById('message').value;

        if (et == '' || ef == '' || ete == '' || efe == '' || em == '') {
                e.innerHTML = 'All fields are required';
                return false;
        }

        if (!validate_email(ete)) {
                e.innerHTML = 'to email must be a valid address';
                return false;
        }

        if (!validate_email(efe)) {
                e.innerHTML = 'from email must be a valid address';
                return false;
        }

        if (preview) {
                document.getElementById('action').value = 'preview';
        } else {
                document.getElementById('action').value = 'send';
        }
        f.submit();
}

function checkForm(thisform)
  {
    if(thisform.first.value=='')
    {
      alert("First name field is required. Please fill it in.");
      return false;
    }
    if(thisform.last.value=='')
    {
      alert("Last name field is required. Please fill it in.");
      return false;
    }
    if(thisform.email.value=='')
    {
      alert("Email field is required. Please fill it in.");
      return false;
    }
    if(thisform.phone.value=='')
    {
      alert("Phone Number field is required. Please fill it in.");
      return false;
    }

    if(thisform.address.value=='')
    {
      alert("Address field is required. Please fill it in.");
      return false;
    }

    if(thisform.city.value=='')
    {
      alert("City field is required. Please fill it in.");
      return false;
    }

    if(thisform.state.value=='')
    {
      alert("State field is required. Please fill it in.");
      return false;
    }

    if(thisform.zip.value=='')
    {
      alert("Zip Code field is required. Please fill it in.");
      return false;
    }


    if(thisform.dob_month.value=='')
    {
      alert("Date of birth field is required. Please fill it in.");
      return false;
    }

    if(thisform.dob_day.value=='')
    {
      alert("Date of birth field is required. Please fill it in.");
      return false;
    }

    if(thisform.dob_year.value=='')
    {
      alert("Date of birth field is required. Please fill it in.");
      return false;
    }

    if(thisform.gyr.value=='')
    {
      alert("Please select a Green Routine.");
      return false;
    }

var c1 = document.getElementById("gyr1");
var c2 = document.getElementById("gyr2");
var c3 = document.getElementById("gyr3");
var c4 = document.getElementById("gyr4");
var c5 = document.getElementById("gyr5");
var c6 = document.getElementById("gyr6");
var c7 = document.getElementById("gyr7");
var c8 = document.getElementById("gyr8");
var c9 = document.getElementById("gyr9");
var c10 = document.getElementById("gyr10");
var c11 = document.getElementById("gyr11");
var bFoundOne = false;

if(c1.checked)
{
bFoundOne = true;
}
if(c2.checked)
{
bFoundOne = true;
}
if(c3.checked)
{
bFoundOne = true;
}
if(c4.checked)
{
bFoundOne = true;
}
if(c5.checked)
{
bFoundOne = true;
}
if(c6.checked)
{
bFoundOne = true;
}
if(c7.checked)
{
bFoundOne = true;
}
if(c8.checked)
{
bFoundOne = true;
}
if(c9.checked)
{
bFoundOne = true;
}
if(c10.checked)
{
bFoundOne = true;
}
if(c11.checked)
{
bFoundOne = true;
}

if(bFoundOne)
{
}
else
{
alert("No items were checked - please select a Green Routine.");
return false;
}

    //if all is OK submit the form

    thisform.submit();
  }
