/* Javascript Document for YLaw website 
 * Gaston R. Cangiano 10/21/08
 * gaston@speakeasy.net
 */

var buttonNum = 6
var imagesPath = 'images/'

var footerText = 'Younossi Law serves corporate, family, and individual clients throughout the U.S., with many of our clients in Northern California, the San Francisco Bay Area, East Bay, Oakland, Santa Rosa, Sacramento, Marin, San Jose, Santa Clara, Sunnyvale, Palo Alto and the greater Silicon Valley. &#124; &#169; 2009 Younossi Law. All Rights Reserved. &#124; <a href="/disclaimer.html" class="orange">Disclaimer</a> &#124; Designed by <a href="http://www.kitedesign.com" target="_blank" class="orange">Kite Design</a>'
var termsText = 'Terms: I understand and agree that I may receive a response to my inquiry from an attorney at the law firm. I agree that by submitting this inquiry, I will not be charged for the initial response, that I am not forming an attorney client relationship, and that I am not forming a confidential relationship. I understand that I may only retain Younossi Law or any of its attorneys as my attorney by entering into a written fee agreement, and that I am not hereby entering into a fee agreement.  I understand that I will not be charged for the response to this inquiry.'

function preloadButtons()
{
	var pics = new Array()
	for(i=1;i<=buttonNum;i++) {
		currName = 'button' + i
		if(!window.document.images[currName]) continue;
		currPath = window.document.images[currName].src
		extIndex = currPath.lastIndexOf('.')
		currPath = currPath.substring(0,extIndex) + '_hi' + currPath.substr(extIndex)
		pics[i] = new Image()
  		pics[i].src = currPath
		window.document.images[currName].onmouseover=function(e) {
				var e=window.event || e	// IE vs Firefox event model	   			
				element = e.srcElement || e.target
				btnPath = window.document.images[element.name].src
				idx = btnPath.lastIndexOf('.')
				btnPath = btnPath.substring(0,idx) + '_hi' + btnPath.substr(idx)
				window.document.images[element.name].src = btnPath
		}
		window.document.images[currName].onmouseout=function(e) { 
				var e=window.event || e	// IE vs Firefox event model	   			
				element = e.srcElement || e.target
				btnPath = window.document.images[element.name].src
				idx = btnPath.lastIndexOf('_')
				btnPath = btnPath.substring(0,idx) + btnPath.substr(idx+3)
				window.document.images[element.name].src = btnPath
		}
	}
}

function writeFooter()
{
	divObj = document.getElementById("footerbox")
	elemList = divObj.getElementsByTagName("p")
	elemList[0].innerHTML = footerText
}

/***********************************************
* Email Validation script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i

function checkmail(e){
	var returnval=emailfilter.test(e.value)
	if (returnval==false){
		alert("Please enter a valid email address.")
		e.select()
	}
	return returnval
}

// Copyright 2005 Bontrager Connection, LLC
// For more information, see the "Restoring Form Field Values"
//    article, first published in Possibilities ezine described
//    at http://willmaster.com/possibilities/

// The form's <form...> tag needs to contain this attribute:
//        onsubmit="javascript:return RecordFormInformation();"

// Put this JavaScript somewhere below the form.

// Two variables in this JavaScript can be customized.

// Customizable variable 1:
// Between the quotation marks, specify the form name:
var FormName = "main";

// Customizable variable 2:
// Between the quotation marks, specify the cookie name:
var CookieName = "FormRestoreCookie";


////////////////////////////////////////////////
//                                            //
//  No other customizations need to be done.  //
//                                            //
////////////////////////////////////////////////

function GetCookie() {
if(document.cookie.length < 1) { return ''; }
var cookiename = CookieName + '=';
var cookiebegin = document.cookie.indexOf(cookiename);
cookiebegin += cookiename.length;
var cookieend = document.cookie.indexOf(";",cookiebegin);
if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
return document.cookie.substring(cookiebegin,cookieend);
} // function GetCookie()


function RestoreFormInformation() {
var CookieString = GetCookie();
if(CookieString.length < 3) { return; }
CookieString = unescape(CookieString);
var CookiePieces = CookieString.split('\t\t');
for(var i = 0; i < CookiePieces.length; i++) {
   var pieces = CookiePieces[i].split('\t');
   if(pieces.length < 3) { continue; }
   if(pieces[1] == -1) {
      if( (pieces[2].indexOf('radio') > -1) || (pieces[2].indexOf('checkbox') > -1) ) {
         eval('document.forms.' + FormName + '.' + pieces[0] + '.checked = true;');
         }
      else {
         if(pieces[2].indexOf('select') > -1) { eval('document.forms.' + FormName + '.' + pieces[0] + '.selected = true;'); }
         else {
            var ta = pieces[3].split('"');
            pieces[3] = ta.join('\\"');
            var ta = pieces[3].split('\n');
            pieces[3] = ta.join('\\n');
            eval('document.forms.' + FormName + '.' + pieces[0] + '.value = "' + pieces[3] + '";');
            }
         }
      continue;
      }
   if( (pieces[2].indexOf('radio') > -1) || (pieces[2].indexOf('checkbox') > -1) ) { eval('document.forms.' + FormName + '.' + pieces[0] + '[' + pieces[1] + '].checked = true;'); }
   else {
      if(pieces[2].indexOf('select') > -1) { eval('document.forms.' + FormName + '.' + pieces[0] + '[' + pieces[1] + '].selected = true;'); }
      else {
         var ta = pieces[3].split('"');
         pieces[3] = ta.join('\\"');
         var ta = pieces[3].split('\n');
         pieces[3] = ta.join('\\n');
         eval('document.forms.' + FormName + '.' + pieces[0] + '[' + pieces[1] + '].value = "' + pieces[3] + '";');
         }
      }
   }
} // function RestoreFormInformation()


function RecordFormInformation() {
var l = new Number();
eval('l = document.forms.' + FormName + '.elements.length')
var NameList = new Array();
for (var i = 0; i < l; i++) {
   var FORMname = new String();
   var FORMfields = new Number();
   eval('FORMname = document.forms.' + FormName + '.elements[i].name;');
   if(FORMname.length < 1) { continue; }
   eval('FORMfields = document.forms.' + FormName + '.' + FORMname + '.length');
   if(parseInt(FORMfields) > 1) { FORMfields = parseInt(FORMfields); }
   else { FORMfields = 1; }
   NameList.push(FORMname + '\t' + FORMfields);
   }
var FORMfieldNameNumber = new Number();
var FORMvalue = new String();
var FORMtype = new String();
var Done = new String();
var CookiePieces = new Array();
for (var i = 0; i < NameList.length; i++) {
   var FORM_NL = NameList[i].split('\t');
   if(Done.indexOf(' ' + FORM_NL[0] + ' ') > -1) { continue; }
   Done += ' ' + FORM_NL[0] + ' ';
   if(FORM_NL[1] == 1) {
      FORMvalue = '';
      FORMfieldNameNumber = -1;
      eval('FORMtype = document.forms.' + FormName + '.' + FORM_NL[0] + '.type;');
      if( (FORMtype.indexOf('radio') > -1) || (FORMtype.indexOf('checkbox') > -1) ) {
         var checked = false;
         eval('checked = document.forms' + FormName + '.' + FORM_NL[0] + '.checked;');
         if(checked == true) { FORMvalue = 'C'; }
         }
      else {
         if(FORMtype.indexOf('select') > -1) {
            var checked = false;
            eval('checked = document.forms' + FormName + '.' + FORM_NL[0] + '.selected;');
            if(checked == true) { FORMvalue = 'S'; }
            }
         else { eval('FORMvalue = document.forms.' + FormName + '.' + FORM_NL[0] + '.value;'); }
         }
      if(FORMvalue.length < 1) { continue; }
      CookiePieces.push(FORM_NL[0] + '\t' + FORMfieldNameNumber + '\t' + FORMtype + '\t' + FORMvalue);
      continue;
      }
   for(var ii = 0; ii < FORM_NL[1]; ii++) {
      FORMvalue = '';
      FORMfieldNameNumber = ii;
      eval('FORMtype = document.forms.' + FormName + '.' + FORM_NL[0] + '[' + ii + '].type;');
      if(FORMtype == undefined) { eval('FORMtype = document.forms.' + FormName + '.' + FORM_NL[0] + '.type;'); }
      if( (FORMtype.indexOf('radio') > -1) || (FORMtype.indexOf('checkbox') > -1) ) {
         var checked = false;
         eval('checked = document.forms.' + FormName + '.' + FORM_NL[0] + '[' + ii + '].checked;');
         if(checked == true) { FORMvalue = 'C'; }
         }
      else {
         if(FORMtype.indexOf('select') > -1) {
            var checked = false;
            eval('checked = document.forms.' + FormName + '.' + FORM_NL[0] + '[' + ii + '].selected;');
            if(checked == true) { FORMvalue = 'S'; }
            }
         else { eval('FORMvalue = document.forms.' + FormName + '.' + FORM_NL[0] + '[' + ii + '].value;'); }
         }
      if(FORMvalue.length < 1) { continue; }
      CookiePieces.push(FORM_NL[0] + '\t' + FORMfieldNameNumber + '\t' + FORMtype + '\t' + FORMvalue);
      }
   }
var CookieString = new String();
CookieString = CookiePieces.join('\t\t');
CookieString = escape(CookieString);
document.cookie = CookieName + "=" + CookieString;
return true;
} // function RecordFormInformation()

function showterms()
{
	if(checkmail(document.forms.main.email)) {
		if(confirm(termsText)) {
			RecordFormInformation()
			return true
		}
	}
	return false
}
