// JavaScript Document
///\brief Functions launched when DOM is ready

$(function() {
		//when language is not detected by any way sent to hub page instead of english.
		if(wep.locale=='os_OS'){$(location).attr('href',"/hub/hub.html");}
		//$('a[href$="http://support.sony-europe.com/hub/hub.html"]').attr("href","http://support.sony-europe.com/index.aspx?site=odw_"+wep.locale);
		if($('#section_1').length!='0' && $('#forums_link_sn').length!='0'){
			forum_url="<div class=\"content-item\"><ul><li id=\"forum_url\">"+$('#forums_link_sn').html()+"</li></ul></div>";
		
			$('#section_1 .tab-box-content-inner').prepend(forum_url);
			}
		if($('#frm-search').length!='0'){$('#frm-search').show();}
		if($('#feedbackBox').length!='0'){$('#feedbackBox').show();}
		if($('#contact_div').length!='0'){$('#contact_div').removeClass('hidden');}
		if($('#contact_div').length!='0' && wep.locale=='pl_PL'){showContactDetails();}
		$('select').each(function(index) {
    		var options_ = $(this).children();
			if(options_.size()=='2' && options_.eq(0).val()=='0' && $(this).val()!= options_.eq(1).val()) {$(this).val(options_.eq(1).val()); var myfrm = $(this).parent(); myfrm.submit()};
  		});

		
		//We show extra tabs for user with javascript.
		if($('.tab-box-content')){
			//view all tabs
			$('.tab-nav-item').removeClass('hidden');}
			$('table.compatibility tbody tr:even').addClass('even');	

	//	new Tips($$('.tip'));
		if($('.faq').length!='0'){faqlaunch(".faq h4",".faq .response");}
/*Used in the download pages to hide only if there is javascript // desactivated - request from Japan*/
		if($('.dl_sections').length!='0'){$('.dl_sections').show();}			
		if($('.tab-nav-item').length!='0'){InitTabNav()};
		if($('#hotnews_all').length!='0'){faqlaunch("#hotnews_all h2","#hotnews_all .block-indent"); $('#hotnews_all .general .block-indent').show(600);}
	
///\brief Initiate the omniture tags
		var locale = wep.locale;
		if(model_used){var modelname=model_used};
		
///\brief if belgium, offer the alternat language
		if($('#lg_change')){
			$('#lg_change').bind('click', function(e){
				changeLANG();	
				return false;
				});
		}

		
///\brief  Initialize the function allowing to show the manuals if the user click on the GO button*/
if($('#globalModelSearch')){
		$('#globalModelSearch').bind('focus', function(e){search_model('globalModelSearch');}).attr("autocomplete","off");
		$('#frm-search').bind('submit', function(e){if($('#globalModelSearch').val()!=''){showModelPage("globalModelSearch" )}else{
										var newAlert = $('<div class="alert-content" title="Warning"> '+selectmsg +'<br/> ex : SLT-A55 </div>');
											$( '#globalModelSearch' ).after(newAlert);	
											$(newAlert).MsgAlert({autoClose: true, wait: false, className: 'conditions_warning'});
										
										};return false;});
		
}
	
	if($('#model_crumb')){$('#model_crumb').bind('click', function(e){showModelPage('mod_crumb_value');return false;});}	
	if($('#kasaform')){$('#model').bind('focus', function(e){search_model('model');}).attr("autocomplete","off");}
		
///\brief  Initialize the function allowing to show the manuals when clicking the recently viewed*/
		if($('#RV1')){$('#RV1').bind('click', function(e){showModelPage('RV1id');return false;});}	
			
	
///\brief Initialize the function allowing to show the repair tab when we enter a model name in the repair searchox (for the moment it is the same as for the model name*/
		if($('#globalRepairSearch')){
			//search_model('globalRepairSearch');
		}


		///\brief allow to retrieve the manuals when the manuals tab is clicked */
		if($('#selMainCat')){
		//	search_model('selMainCat');
		}

///\brief If there is .settingmenuhover class launch the scripts that hide the information and add the click / show / hide of sections*/
		if($('#troubleshoot')){hideAndToggle();}
		
///\brief Specific for videotransfet tutorial (DIME/Tutorials*/	
		if($('#videotrans')){ 
			hideAndToggle(); 
			hideVideos();
			};
		
		if($('#BDP_out')){hideVideos();};		


		if($('#pc').length!='0'){
			$('#pc').bind("keyup",function(e){ 
				if($('#pc').val().length==8) {
						$('#pc').css('background-color', '#ffffff');
						$('#pc').css('color','#124c16');
						pcLookUp();
				}
			});
		//$('#sn').bind("keyup",function(e){ snCheck(); });
	 	}


/* End of onload scripts*/		
});		

/* Call webservice to check if the product code is valid */

function pcLookUp() {
    var pc = $('#pc').val();
	var modelname;
	//$('#sn').val('');
    if (pc.length==8){
		$.ajax({
			type: "GET",url: "/shared/code/supportwebservs.asmx/getModelName?theProductCode=" + pc,dataType: "xml",
			success: function(data) {
				modelname = $(data).find('string').text();
				if (modelname !== "0"){ 
					modelname=modelname.replace('/', '_');
					//$.cookie('modelId',modelname, { duration: 365, path: "/" });
            		//$.cookie('productCode', pc, { duration: 365, path: "/" });
            		//writeSessionVariable('productCode', pc);
					//writeSessionVariable('modelId', modelname);
					$('#m').val(modelname);
					//$('#mn').val(modelname);
					//$('#loading_icon').hide();
					$('#pc').css('background-color','#69da66'); $('#pc').css('color','#124c16');
					//$('#sn').removeAttr('readonly').css('background','#fff');
				}else { 
				//$('#loading_icon').hide(); 
				$('#pc').css('background-color', '#bb362d'); $('#pc').css('color', '#fff');$('#sn').val();
				//$('#sn').attr('readonly','readonly');
				}
			},

			error: function(XMLHttpRequest, textStatus, errorThrown) {
				//alert(errorThrown);
			}
		});
    }

}


/*
function snCheck() {

    if ($('#sn').val().length == 7) {

            //$.cookie('serialNumber', $('#sn').val(), { expires: 365, path: "/" });

           // writeSessionVariable('serialNumber', $('#sn').val());

	}

}
*/


