function flash ( url, id, width, height, vars, attributes ) {    
	document.write('<embed id="'+id+'" src="'+url+'" width="'+width+'" height="'+height+'" flashvars="'+vars+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" '+attributes+' />');
}

function breadcrumbs(){  
  var sURL = new String;
  var bits = new Array();
  var x = 0;
  var stop = 0;
  var output = "<a href=\"/\"><img src=\"/images/icon_home.gif\" border=\"0\" />Home</a>&nbsp;&rsaquo;&nbsp;";
  sURL = location.href;
  var containsFileExtension = ( ( ( sURL.indexOf(".aspx") > 0 ) || ( sURL.indexOf(".html") > 0 ) ) && ( sURL.indexOf("index.html") < 0) && ( sURL.indexOf("index.aspx") < 0) );
  sURL = sURL.slice(8,sURL.length);
  var chunkStart = sURL.indexOf("/");
  sURL = sURL.slice(chunkStart+1,sURL.length)
  while(!stop){
    chunkStart = sURL.indexOf("/");
    if (chunkStart != -1){
      bits[x] = sURL.slice(0,chunkStart)
      sURL = sURL.slice(chunkStart+1,sURL.length);
    }else{
      stop = 1;
    }
    x++;
  }
  var bitsToUse = (containsFileExtension ? bits.length : bits.length-1) ;
  for(var i=0; i<bitsToUse; i++){
	 if (bits[i] == "v2") continue;
    output += "<a href=\"";
    for(var y=1;y<x-i;y++){
      output += "../";
    }
	
    output += bits[i] + "/\">" + bits[i].replace(/_/gi, " " ) + "</a>&nbsp;&rsaquo;&nbsp;";
 }
  document.write(output + document.title );
}


function selectNavSection() {
	var URLParts = String(location.href).split("/");
	var section = URLParts[3];
	if ( section == "v2" ) {
		section = URLParts[4]; // for v2
	}
	var snavSection = String("navitem_" + section);
	if (document.getElementById(snavSection)) {
		document.getElementById(snavSection).className="selected";
	}
}


function printpage() {
  window.print()
}






/* FORM VALIDATION */
function validate( nextAction ) {
	//http://www.sitepoint.com/article/client-side-form-validation
	
	var inputs = document.getElementsByTagName('input');
	var selects = document.getElementsByTagName('select');
	var textareas = document.getElementsByTagName('textarea');
	//var formItems = document.getElementsByTagName('form')[0].childNodes;

	return validateItems( [inputs, selects, textareas], nextAction );
} 

function validateItems( items, nextAction ) {
	var str = "";
	
	// loop through all input elements in form
	for(var elm in items) {
		var elements = items[elm];
		
		// loop through all input elements in form
		for(var i = 0; i < elements.length; i++) {
			
			// check if element is mandatory; ie has a error message
			var errorMsg = elements.item(i).getAttribute('errorMsg');
			if (errorMsg) {
				elements.item(i).setAttribute('onfocus', 'resetValidationError(this)');
				resetValidationError( elements.item(i) );
			}
			
			//var pattern = elements.item(i).getAttribute('pattern');
			//var emailPattern = /^(.+)@(.+)$/;
			
			if (errorMsg != null) {
				var value = elements.item(i).value;
				if ( value.length <= 0 ) {
					// if an invalid character is found or the element was left emtpy
					str += elements.item(i).getAttribute('errorMsg') + "\n";
					// notify user by changing background color
					elements.item(i).parentNode.className += " invalidRow";
					elements.item(i).className += " invalidField";
				}
			}
		}
	
	}
	
	if (str != "") {
		// do not submit the form
		alert(str);  
		return false;
	} else {
		// form values are valid; submit
		if( nextAction == "print" ) {
			print();
		}
		return true;
	}
}

function resetValidationError( element ) {
	if (element.parentNode.className == " invalidRow" || element.parentNode.className == "invalidRow") {
		element.parentNode.className = "";
	} else if (element.parentNode.className.indexOf(" invalidRow") > -1) {
		element.parentNode.className = element.parentNode.className.split(" invalidRow")[0];
	}
	if (element.className == " invalidField" || element.className == "invalidField") {
		element.className = "";
	} else if (element.className.indexOf(" invalidField") > -1) {
		element.className = element.className.split(" invalidField")[0];
	}
}

function addNonBr( quote ) {
	var splitQuote = quote.split(" ");
	if ( splitQuote[splitQuote.length-1].indexOf("</span>") > -1 ) {
		splitQuote[splitQuote.length-1] = splitQuote[splitQuote.length-1].replace("</span>", "");
		var closeSpans = "</span></span>";
	} else {
		var closeSpans = "</span>";
	}
	splitQuote[splitQuote.length-1] = "<span style=\"white-space:nowrap\">" + splitQuote[splitQuote.length-1];
	var quote = splitQuote.join(" ");
	
	return [quote, closeSpans];
}



function show( items ) {
	for(var i=0; i<items.length; i++) {
		document.getElementById(items[i]).className="visible";
	}
}
function hide( items ) {
	for(var i=0; i<items.length; i++) {
		document.getElementById(items[i]).className="invisible";
	}
}



function createEmailThisLink ( url ) {
	var popOptions = '"/Contact_Us/EmailThisForm.aspx?Comments='+ url +'&Title=' + document.title +'", "EmailThisPopup", "width=420,height=450,scrollbars=no"';
	document.write("<a href='javascript:popup("+ popOptions +");'><img src='/images/icon_mail.gif' border='0' />Email this</a>");
}



function popup ( url, popName, popOptions ) {
	window.open(url,popName,popOptions);
}



function createFeedbackLink ( linktext, action ) {
	//ContactDept=1&Comments=X 
	if ( action == "Subscription" ) {
		var query = "?Comments=I would like to subscribe to The Karis Group newsletter.&ContactDept=4";
	}
	if ( action == "UpdateNotification" ) {
		var query = "?Comments=Please e-mail me when this section is updated: " + document.location.href;
	}
	document.write('<a href="/Contact_Us/Feedback.aspx'+ query + '">'+ linktext + '</a>');
}

				

function chkAge ( id ) {
	var DOB = document.getElementById( id ).value;
	if (DOB.length == 10) {
		var year = DOB.split("/")[2];
		if (year.length == 4 && year < 1989) {
			document.getElementById("SignatureLegalGuardian").className="visible";
			document.getElementById("SignaturePatient").className="invisible";
		} else {
			document.getElementById("SignatureLegalGuardian").className="invisible";
			document.getElementById("SignaturePatient").className="visible";
		}
	}
}


function getCurrentDate() {
	var currentTime = new Date()
	var month = currentTime.getMonth() + 1
	var day = currentTime.getDate()
	var year = currentTime.getFullYear()
	var curDate = month + "/" + day + "/" + year;
	
	return curDate;
}



function displayQuotesOLD( quotevar ) {	
          
	if ( quotevar == "quotes_CurrentSection" ) {
		var URLParts = String(location.href).split("/");
		var section = URLParts[3];
		if ( section == "v2" ) {
			section = URLParts[4]; // for v2
		}
		
		var quotes = quotes_Default;
		var quotesForSection = String("quotes_" + section);
		if ( !quotesForSection || quotesForSection.indexOf(".html") == -1 ) {
			quotes = eval("quotes_" + section);
		}	
		
	} else {
		var quotes = quotevar;
	}
	
	var randomQuote = Math.round( Math.random()*(quotes.length-1) );
	document.write( '<div class="quote"><table width="80%" align="center" cellpadding="0" cellspacing="0" border="0"><tr><td valign="middle">' );
	
	// insert non breaking span to keep last word together with the ending quote
	
	// write the quote html
	if ( quotes[randomQuote][1] && quotes[randomQuote][1].length > 1 ) {
		var quote = addNonBr( quotes[randomQuote][0] );
		document.write( '<img src="/images/quote_left.gif" />' + quote[0] + '<img src="/images/quote_right.gif" />' + quote[1] + '<div class="quoteName">' + quotes[randomQuote][1] + '</div>' );
	} else {
		var quote = addNonBr( quotes[randomQuote] );
		document.write( '<img src="/images/quote_left.gif" />' + quote[0] + '<img src="/images/quote_right.gif" />' + quote[1] );
	}
	
	document.write( '</td></tr></table></div>' );
}

//--------------------------------------------------------------------------------------------------------------
//New functionality to scroll through twitter quotes. 6/8/2010 Jamie Ayer
var quoteIntervalId = 0;
var MaskIntervalId = 0;
var quotesArray;
var randomQuote;
var qText;   


var m_FadeOut = 255;
var m_FadeIn = 33;
var m_Fade = 33;
var m_FadeStep = 3;
var m_FadeWait = 3000;
var m_bFadeOut = false;
var m_iFadeInterval;
var arrFadeCursor = 0;
var arrFadeMax;

//Called from pages beneath Contact Us button.  Makes initial call to Twitter page.
function displayQuotes( quotevar ) {  	
       
   	
   	//Defaults up to 20 Tweets with a max of 200.
   	//ref http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses-user_timeline
	var url = 'http://twitter.com/statuses/user_timeline/karisfeedback.json?callback=tCallbackKarasFeedback&count=200';	
	var script = document.createElement('script');		
	script.setAttribute('src', url);
    document.getElementsByTagName('head')[0].appendChild(script);      
    
    m_iFadeInterval = setInterval(fade_ontimer, 10);     
    
    //Set initial array in case of Twitter Site down.
    randomQuote = Math.round( Math.random()*(quotes_Default_Twitter.length-1) );    
    qText = js_RemoveChar(quotes_Default_Twitter[randomQuote]);       
    //class="quote background-color: #212121;color: #CACACA;font-family: Verdana, Arial, sans-serif;font-size: 13px;line-height: 15px;"
    document.write( '<div style="background-color:#212121;font-family: Verdana, Arial, sans-serif;font-size: 13px;line-height: 15px;"><table height="170px" width="80%" align="center" cellpadding="0" cellspacing="0" border="0"><tr><td height="150px" valign="middle">' );
	document.write( '<div id="QuoteContent"><a id="fade_link">' + "\"" + qText + "\"" +  '</a></div>');	
	document.write( '</td></tr><tr><td height="20px" valign="middle"><div width="100%" align="right" id="QuoteLink"><a style="text-decoration:none;color:#ffc736;" href="/About_Us/TwitterFeedback.aspx"><img width="15px" height="15px" border="0" src="/Images/Twitter.png" hspace=6>More..</a></div></td></tr></table></div>' ); 
}

//Rotating Tweets while users stays on current page.
function SetNewTwit()
{      
    //If Twitter Callback fails, pull quotes from Hard Coded Array for the time being.    
   if( quotesArray != null && quotesArray.length > 0 )
   {        
        //arrFadeMax = quotesArray.length-1;
        randomQuote = Math.round( Math.random()*(quotesArray.length-1) );            
        qText = js_RemoveChar(quotesArray[randomQuote].text);  
        document.getElementById('QuoteContent').innerHTML = '<a id="fade_link">'+ "\"" + qText + "\"" + '</a>';
   } 
   else
   {        
        //arrFadeMax = quotes_Default_Twitter.length-1;
        randomQuote = Math.round( Math.random()*(quotes_Default_Twitter.length-1) );         
        qText = js_RemoveChar(quotes_Default_Twitter[randomQuote]); 
        document.getElementById('QuoteContent').innerHTML = '<a id="fade_link">'+ "\"" + qText + "\"" + '</a>';
   }               
}

//Called based on json call to twitter.  Does the actual work upon returning data.  Copy of tweets stored in local array to releive calls to server.
function tCallbackKarasFeedback(twitters) {

  try
  {
      if( twitters.length > 0 )
      {       
           quotesArray = twitters;   
      }     
  }
  catch(err){}  
}

//Helper function to strip out existing Quotations so it looks ok with the quote images on the page.
function js_RemoveChar(str)
{
    remove1 = '"';remove2 = '“';remove3 = '”';
    regExp1 = new RegExp("["+remove1+"]","g");
    regExp2 = new RegExp("["+remove2+"]","g");
    regExp3 = new RegExp("["+remove3+"]","g");   
    
    var msg =  str.replace(regExp1,"");
    msg = msg.replace(regExp2,"");
    msg = msg.replace(regExp3,"");
    
    return msg;
}


function fade_ontimer(){
	if (m_bFadeOut){
		m_Fade += m_FadeStep;
		if (m_Fade > m_FadeOut){		
			clearInterval(m_iFadeInterval);
			setTimeout(Faderesume, m_FadeWait);
			m_bFadeOut=false;
		}
	}else{
		m_Fade -= m_FadeStep;
		if (m_Fade < m_FadeIn){
			arrFadeCursor++; // =1 add one to the arraycursr
			if (arrFadeCursor > arrFadeMax){
				arrFadeCursor = 0; // this would reset the curser back to the beginning of the array index
			}
			SetNewTwit();
			m_bFadeOut = true; // ? i dont' know
		}	
	}
	var ilink = document.getElementById("fade_link");
	if ((m_Fade < m_FadeOut)&&(m_Fade > m_FadeIn)){
		ilink.style.color = "#" + ToHex(m_Fade);
	}
}

function Faderesume() {
  m_iFadeInterval = setInterval(fade_ontimer, 10);
}

function ToHex(strValue) {
  if( strValue < "34")
    return "212121";
    
  try {
    var result= (parseInt(strValue).toString(16));
    while (result.length !=2){ result= ("0" +result); }
    result = result + result + result;
    return result.toUpperCase();
  }
  catch(e){ }
}