
var winWidth = 0, winHeight = 0;

function getWindowSize() {
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    winWidth = window.innerWidth;
    winHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    winWidth = document.documentElement.clientWidth;
    winHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    winWidth = document.body.clientWidth;
    winHeight = document.body.clientHeight;
  }
}


function newSize2(w, h, s) {
	var flash = null;
	if(document.all && !document.getElementById) {
		flash = document.all['flashContent'];
	}else{
		flash = document.getElementById('flashContent');
	}
	
	if (flash != null) {
		flash.style.width = w;
		flash.style.height = h;
	}
	a = document.getElementById("leftLane");
	b = document.getElementById("rightLane");
	c = document.getElementById("centerLane");
	maxHeight = 0;
	if (a != null) {
		maxHeight = a.offsetHeight;
		if (b != null) {
			maxHeight = Math.max(maxHeight, b.offsetHeight + s);
		}
		if (c != null) {
			maxHeight = Math.max(maxHeight, c.offsetHeight);
		}
	}
  if (b != null && maxHeight == 0) {
		maxHeight = b.offsetHeight;
	  if (c != null) {
			maxHeight = Math.max(maxHeight, c.offsetHeight);
		}
  }
  if (c != null && maxHeight == 0) {
  	maxHeight = c.offsetHeight;
  }
	getWindowSize();
	maxHeight = Math.max(maxHeight, winHeight - 270) +  15;
	if (a != null) {
		a.style.height = maxHeight;
	}
	if (b != null) {
		b.style.height = maxHeight;
	}
	if (c != null) {
		c.style.height = maxHeight;		
	}

}


function newSize(w, h) {
	return newSize2(w, h, 22);
}


//??String???prototype????String?????
String.prototype.rTrim=rTrim;
String.prototype.lTrim=lTrim;
String.prototype.trim=trim;
//?????????
function rTrim(){
    var orgStr= this.toString();
    var str=orgStr;
    while( str.length >0) {
        if (str.charAt(str.length-1) != ' '){
            break;
        }
        str=str.substring(0, str.length-1) ;
    }
    return str ;
 }
 //??
 function lTrim(){
     var orgStr= this.toString();
     var str=orgStr;
     while (str.length>0){
         if (str.charAt(0) != ' '){
             break;
         }
         str=str.substring(1, str.length) ;
     }
     return str;
 }
 //???????????
 function trim(){
     var orgStr= this.toString();
     var str=orgStr;
     return str=(str.lTrim()).rTrim();
 }


function alertCheckDate() {
  var columnName = arguments[0]
  var value = arguments[1].value;
  format = "yyyy/MM/dd";
  if (arguments.length > 2) {
    format = arguments[2];
  }
  if (isDate(value, format) == false) {
    alert(columnName + ": ??????, ???: " + format);
    return false;
  }
  return true;
}


/**
 *
 * ???????
 *
 */
function checkNumber() {
  var value = arguments[0];

  var s = new String(value);

  if( s.length != s.trim().length ){
      return false;
  }
  var maxHeight = arguments[1];
  var scale = arguments[2];
  if (scale > 0) {
	value = Math.pow(10, scale) * value;
  }
  if (isNaN(value) || value.length > maxHeight) {
    return false;
  }

  return true;
}

function alertCheckNumber() {
  var columnName = arguments[0];
  var maxHeight = arguments[2];
  var scale = arguments[3];
  var value = arguments[1].value;
  if (checkNumber(value, maxHeight, scale) == false) {
    alert(columnName + ": ??????");
  }
  return true;
}


/**
 *
 * ????????
 *
 */
function isBlank() {
  var value = arguments[0].trim();
  if (value.length == 0) {
    return true;
  }
  return false;
}


function IsNumeric(sText) {
	var ValidChars = "0123456789.";
	var IsNumber = true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++) {
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1) {
		IsNumber = false;
		}
	}
	return IsNumber;
}




function alertCheckBlank() {
  var columnName = arguments[0];
  var value = arguments[1];
  if (isBlank(value)) {
    alert(columnName + ": ?????");
    return false;
  }
  return true;
}

function checkString() {
  /*var value = arguments[0];
  var length = arguments[1];

  if (typeof value == "undefined" || value == null || value.length == 0) {
    return true;
  }
  var reallength = 0;
  var valuelen = value.length;
  for (i = 0; i < valuelen; i++) {
    c = value.charCodeAt(i);
    if (c <= 128) {
      reallength++;
    } else {
      reallength += 3;
    }
  }
  if (reallength > length) {
    return false;
  }
  */
  return true;
}


function alertCheckString() {
  var columnName = arguments[0];
  var value = arguments[1].value;
  var maxHeight = arguments[2];
  if (checkString(value, maxHeight) == false) {
    alert(columnName + ": ??????????" + maxHeight);
    return false;
  }
  return true;
}

function urlEncoder(str) {
  re = /%/gi;
  newstr = str.replace(re, "%25");
  return newstr;
}

function checkSelected(buttonGroup) {
  if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i< buttonGroup.length; i++) {
		if (buttonGroup[i].checked) {
		  return true;
		}
      }
   } else {
      if (buttonGroup.checked) { 
      	return true; 
      } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return false;

}

function showBannerUrl(isPopUp, UUID){		
	if ( isPopUp == 1 ){
		window.open("/is-bin/INTERSHOP.enfinity/WFS/Sony-SonyStyle-Site/zh_TW/-/TWD/Banner-Redirect?BannerUUID=" + UUID ,'redirectPage');
	}else{
		location.href='/is-bin/INTERSHOP.enfinity/WFS/Sony-SonyStyle-Site/zh_TW/-/TWD/Banner-Redirect?BannerUUID=' + UUID;
	}
}


function clickExpandListItem(o) {
  var a = document.getElementById("ExpandDescPageList");
  nodes = a.childNodes;
  for (i = 0; i < nodes.length; i++) {
  	if (nodes[i].tagName == 'A') {
	    nodes[i].className = "expandListItem";
	  }
  }
  
  o.className = "expandListItemClick";
}


function gotoAnchorName(n) {
	o = window.location;
  s = o.href.substring(0, o.href.length - o.hash.length) + '#' + n;
  window.location.href = s;
}


function changeImage(o, imgurl) {
	nodes = o.childNodes;
	for (i = 0; i < nodes.length; i++) {
  	if (nodes[i].tagName == 'IMG') {
	    nodes[i].src = imgurl;
	  }
  }
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function addWildCard() {
	t = SimSearch.WFSimpleSearch_NameOrID.value;
	if (isBlank(t) || t.length < 2) {
		alert("搜尋字串至少兩個字以上");
		return false;
	}
	SimSearch.WFSimpleSearch_NameOrID.value = t;
	return true;
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function isFilled(elm)	{
	if (isAllSpace(elm.value) || elm.value==null) 
		return false;
	else 
		return true;
}

function isEMail(elm) {
    i=elm.value.indexOf("@");
    j=elm.value.indexOf(".",i);
    k=elm.value.indexOf(",");
    kk=elm.value.indexOf(" ");
    jj=elm.value.lastIndexOf(".") + 1;
    len=elm.value.length;
    if (len==0 || (i <= 0) || (j <= (1+1)) || (k != -1) || (kk != -1) || (len-jj < 2) || (len-jj > 3)) 
		return false;
    else
		return true;
}

function isAllSpace(elm) {
	for (i = 0;  i < elm.length;  i++) {
		if (elm.charAt(i)!=" ")
			return false;
	}
	return true;
}

