// <![CDATA[
function noStar(inputStr) {
for (i = 0; i < inputStr.length; i++) {
var c = inputStr.charAt(i);
if ( c =="*" ) {
return false;
}
}
return true;
}
function validateSearchForm(a, url) {
if (a == 1) {
var input = document.header1.qt2.value;
var alertDisplay='';
/* 
if(input.length < 3){
alertDisplay+='Input must be at least 3 characters long.\n';
}
if(!noStar(input)){
alertDisplay+='\n';
alertDisplay+='An asterisk is not allowed in the input. \n';
}
*/
if(alertDisplay!=''){
alert(alertDisplay);
document.header1.qt2.focus();
document.header1.qt2.select();
return false;
}
if(document.header1.qt2.value == 'USサイト検索(製品番号入力)') {
document.header1.PART_NUMBER.value = '';
document.header2.PART_NUMBER.value = '';
}else {
document.header1.PART_NUMBER.value = document.header1.qt2.value;
document.header2.PART_NUMBER.value = document.header1.qt2.value;
}
document.header1.QueryText.value = document.header1.PART_NUMBER.value;
}
if (a == 2) {
if(document.header2.qt.value == 'USサイト検索(キーワード入力)') {
document.header2.qt.value ='';
}
document.header2.action="http://www.freescale.com/webapp/search/Serp.jsp";
document.header2.QueryText.value = document.header2.qt.value;
}
return true;
}
function submit(a,url) {
if (a==1) {
if(document.header.qt.value == 'USサイト検索(キーワード入力)') {
document.header.qt.value ='';
}
document.header.action =url;
}
if (a==2) {
var input = document.header.qt2.value;
var alertDisplay='';
if(input.length < 3){
alertDisplay+='Input must be at least 3 characters long.\n';
}
/* if(!noStar(input)){
alertDisplay+='\n';
alertDisplay+='An asterisk is not allowed in the input. \n';
}*/
if(alertDisplay!=''){
alert(alertDisplay);
document.header.qt2.focus();
document.header.qt2.select();
return;
}
if(document.header.qt2.value == 'USサイト検索(製品番号入力)') {
document.header.PART_NUMBER.value = '';
}else {
document.header.PART_NUMBER.value = document.header.qt2.value;
}
document.header.action = url ;
}
document.header.method = "POST";
document.header.submit();
}
function resetsearch(whichbox){
	if (document.getElementById(whichbox).value == ""){
		if (whichbox == "parts"){
			document.getElementById(whichbox).value = "USサイト検索(製品番号入力)";
		}else{
			document.getElementById(whichbox).value = "USサイト検索(キーワード入力)";
		}
	};
}

function getCookieLoginStatus() {
var name='SessID';
var start = document.cookie.indexOf(name+"=");
var temp = document.cookie.substring(start);
var indext = temp.indexOf("SessID=");
if (indext == -1) {
return false;
}
var val=temp.substring(indext+1);
if (val.length > 0) {
return true;
}
return false;
}
// ]]>

function partnerSwitch() {
    var $active = $('#partners a.active');

    if ( $active.length == 0 ) $active = $('#partners a:last');

    var $next =  $active.next().length ? $active.next()
        : $('#partners a:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(document).ready(function(){
 
//	$('#news').newsfeed('http://feeds.feedburner.com/FSL_PRESSRELEASES');	
//	//$('#events').eventsfeed('http://www.freescale.com/files/test/redesign1/FSL_EVENTS.xml');
//	$("#twitterbox").css({'height':'110px', 'overflow-y' : 'scroll', 'overflow-x':'hidden'}).tweet();
//	$('#cnv li').css({'border-right':'1px solid #c3cfd1'});

	setInterval( "partnerSwitch()", 5000 );
	
	/** script to read events json file and display in events area on homepage **/
/*
	 $.getJSON("http://www.freescale.com/files/test/redesign1/FSL_EVENTS.json", function(json) {
	   var index = json.events.length;
	   var i=0;
	   var htmlstr ="";   
		for (i=0;i<index;i++)
			{
				var title = json.events[i].title;
				var date =  json.events[i].date;
				var link =  json.events[i].link;
				var place =  json.events[i].location;
				htmlstr += '<div class="eventsItem">' + date +', <a href="' + link + '">' + title + '</a>, ' + place + '</div>';
		};
		//htmlstr += "</ul>";	   
		$('#events').html(htmlstr);
	 });
*/
	
	
	$('#searchtop li').hover(function(){
		$('input#parts').val($(this).attr('title'));
		},
		function(){
	
	      $('input#parts').val($('a.active').attr('title'));
		}
	);
	
   $('#searchtop li a').click(function(){
		$('#searchtop li a').removeClass('active');								   
		$(this).addClass("active");	
	
	});

var bulletON = "http://www.freescale.com/files/test/redesign1/bullet-on.png";
var bulletOFF = "http://www.freescale.com/files/test/redesign1/bullet-off.png";

	/** script to read events json file and display in events area on homepage **/
/*
	 $.getJSON("http://www.freescale.com/files/test/redesign1/hmpg_videos.json", function(hmpg) {
	   var index = 10;
	   var i=0;
	   var htmlstr =""; 
		for (i=0;i<index;i++)
			{	var title = hmpg.videos[i].title;
				var link =  hmpg.videos[i].link;
				var time =  hmpg.videos[i].time;
				var image = hmpg.videos[i].image;
				if (i ==0) {
				htmlstr += '<div class="ytube"><a href="' + link + '" class="media"><img src="'+ bulletON +'" class="bullet"></a><div class="videoInfo" image="'+ image +'" title="' + title + '" time="' + time + '"></div></div>';
				} else {
				htmlstr += '<div class="ytube"><a href="' + link + '" class="media"><img src="'+ bulletOFF +'" class="bullet"></a><div class="videoInfo" image="'+ image +'" title="' + title + '" time="' + time + '"></div></div>';
				};
		};
		$('#bullets').html(htmlstr);	
		var firstmovie = $('a.media:first').attr('href');
		var firsttitle = $('.videoInfo:first').attr('title');
		var firsttime = $('.videoInfo:first').attr('time');
		$('#title').text(firsttitle+" ("+time+")");
		var firstimage = $('.videoInfo:first').attr('image');
	 	jwplayer('container').setup({
	  	  'flashplayer': 'http://www.freescale.com/files/mediaplayer/player.swf',
	  	  'image' : firstimage,
	  	  'file': firstmovie,
	  	  'width': 240,
	  	  'height': 200,
		  'skin': 'http://www.freescale.com/files/mediaplayer/skins/simple/simple.zip'
	 	});
	 });
*/

/*
	$("a.media").live("click",function(){
			$('.bullet').attr('src',bulletOFF);						   
			$(this).find('img.bullet').attr('src',bulletON);
			var htmlStr=$(this).next('.videoInfo').attr('title');
			var timeStr=$(this).next('.videoInfo').attr('time');
			$("div#title").html(htmlStr+" ("+timeStr+")");	
			var vidImage = $(this).next('.videoInfo').attr('image');
				
			
			var vid = $(this).attr("href");
			jwplayer().load([{file : vid, image : vidImage}]);
			return false;
	});
*/
});


