﻿/*
==================================================================
//Desc:Extend function of JQuery
//Dependence:jquery lib
==================================================================
*/
jQuery.fn.extend({
    //accept int form 0 to 9
    onlyAcceptInt:function()
    {	
        if(jQuery(this) != 'undefine' && jQuery(this) !=null)
        {
            jQuery(this).keypress(function(e)
            {              
                if(jQuery.browser.msie)
                {
                    if ((window.event.keyCode<48 || window.event.keyCode>57||window.event.keyCode==13) && window.event.keyCode !=8) 
                    { 
                        return window.event.keyCode=0;
                    }
                }
                else
                {
                    if ((e.which<48 || e.which>57||e.which==13) && e.which !=8) 
                    { 
                        return e.which=0;
                    }
                }
            });
        }
    },
       //accept int form 0 to 9 and '-1'
    onlyAcceptAndNegative:function()
    {
        if(jQuery(this) != 'undefine' && jQuery(this) !=null)
        {
            jQuery(this).keypress(function(e)
            {
                if(jQuery.browser.msie)
                {
                    if(!(((window.event.keyCode>=48)&&(window.event.keyCode<=57))||(window.event.keyCode==13)||(window.event.keyCode==45)))//从 0~9 和'-1'号
                    {
                        return window.event.keyCode=0;
                    }
                }
                else
                {
                    if(!(((e.which>=48)&&(e.which<=57))||(e.which==13)||(e.which==45)))//从 0~9 和'.'号
                    {
                        return e.which=0;
                    }
                }
            });
        }
    },
    //accept int form 0 to 9 and '.'
    onlyAcceptNumeric:function()
    {
        if(jQuery(this) != 'undefine' && jQuery(this) !=null)
        {
            jQuery(this).keypress(function(e)
            {
                if(jQuery.browser.msie)
                {
                    if(!(((window.event.keyCode>=48)&&(window.event.keyCode<=57))||(window.event.keyCode==13)||(window.event.keyCode==46)))//从 0~9 和'.'号
                    {
                        return window.event.keyCode=0;
                    }
                }
                else
                {
                    if(!(((e.which>=48)&&(e.which<=57))||(e.which==13)||(e.which==46)))//从 0~9 和'.'号
                    {
                        return e.which=0;
                    }
                }
            });
        }
    },
    //when mouse over girdview rows    
    GridHorve:function(HoverCss)
    {  
        if(jQuery(this) != 'undefine' && jQuery(this) !=null)
        {
            
            jQuery(this).find("tr").hover(function(){            
                if(jQuery(this).find("th").length == 0)
                {
                   
                    jQuery(this).addClass(HoverCss);
                }
            },
            function(){
                jQuery(this).removeClass(HoverCss);
            });
        }
    }
});

/*
==================================================================
//Class:MsgTools
//Dependence:jquery lib
==================================================================
*/
var MsgTools =
{
    //desc:show message in specified div
    showMsgInDiv:function(divId,msgString)
    {
        var jQuerydivObj = jQuery("#"+divId);
        if(jQuerydivObj != "undefined")
        {
            if(msgString == null || msgString == "")
            {
                jQuerydivObj.hide().html();
            }
            else
            {
                var maxWidth = jQuerydivObj.parent().width()-30;//减去padding 和 border
                jQuerydivObj.css("width",maxWidth+"px");               
                jQuerydivObj.html(msgString).fadeIn();               
            }
        }       
    },
    
    showMsgBox:function(titleString,msgString)
    {
        return false;
    }
};


/*
==================================================================
//Class:StringTools
==================================================================
*/

var StringTools =
{
    //desc:trim left white space of specified text
    LTrim:function(strText)
    {
        var whitespace = new String(" \t\n\r");
        var s = new String(strText);
        if (whitespace.indexOf(s.charAt(0)) != -1)
        {
            var j=0, i = s.length;
            while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
            {
                j++;
            }
            s = s.substring(j, i);
        }
        return s;
    },
    
    //desc:trim right white space of specified text
    RTrim:function(strText)
    {
        var whitespace = new String(" \t\n\r");
        var s = new String(strText);
        if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
        {
            var i = s.length - 1;
            while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
            {
                i--;
            }
            s = s.substring(0, i+1);
        }
        return s;
    },
     //desc:trim both left&right white space of specified text
    Trim:function(strText)
    {
        return this.RTrim(this.LTrim(strText));
    },
    
    //desc:xmlencode of specified text
    XMLEncode:function(strText)
    {
       strText=this.Trim(strText);
       strText=strText.replace("&","&amp;");
       strText=strText.replace("<","&lt;");
       strText=strText.replace(">","&gt;");
       strText=strText.replace("'","&apos;");
       strText=strText.replace("\"","&quot;");
       return strText;
    },
    
    //check whether the text is email
    isEmail:function(strText)
    {
        var regString = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
		return regString.test(strText);
    },
    
     //check whether the text is empty
    isNullOrEmpty:function (strText)
    {    
        if(strText==null)
        {
            return true;
        }
        else if(this.Trim(strText)=="")
        {
            return true;
        }
        else
        {
            return false;
        }
     },
     
     //check whether the text is  digit 
    isDigit:function (strText)
    {
        return ((strText>="0")&&(strText<="9"));
    } ,
     //check whether the text is  int 
    isInt:function(strText)
    {
        var regString = /^\d+$/;
        return regString.test(strText);
    },
     //check whether the text is  nummric 
    isNumeric:function (strText)  
    { 
        var regString =/^(0|[1-9]\d*)(\.\d*[0-9])?$/;
        return regString.test(strText);
    },
      //check whether the text is  nummric 
    isNumeric1:function (strText)  
    { 
        return true;
    },
    //check whether the text is  nummric with sign 
    isNumericWithSign:function (strText)  
    { 
        var regString =/^(\+|-)?(0|[1-9]\d*)(\.\d*[0-9])?$/;
        return regString.test(strText);
    },
    //check whether the fInput is  in the range 
    isNumericInRange:function(fInput,fLower,fHigh)
    {
        if(!this.isNumeric(fInput))
        {
            return false;
        }
        else if(this.isNullOrEmpty(fLower))
        {       
            return (fInput<=fHigh);
        }
        else if (this.isNullOrEmpty(fHigh))
        {
            return (fInput>=fLower);
        }
        else
        {         
            return ((fInput>=fLower)&&(fInput<=fHigh));
        }
    }
};
 function Clear()
 {
        var obj_input = document.getElementsByTagName("input");
        for(var i=0;i<obj_input.length;i++)
        {
            if(obj_input[i].type =="text")
                obj_input[i].value = "";        
        }
        var obj_textarea=document.getElementsByTagName("textarea");
        for(var j=0;j<obj_textarea.length;j++)
        {
            obj_textarea[j].value="";
        }
        var obj_select=document.getElementsByTagName("select")
        for(var k=0;k<obj_select.length;k++)
        {
            if(obj_select[k].length>0)
            {
                obj_select[k][0].selected=true;
            }      
        }
        return false
   }

$(window).load(function(){
    // img start
   $("img.imgFrontCss,img.imgBackCss").each(function(){
     var standardWidth=92;
    var imgWidth=$(this).width();
    var imgHeight=$(this).height();
    
     if(imgWidth>=imgHeight)
     {
         $(this).width(standardWidth);
     }
    else
    {
       $(this).height(standardWidth);
    }
     $(this).css("display","inline")
  });
  
ChangeFontByMouse("ulProductList")
 
});

function ChangeFontByMouse(id)
{ 
   var ulElement=document.getElementById(id);
   if(ulElement!=null){
       var arrayli=ulElement.getElementsByTagName("li");
       var oldStyle; //保存原有样式
       for(var i=0;i<arrayli.length;i++)
       {
             arrayli[i].onmouseover = function() {
                    oldStyle = this.className;
                    this.className = "ChangeFont"
            } 
                arrayli[i].onmouseout = function() {
                    this.className = oldStyle;
           } 
       }
   }
}
  //img end
