//r59723 code to extract query parameter value
function extractQP(name)
{
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}


//First part here is to ease debugging and different options purely during the sprint
debug_url=location.href;

var addthis_down = debug_url.indexOf("status=sitedown");
var pos_check = debug_url.indexOf("pos=");

addthis_pub							 = 'freescale'; 
addthis_logo						 ='http://www.freescale.com/shared/images/freescale_logo.gif';
//addthis_logo						 ='http://www.freescale.com/files/worldwide/homepage/images/HMCHP.jpg';
//addthis_logo_background	 = 'EFEFFF';
//addthis_logo_color				 = '666699';
//addthis_brand						 = 'FREESCALE SEMICONDCUTOR';
addthis_brand						 = 'Freescale';
addthis_options					 = 'favorites, email, digg, delicious, stumbleupon, technorati, reddit, twitter, google , live, more';
//addthis_options					 = 'favorites, email, digg, delicious, reddit, twitter, google , live, more';
//addthis_options					 = 'favorites, email, digg, delicious, myspace, facebook, google , live, more';

addthis_hide_embed=false;



//Testing offset options
if(pos_check>0){
  addthis_offset_left=parseInt(extractQP('pos'));
}

var windowtitle=document.getElementsByTagName('title')[0].text;
addthis_title="Freescale - "+windowtitle;

if(addthis_down<0){
	//Added for Search History Start Feb 13 , 2009
	document.write("<a href=\"http://www.addthis.com/bookmark.php\" onclick=\"getPageURL();call_pbar_metrics('pb_share');return addthis_sendto();\"><img src=\"http://s9.addthis.com/button1-share.gif\" width=\"125\" height=\"16\" border=\"0\" alt=\"\" /></a>");
   // document.write("<a href=\"http://www.addthis.com/bookmark.php\" onmouseover=\"getPageURL();return addthis_open(this, '',addthis_url, addthis_title)\" onmouseout=\"addthis_close()\" onclick=\"return addthis_sendto()\"><img src=\"http://s9.addthis.com/button1-share.gif\" width=\"125\" height=\"16\" border=\"0\" alt=\"\" /></a>");
   //Added for Search History CCT64681 Start Feb 13 , 2009
   //document.write("<script type='text/javascript' src='http://s7.addthis.com/js/152/addthis_widget.js'></script>");
}

else{
  document.write("<a href=\"#\" onclick=\"alert(\'We apologize that this service is currently unavailable\')\"><img src=\"http://s9.addthis.com/button1-share.gif\" width=\"125\" height=\"16\" border=\"0\" alt=\"\" /></a>");
}

var tidindex;
function getPageURL()
{
	var windowtitle=document.getElementsByTagName('title')[0].text;
	addthis_title="Freescale - "+windowtitle;




	addthis_url=location.href;
	//alert("addthis_url.length  "+addthis_url.length);
//var test=addthis_url.lastIndexOf("&");
//alert(test);
	//alert("addthis_url  "+addthis_url);
	tidindex=addthis_url.indexOf("?tid=");
	//alert("tidindex  "+tidindex);
	if(tidindex<0)
	{
		tidindex=addthis_url.indexOf("&tid=");
	}
	
//alert("tidindex  "+tidindex);
	if((addthis_url.indexOf("Serp"))>0)
	{         
		//alert("FOR SERP");
         if(tidindex < 0)
		{
			var queschk=addthis_url.indexOf("?");
			if(queschk>0)
			{
				//alert("querytxt"+querytxt);
				//if query string present
				
				if((querytxt=="") || (querytxt==null))
				{
					addthis_url=addthis_url+"&tid=fsladdthis";
				}
				else
				addthis_url=addthis_url+"&tid=fsladdthis&QueryText="+querytxt;
			}
			else
			{
				//if no Query string present
				addthis_url=addthis_url+"?tid=fsladdthis&QueryText="+querytxt;
			}
		}
		else
		{ 
             addthis_url= tidHandle(addthis_url);
			// alert(querytxt);
			 if(!((querytxt=="") || (querytxt==null)))
			{
			 addthis_url=addthis_url+"&QueryText="+querytxt;
			 }
		}

	}

	else if((addthis_url.indexOf("MainSERP"))>0)
	{
		//alert("FOR MAINSERP");
		//incase of MainSerp , get the hidden url value in case of GWT 
		 if(tidindex < 0)
		{
		addthis_url=window.location.protocol +'//'+ window.location.host+document.PartDirect.RETURL.value+"&tid=fsladdthis";
		}
		else
		{
			//addthis_url=document.PartDirect.RETURL.value;
			addthis_url=tidHandle(document.PartDirect.RETURL.value);
			 addthis_url=window.location.protocol +'//'+ window.location.host+addthis_url;
			
		}
	}	
	else if(tidindex> 0 )
	{
		 addthis_url=tidHandle(addthis_url)
		
	}

	else
	{
		//alert("IF TID NOT THERE");
		if(addthis_url.indexOf("#")>0){
			//if GWT hit then # will be appended , so append tid parameter after removing #...
			//alert("INDEX OF # = "+addthis_url.indexOf("#"));
			addthis_url=addthis_url.substring(0,addthis_url.indexOf("#"));	
		}
		//if tid parameter is not there, then simply append below parameter
		addthis_url =addthis_url+"&tid=fsladdthis";
	}

   


}

function tidHandle(addthislocal_url)
{
		newaddthis_url=addthislocal_url;
		var beforetid=newaddthis_url.substring(0,tidindex+1);
		//alert("beforetid"+beforetid);
		var includingtid=newaddthis_url.substring(tidindex+1,addthislocal_url.length);
		//to eliminate tid=something and replace with tid="fsladdthis"
		var indexamp=includingtid.indexOf("&");
		var frmampersand="";
		if(indexamp>0){
			//if one more parameter after tid , so get tht to eliminate tid parameter
			frmampersand=includingtid.substring(indexamp);
		}
		addthislocal_url =beforetid+"tid=fsladdthis"+frmampersand;	

		return addthislocal_url;

}

function copyInnerHTML(idName, url, title){
	
	/* following check is to make sure that only youtube urls are converted into 'watch' format */
	if (url.indexOf('youtube.com') > -1){

		url=url.replace('/v/','/watch?v=');
	}

	addthis_url="";
	addthis_title="";
	content="<a href=\"http://www.addthis.com/bookmark.php\" onclick=\"addthis_url='"+url+"'; addthis_title='Freescale - "+title+"'; return addthis_click(this,'');\" target=\"_blank\"><img src=\"http://s9.addthis.com/button1-addthis.gif\" width=\"125\" height=\"16\" border=\"0\" alt=\"Bookmark and Share\" /></a> <script type=\"text/javascript\">var addthis_pub = '"+addthis_pub+"';</script>";

	var div1=document.getElementById("contentDiv");
	if(div1){
		div1.parentNode.removeChild(div1);
	}

	var div=document.createElement("div")
	div.id="contentDiv"
	
	//div.style.marginLeft="300px"
	div.style.marginLeft="5px"
	div.innerHTML=content
	document.getElementById(idName).appendChild(div);
}
