

//窗口弹出函数
function popup(winUrl,winName,strResize,winW,winH,winL,winT)
{
  var thisPopupWin;
  var iLeft,iTop;
  if(winL==null){
    iLeft=(window.screen.width-winW)/2;}
  else{
    iLeft=winL;}
  if(winT==null){
    iTop=(window.screen.height-winH)/2;}
  else{
    iTop=winT;}
      
  thisPopupWin=window.open(winUrl,winName,"width="+winW+",height="+winH+",top="+parseInt(iTop) +",left="+parseInt(iLeft)+",toolbar=no,menubar=no,scrollbars=yes,resizable="+strResize+",location=no,status=no");
  thisPopupWin.focus();
}

//窗口弹出函数
function popupnew(winUrl,winName,strResize,strscrollbars,winW,winH,winL,winT)
{
  var thisPopupWin;
  var iLeft,iTop;
  if(winL==null){
    iLeft=(window.screen.width-winW)/2;}
  else{
    iLeft=winL;}
  if(winT==null){
    iTop=(window.screen.height-winH)/2;}
  else{
    iTop=winT;}
      
  thisPopupWin=window.open(winUrl,winName,"width="+winW+",height="+winH+",top="+parseInt(iTop) +",left="+parseInt(iLeft)+",toolbar=no,menubar=no,scrollbars="+strscrollbars+",resizable="+strResize+",location=no,status=no");
  thisPopupWin.focus();
}


//窗口弹出函数
function showwin(winUrl,winName,strResize,strscrollbars,winW,winH,winL,winT)
{
  var thisWin;
  var iLeft,iTop;
  if(winL==null){
    iLeft=(window.screen.width-winW)/2;}
  else{
    iLeft=winL;}
  if(winT==null){
    iTop=(window.screen.height-winH)/2;}
  else{
    iTop=winT;}
      
  thisWin=window.open(winUrl,winName,"width="+winW+",height="+winH+",top="+parseInt(iTop) +",left="+parseInt(iLeft)+",toolbar=no,menubar=no,scrollbars="+strscrollbars+",resizable="+strResize+",location=no,status=no");
  thisWin.focus();
}

function newcart(_url){
  showwin(_url,'','yes','yes',710,450);
}

//删除确认函数
function delconfirm(strTemp)
{
	if(strTemp==null) strTemp="are you sure delete?";
	if(confirm(strTemp))return true;
	return false;
}

//打印函数
function doprint()
{
  this.focus();
	window.print();
}

//去除左右空格
function str_trim(sStr) {
    charCode = new Array();
    //alert(sStr.length);
    for (i=0; i < sStr.length; i++) {
      charCode[i] = sStr.charCodeAt(i);
    }
    for (k=sStr.length-1; k >= 0; k--) {
      if (charCode[k] != 32) break;
    }
    sRightStr = sStr.substring(0,k+1);
    for (j=0; j < sRightStr.length; j++) {
      if (charCode[j] != 32) break;
    }
    sLeftStr = sRightStr.substring(j);
    //alert(sLeftStr.length);
    return sLeftStr;
}


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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  var firstobj;
  for (i=0; i<(args.length-2); i+=3) {
    var errorspre=errors;
    test=args[i+2]; 
    val=MM_findObj(args[i]);
    if (val) {
      nm=val.title;
      if ((val=str_trim(val.value))!="") {
        if (test.indexOf('isEmail')!=-1) { 
          p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must be a email address.\n';
        } 
        else if (test!='R') {
          num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must be a number.\n';
          if (test.indexOf('inRange') != -1) { 
            p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must between '+min+'and '+max+'.\n';
          }
        }
      } 
      else if (test.charAt(0) == 'R') errors += '- '+nm+' must not null.\n'; 
    }
    if(errorspre!=errors && firstobj==null) firstobj=MM_findObj(args[i]);
  } 
  if (errors){
   alert('you got errors:\n'+errors);
   if(firstobj!=null){if(!firstobj.disabled&&!firstobj.readonly)firstobj.focus();}
  }
  document.MM_returnValue = (errors == '');
}

function isAllowedPicFile(filename, allowedExt) {
    if(filename == '') return false;
    var arrAllowedExt = new Array();
    var fileext = filename.substring(filename.lastIndexOf(".") + 1, filename.length);
    fileext = fileext.toLowerCase();
    if(allowedExt != "") {
        arrAllowedExt = allowedExt.split(",");
        for(i = 0; i < arrAllowedExt.length; i++) {
            if(fileext == arrAllowedExt[i].toLowerCase()) {
                return true;
            }
        }
        return false;
    }
    return true;
}
