// JavaScript Document

var months = new Array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

function openLegal(theID){
	window.open("http://www.subaru.co.za/scripts/showlegal.asp?ID=" + theID,"","left=0,top=0,width=600,height=500,scrollbars=yes,toolbar=no,left=0.top=0");
	return;
}

function testSelected(rb) {
	if (rb.length==undefined)
		return rb.checked;	
	
	for (count=0;count<rb.length;count++) {
		if (rb[count].checked)
			return true;
	}
	return false;
}

// utility panel code

function checkItem(itemID) {
	ret = "0";
	if ($(itemID).attr("class")) {
		if ($(itemID).attr("class").indexOf("hidepanel")==-1) ret="1"
	}

	return ret;
}

function alterUtility() {
	id = $(this).parent().attr("id");
	
	$(this).parent().toggleClass("showpanel");
	$(this).parent().toggleClass("hidepanel");
	
	cookie = "";
	
	cookie += "d:"+checkItem("#utilitydealership");
	cookie += "~p:"+checkItem("#utilitypoll");
	cookie += "~g:"+checkItem("#utilitygallery");
	cookie += "~l:"+checkItem("#utilitylogin");
	
	$.cookie('utility', cookie, { expires:60, path: '/' }); // set cookie
}

// verifies that thee email address provided is correct.

var reEmail = /^.+\@.+\..+$/
var defaultEmptyOK = false


function isEmpty(s) { 
  return ((s == null) || (s.length == 0))
}


function isEmail (s){
  if (isEmpty(s)) 
    if (isEmail.arguments.length == 1) return defaultEmptyOK;
    else return (isEmail.arguments[1] == true);
    
  else {
    return reEmail.test(s)
  }
}

// fancy js corner code

function setCorners() {
  el = document.getElementsByName('imagewrapper');  
  for (count=0;count<el.length;count++) {
    i = el[count].getElementsByTagName("img");
    if (i.length>0) {      
      el[count].style.width = i[0].width+"px";
    }
    makeRound(el[count]); 
  }
}

function makeRound(wrapper) {
  for (var i=1;i<=4;i++) {
    var curve = document.createElement('span');
   	curve.className	= 'curve'+i;
    wrapper.appendChild(curve);
 	}
}

// document load code

$(document).ready(function() { 
	//setCorners();			
	$(".utilitypanel .button").bind("click",alterUtility)
});

