// =================================================================
// Copyright Sony CoCE-VL Europe
// This collection of functions is shared between various pages
// =================================================================

// Set focus on a predefined field, gives visitors an better impression
function SetFocusOnMe(me){
	me.focus()
}

function StatusMsg(msgStr) {
  status=msgStr;
}

// Swap one class with another, used for forms to emulate buttons
function SwapClass(obj, new_style) {
    obj.className = new_style;
}

// used for tutorials, to show viewlets in full screen, might need some improvement but ok for now.
function ResizeWindow() {
	top.window.moveTo(0,0);
	if (document.all) {
		top.window.resizeTo(screen.availWidth,screen.availHeight);
	}
	else if (document.layers||document.getElementById) {
		if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){
			top.window.outerHeight = screen.availHeight;
			top.window.outerWidth = screen.availWidth;
		}
	}
}

function openViewlet(htmlFile,htmlWidth,htmlHeight){
	window.open(htmlFile,'Tutorials','width='+htmlWidth+',height='+htmlHeight+',top=10,left=20,resizable=1');
}

function openMe(newin) {
	    flyout=window.open(newin,"flyout","resizable=no,scrollbars=no,width=1014,height=700,top=0,left=0")
	}
	
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}

function getmodel( oSel, url){
	with ( oSel.options[ oSel.selectedIndex ] ) {
		document.location = url +  "&m=" + text;
		}	
} 
			
function GetModel( oObj, prdCat, site ){
				var optionValue = document.models.model.options[ document.models.model.selectedIndex ].value;
				location.href='?site='+site+'&sc=' + prdCat + '&m=' + optionValue;
			}

			
/* Functions used in DIME / compatibilty DSR techinfo*/
function changeModel( site, model, linkP ) {
				window.location = linkP+'.aspx?site=' + site + '&m=' + model;
			}

function go() { 
	window.location=document.getElementById("menu").value; }
	
/*Function used to add onload event to a page*/			
function addOnloadEvent(fnc){
  if ( typeof window.addEventListener != "undefined" )
    window.addEventListener( "load", fnc, false );
  else if ( typeof window.attachEvent != "undefined" ) {
    window.attachEvent( "onload", fnc );
  }
  else {
    if ( window.onload != null ) {
      var oldOnload = window.onload;
      window.onload = function ( e ) {
        oldOnload( e );
        window[fnc]();
      };
    }
    else
      window.onload = fnc;
  }
}	


function model_unique(){
	if(document.models){
		if(window.location.href.indexOf("&m=") == -1){
		var optionNr = document.models.model.options.length;
		if (optionNr <3){
			var changeFnc=document.models.model.attributes.onchange.value;
			var datas = changeFnc.split(',');
			var site = datas[2].substring(datas[2].indexOf("'")+1,datas[2].lastIndexOf("'"));
			var prdCat = datas[1].substring(datas[1].indexOf("'")+1,datas[1].lastIndexOf("'")); 
			var modVal=document.models.model.options[1].value;
			location.href='?site='+site+'&sc=' + prdCat + '&m=' + modVal;
			}; 
		}
	}
}


addOnloadEvent(function(){ model_unique(); if(document.URL.indexOf('/main/main.aspx')!=-1){runSlideShow()}; });	
	
function check_wm_serial(model, serial)
{
	var affected = "Please contact our Customer Information Center, when the headphones supplied with WALKMAN have these symptoms. Sony will replace the damaged headphones with new ones without charge.";
	var not_affected = "Your WALKMAN is not affected by this issue. You can continue enjoying your WALKMAN.";
	var wm_message = document.getElementById("wm_message");
	
	if (serial.length < 7) wm_message.value = "The serial number must contain 7 digits.";
	else if (model == "NWZ-S738F" && serial >= "5000001" && serial <= "5031355") wm_message.value = affected;
	else if (model == "NWZ-S739F" && serial >= "5000001" && serial <= "5014255") wm_message.value = affected;
	else wm_message.value = not_affected;
}
