/* Javascript file for Toshiba Mobile */

//alert("hello")
/* insert javascript stylesheet */
document.write("<link rel=\"StyleSheet\" href=\"/toshibaMobileAssets/css/toshibaMobileJavascript.css\" type=\"text/css\" media=\"screen\" />");


// Global Variables
var iepc,firefox,ns7,ns8,mozilla,safari,camino,OS;

/****	Check to see if the browser is Fully or Degraded support (not Basic) ****/
function fnBrowser() {	
	var ua = navigator.userAgent.toLowerCase();

	iepc = (((ua.indexOf("msie 7") != -1)||(ua.indexOf("msie 6") != -1)||(ua.indexOf("msie 5.5") != -1))&&(ua.indexOf("windows") != -1)&&(ua.indexOf("opera") == -1))? true:false;
	firefox = ua.indexOf("firefox") != -1 ? true:false; // pc or mac
	ns7 = ua.indexOf("netscape/7") != -1 ? true:false; // firefox mode
	ns8 = ua.indexOf("netscape/8") != -1 ? true:false; // firefox mode
	safari = ua.indexOf("safari") != -1 ? true:false;
	camino = ua.indexOf("camino") != -1 ? true:false;
	OS = ua.indexOf("windows") != -1? "PC":"MAC";		
	opera = ua.indexOf("opera/9") != -1 ? true:false;
	if (iepc||firefox||ns7||ns8||camino||safari||opera) {
		return true;
	} else {
		return false;
	}
}
fnBrowser(); // run on load;

/**
* Runs when you submit the Where To Buy form on the 2008 product pages.
*/
function fnSubmitWhereToBuyForm() {
	var sURL = document.whereToBuyForm.selectCountry.value;

	if (sURL.length > 0) {
		if (document.getElementById("businessUse").checked) {
			sURL += document.getElementById("businessUse").value;
		}
		else if (document.getElementById("personalUse").checked) {
			sURL += document.getElementById("personalUse").value;
		}
		else {
			// Don't redirect if usage not selected
			sURL = "";
		}
	}
	
	// Redirect if both country and usage are selected.
	if (sURL.length > 0) {
		document.location = sURL;
		//alert(sURL);
	}
}
    
// run jquery in no conflict mode

var $j = jQuery.noConflict();


// Filter elements by keywords contained in a div using a dropdown with coresponding values.

function e3FilterArea(formId, divs){
	formId.find('input[type="submit"]').click(
		function(){
			var filter = $j("select#sortBy").val();
			e3Filter(filter, divs);
			return false;
		});
}

function e3Filter(filter, divs){
	
	filtered = $j(divs).find('.keywords:contains('+ filter+ ')');

	ds = $j(divs);
	
	// get the number of filtered divs
	count = filtered.length;
	
	// the id of the number span to change
	fc = $j('#filterCount');
	
	if(count>0){
		fc.html(count);
		ds.hide();
		filtered.parents(divs).show();
	}	
	else{
		fc.html(ds.length);
		ds.show();
	}
}

$j(document).ready(function() {

		e3FilterArea($j('#rangeFilter'), '.range3ColFb .col');
		e3FilterArea($j('#galleryFilter'), '.galleryWrap');
		
		
	// hide application hidden area
	$j("#applicationsHide").hide();
	
	fnAssignPopups();
	
	if($j('#home').length>0){
		setInterval("fnLatestNews()", 5000);
	}
	
	
	
	// Disabled because hard coded feed goes to UK, this is moved to Latest News module.
	//fnNewsTicker();	
	
	fnsoftwareUpdateTG01();
	fnWtbForm();
	fnEditMode();
});

// show or hide application hidden area
function fnToggleApplications() {
	$j("#applicationsHide").toggle();
	return false;
}


/* Popups */
function fnPopup(sUrl, piWidth, piHeight,scrollbars,attributes) {	
	if (!scrollbars) {
		scrollbars = "no";
	}
	if (!attributes) {
		attributes = "";
	}
	var iWidth = piWidth;
	var iHeight = piHeight;
	var sScreenX = screen.width;
	var sScreenY = screen.height;
	var x = sScreenX - iWidth;
	var y = sScreenY - iHeight;
	var winLeft = x/2;
	var winTop =  y/2;	
	window.open(sUrl,"","width=" + iWidth + ",height="+ iHeight + "," + attributes + ",left=" + winLeft + ",top=" + winTop + ",scrollbars=" + scrollbars + ",resizable=" + scrollbars);	
}

function fnAssignPopups(){
	$j('#footer a.pop').click(function(){
		fnPopup($j(this).attr('href'), 500, 500, 'yes');
		return false;
	});
}

function fnSoftwareUpdatesForm(){
	//alert($j("form .softwareUpdates"))
	
	if($j("form .softwareUpdates")) {
		$j("form .softwareUpdates .row#imei #imeiNote").hide();
		$j("form .softwareUpdates .row#version #versionNote").hide();
	
		$j("#imei a#imeiQuest").tooltip({
		bodyHandler: function() {
			return $j($j(this).attr("href")).html();
		},
		showURL: false
		});

		$j("#version a#versionQuest").tooltip({
			bodyHandler: function() {
				return $j($j(this).attr("href")).html();
			},
			showURL: false
			});
	
	  $j('#txtEmail').alphanumeric({allow:".-_@'"});
	  $j('#txtFirstName').alpha({allow:".-_# "});
	  $j('#txtSurname').alpha({allow:".-_# "});
	  $j('#txtIMEINumber').numeric({allow:"+."});
	  
		$j('#selectCountry').change(function(){
			  $j('#frmPG08SoftwareUpdate').submit(); 
		});
	
		$j('#selectVersion').change(function(){
			  $j('#frmPG08SoftwareUpdate').submit(); 
		});
	
		$j('a#imeiCheckBtn').click(function(){
		  	$j('#frmPG08SoftwareUpdate').submit(); 
				return false;
		});
	
		$j	('.softwareUpdates .formSect1 .frmSoftwareUpdateBtn').hide();
		//$('a#downloadBtn').click(function(){
		//  	$('#frmPG08SoftwareUpdate').submit(); 
		//		return false;
		//})
		//.attr({ target: "_self" });
  	
	}	
}

function fnNewsTicker(){
	/* Moved into Latest News module ?
	if ($j('#home #home3ColFb #newsColInner').length > 0 ) {
		//alert('home exists');
		sendTimedRequest('/DesktopModules/LatestNews/NewsFeed.aspx','mLinkTxt='+encodeURIComponent('View all our press releases')+'&h3Txt='+encodeURIComponent('nas'), '', 'col3', 5000);
	}
	*/
}

function fnSupportForm(){
	//alert($(".softwareUpdates form"))
	
	
	if($j("#supportForm")) {

		var txtName = $get("<%= txtName.ClientID %>");
		var txtTelephone = $get("<%= txtTelephone.ClientID %>");
		var txtEmail = $get("<%= txtEmail.ClientID %>");
		var txtInqType = $get("<%= txtInqType.ClientID %>");
		var taDesc = $get("<%= taDesc.ClientID %>");
		var txtSerial = $get("<%= txtSerial.ClientID %>");

		$j("input[id$=txtName]").alphanumeric({allow:".-_@' "});
	  $j("input[id$=txtTelephone]").numeric({allow:".-() "});
	  $j("input[id$=txtEmail]").alphanumeric({allow:".-_@'"});
	  $j("input[id$=txtInqType]").alphanumeric({allow:"+.-@_() "});
	  $j("input[id$=taDesc]").alphanumeric({allow:"+.-@_() "});
	  $j("input[id$=txtSerial]").numeric({allow:".-() "});
		
	}
}

function fnLatestNews(){
	$j("#col3").load(window.location + " #col3");
}

function fnsoftwareUpdateTG01() {
	// Software Update
	$j("#softwareUpdateColumn2 #step2").addClass("collapse");
	$j("#softwareUpdateColumn2 select.language").change(function(){
		if($j(this).val() !="" && $j(this).val() !="0") {
			showStep2();
		} else {
			showStep1();
		}
	})	
	
	function showStep1(){
		$j("#softwareUpdateColumn2 #step1").removeClass("collapse").unbind("click");
		$j("#softwareUpdateColumn2 #step2").addClass("collapse");
		$j("#back").remove();
	}
	function showStep2() {
		$j("#softwareUpdateColumn2 #step1").addClass("collapse").append('<span id="back"></span>')
		$j("#back").click(function(){
			showStep1();
		});
		$j("#softwareUpdateColumn2 #step2").removeClass("collapse");
	}
	

	
	$j(".reveal").each(function(i){
		$j(this).before('<span class="revealArrow" onclick="reveal('+i+')">... <img src="/toshibaMobileAssets/images/arrowGrey.gif" alt="" />Reveal</span>');
		$j(this).hide();
	});
	
};


function reveal(index){
	$j(".revealArrow:eq("+index+")").hide()
	$j(".reveal:eq("+index+")").show()
}

function fnWtbForm(){
	if($j('#dnn_WhereToBuy').length>0){
		var btn = $j('#dnn_WhereToBuy input:submit');
		var txt = btn.attr('value');
		var str ='<a href="#" class="arrowSmall" id="wtbSubmit">'+txt+'</a>';
		
		btn.hide().after(str);
		
		$j('#dnn_WhereToBuy #wtbSubmit').click(function(){
			btn.click();
			return false;
		});
		
	}
}

function fnEditMode(){
	
	if($j('#dnn_IconBar\\.ascx_optMode_1').attr('checked')){
		$j('body').addClass('editMode');
	}
}