/**
 * 
 * @param {Object} str_0
 * @param {Object} str_1
 * @param {Object} str_2
 * @param {Object} str_3
 */
function rnd_str(str_0,str_1,str_2,str_3) { 
	var Seed_array = new Array();
	var seedary; 
	var i; 
	
	Seed_array[0]="" 
	Seed_array[1]= "a b c d e f g h i j k l m n o p q r s t u v w x y z";  
	Seed_array[2]= "a b c d e f g h i j k l m n o p q r s t u v w x y z"; 
	Seed_array[3]= "0 1 2 3 4 5 6 7 8 9"; 
	
	if (!str_1&&!str_2&&!str_3){str_1=true;str_2=true;str_3=true;} 
	if (str_1){Seed_array[0]+=Seed_array[1];} 
	if (str_2){Seed_array[0]+=" "+Seed_array[2];} 
	if (str_3){Seed_array[0]+=" "+Seed_array[3];} 
	
	Seed_array[0]= Seed_array[0].split(" "); 
	seedary="" 
	for (i=0;i<str_0;i++) { 
		seedary+=Seed_array[0][Math.round(Math.random( )*(Seed_array[0].length-1))] 
	} 
	return(seedary); 
}

function checkMobile(obj){
		var mobile=obj.value;
		var reg0=/^1\d{10}$/;   //130--139?????????7???
		//var reg1=/^153\d{4,8}$/;  //??????153?????????7???
		//var reg2=/^159\d{4,8}$/;  //??????159?????????7???
		//var reg3=/^150\d{4,8}$/;  //??????159?????????7???
		var my=false;
		if (reg0.test(mobile))my=true;
		//if (reg1.test(mobile))my=true;
		//if (reg2.test(mobile))my=true;
		//if (reg3.test(mobile))my=true;
		return my;
}
function parseDate_spliter(stringDate) {
	var dateEle = stringDate.split("-");
	return parseInt(dateEle[1],10)* 30 +  parseInt(dateEle[2],10) + parseInt(dateEle[0],10) * 365;
}
/**
 * 
 * @param {Object} dateValueFromController
 */
function checkDateValid(dateValueFromController)
	{
	var strDateValue = new String(dateValueFromController.value);
	var lens      = strDateValue.length;
	var dashIndex = strDateValue.lastIndexOf("-");
	var year  = strDateValue.substring(0,4);
	var month = strDateValue.substring(5,dashIndex);
	month = month * 1;
	var day   = strDateValue.substring(dashIndex+1,lens);
	if(year>9999 || year <1000)
	{
		dateValueFromController.focus();
		return false;
	}
	else
	{
		switch(month)
		{
			case 1:case 3:case 5:case 7:case 8:case 10:	case 12:
				 if(day<1 || day>31)
				 {
					dateValueFromController.focus();
					return false;
 				 }
				 break;
				
			case 4:case	6:case 9:case 11:
			     if(day<1 || day>30)
			     {
					dateValueFromController.focus();
					return false;
				 }
				 break;
		        case 2:
				 if((year%4)==0 && (year%100)!=0 || (year%400)==0 )
				 {
					 if(day<1 || day>29)
					 {
						dateValueFromController.focus();
						return false;
						}
											
				 }
				 else
				 {
				 	 if(day<1 || day>28)
				 	 {
						dateValueFromController.focus();
						return false;
						}
											
				 }
				 break;
				 
			default: 
					 dateValueFromController.focus();
					 return false;
					 break;
		}
	}
	return true;
}

function getObj(obj){
	return document.getElementById(obj)
}

/**
 * 
 * @param {Object} objEmails
 */
function checkEmailOld(objEmails)
{
	strEmails = objEmails.value;
	// Cut the special chars
	pattern = new RegExp("\\s","g");
	strEmails = strEmails.replace(pattern,"");
	pattern = new RegExp("^;");
	if (pattern.test(strEmails))
	{
		strEmails = strEmails.substring(1);
	}
	pattern = new RegExp(";$");
	if (pattern.test(strEmails))
	{
		strEmails = strEmails.substring(0,(strEmails.length - 1));
	}
	pattern = new RegExp("; ","g");
	strEmails = strEmails.replace(pattern,";");
	objEmails.value = strEmails;
	// Check mail address
	pattern = new RegExp("^[a-zA-Z][0-9a-zA-Z_\\.\\-]+@([0-9a-zA-Z][0-9a-zA-Z\\-]*[\\.])+[a-zA-Z]+$");
	arrEmails = new Array();
	if (strEmails != "")
	{
		arrEmails = strEmails.split(";");
	}
	bCanSubmit = true;
	nEmailsIndex = -1;
	while (++nEmailsIndex < arrEmails.length)
	{
		if (!pattern.test(arrEmails[nEmailsIndex]))
		{
			bCanSubmit = false;
			//alert("Invalid mail address \""+arrEmails[nEmailsIndex]+"\" !");
			break;
		}
	}
	return bCanSubmit;
}
function checkEmail(objEmails) {
	emailStr = objEmails.value;
	if (emailStr.length == 0) {
		return false;
	}	
	var rx = /^(([^\(\)\.\,\;\:\s\@\"\\]+(\.[^\(\)\.\,\;\:\s\@\"\\]+)*)|(\".+\"))@(([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})|([a-zA-Z0-9][a-zA-Z0-9\-]*(\.[a-zA-Z0-9\_\-]+)*\.(([a-zA-Z]{2,})|([a-zA-Z\>\]]{3,}))))$/;
	if(!rx.test(emailStr)) {
		return false;
	} else {
		var emailPat=/^(.+)@(.+)$/;
		var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
		var matchArray=emailStr.match(emailPat);
		var user=matchArray[1];
		var domain=matchArray[2];
		var IPArray = domain.match(ipDomainPat);
		if (IPArray != null) {
			for (var i = 1; i <= 4; i++) {
			  	if (IPArray[i] > 255) {
			     	return false;
			  	}
			}
		}
		return true;
	}
}

/**
 *
 * @param {Object} String
 */
function checknumber(String) 
{ 
	var Letters = "1234567890"; 
	var i; 
	var c; 
	if(String.charAt(0) == '0')
		return     true;
	for( i = 0; i < String.length; i ++ ) 
	{ 
		c = String.charAt( i ); 
		if (Letters.indexOf( c ) ==-1) 
		{ 
			return true; 
		} 
	}
	return false; 
}
function containsNumber(String){
	var Letters = "1234567890"; 
	var i; 
	var c; 
	for( i = 0; i < String.length; i ++ ) { 
		c = String.charAt( i ); 
		if (Letters.indexOf( c ) !=-1) 
		{ 
			return true; 
		} 
	}
	return false; 
}
function containsSpecialChars(String){
	var Letters = "'#@\\/\""; 
	var i; 
	var c; 
	for( i = 0; i < String.length; i ++ ) 
	{ 
		c = String.charAt( i ); 
		if (Letters.indexOf( c ) !=-1) 
		{ 
			return true; 
		} 
	}
	return false; 
}

function checkmoney(String) 
{
	var Letters = "1234567890.";
	var c;
	if(String.charAt(0) == '.')
		return     false;

	if(String.charAt(String.length-1) == '.')
		return     false;
		
	var nCount = 0;
	
	for( var i = 0; i < String.length; i++){  
		c = String.charAt(i);
		if(c == ".")
			nCount ++;
		if(Letters.indexOf(c)<0)
			return     false;
	}
	if (nCount > 1)
		return     false;
	return     true;
}
/**
 *
 * @param {Object} strPhoneNumber
 */
function changeDateToChinese(strPhoneNumber){
	var arrPhoneNumber = strPhoneNumber.split("-");
	var nYear = arrPhoneNumber[0];
	var nMonth = arrPhoneNumber[1];
	if(nMonth.substring(0,1) == 0)
		nMonth = nMonth.substring(1)
	var nDay = arrPhoneNumber[2];
	if(nDay.substring(0,1) == 0)
		nDay = nDay.substring(1)
	return (nYear + "???" + nMonth+ "???" + nDay+"???")
}

function allGBK(str) 
{
   for (i = 0; i < str.length; i++) 
   {
      if (!(((str.charCodeAt(i) >= 0x3400) && (str.charCodeAt(i) < 0x9FFF)) || (str.charCodeAt(i) >= 0xF900)))
      {
         return false;
      }
   }
   return true;
}
function checkName(str)
{
    if(!allGBK(str)){
      return false;
    }
    return true;
}

function AtTrim(s)
{
	var r1, r2, s1, s2, s3;

    r1 = new RegExp("^ *");
    r2 = new RegExp(" *$");

    s1 = ""+s+"";
    s2 = s1.replace(r1, "");
    s3 = s2.replace(r2, "");

    r1 = null;
    r2 = null;

    return(s3);
}

String.prototype.trim  =  function()  
{  
return  this.replace(/(^\s*)|(\s*$)/g,  "");  
}  

function strlen(str) { 
  var len;
  var i;
  len = 0;
  for (i=0;i<str.length;i++) {
    if (str.charCodeAt(i)>255) len+=2; else len++;
  }
  return len;
}

function limitTextEnter(textbox)
{
	//???IE6 ???firefox 2.0??????????????? ????????????????????????????????????text???textarea????????????
	/**
	 * ???????????????
	 * <textarea  maxlength="6" onkeyup="limitTextEnter(this)">
	 */
	var nMaxLen=textbox.getAttribute? parseInt(textbox.getAttribute("maxlength")):"";
	if(textbox.getAttribute && strlen(textbox.value)>nMaxLen){
		textbox.value=cutStrByLen(textbox.value,nMaxLen);
	  }
}

function cutStrByLen(str,len)
{
	//???IE6 ???firefox 2.0??????????????? ?????????????????????2?????????????????????substring()??????
	var templen=0;
	for (var i=0;i<str.length;i++) {
		if (str.charCodeAt(i)>255) templen+=2; else templen++;
		if(templen > len) return (i > 0)?str.substring(0,i):"";
	}
	return str;
}
function getMailList(mails) {
    var attendeeList = AtTrim(mails);
    var mailList = new Array();
    if (!(attendeeList=="")) {
        attendeeList = EmailListSpecialCharReplace(attendeeList);
        if (attendeeList.indexOf(',') == -1) {
            mailList[0] = attendeeList;
        }
        mailList = attendeeList.split(',');
    }
    var returnEmails = new Array();
    var j = 0;
    for(i = 0; i <mailList.length; i++) {
        if (AtTrim(mailList[i]) == "") {
            continue;
        } else {
            returnEmails[j++] = AtTrim(mailList[i]);
        }
    }
    return returnEmails;
}
function isValidEmail(emailStr) {
	if (emailStr.length == 0) {
		return false;
	}	
	var rx = /^(([^\(\)\.\,\;\:\s\@\"\\]+(\.[^\(\)\.\,\;\:\s\@\"\\]+)*)|(\".+\"))@(([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})|([a-zA-Z0-9][a-zA-Z0-9\-]*(\.[a-zA-Z0-9\_\-]+)*\.(([a-zA-Z]{2,})|([a-zA-Z\>\]]{3,}))))$/;
	if(!rx.test(emailStr)) {
		return false;
	} else {
		var emailPat=/^(.+)@(.+)$/;
		var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
		var matchArray=emailStr.match(emailPat);
		var user=matchArray[1];
		var domain=matchArray[2];
		var IPArray = domain.match(ipDomainPat);
		if (IPArray != null) {
			for (var i = 1; i <= 4; i++) {
			  	if (IPArray[i] > 255) {
			     	return false;
			  	}
			}
		}
		return true;
	}
}
function DrawImageWithParam(iwidth,iheight,ImgD) {
            var image = new Image();
            //var iwidth = 73; //定义允许图片宽度
            //var iheight = 98; //定义允许图片高度
            if (ImgD == null || ImgD == undefined) {
                return false;
            }
            image.src = ImgD.src;
            if (image.width > 0 && image.height > 0) {
                flag = true;
                if (image.width / image.height >= iwidth / iheight) {
                    if (image.width > iwidth) {
                        ImgD.width = iwidth;
                        ImgD.height = (image.height * iwidth) / image.width;
                    } else {
                        ImgD.width = image.width;
                        ImgD.height = image.height;
                    }
                } else {
                    if (image.height > iheight) {
                        ImgD.height = iheight;
                        ImgD.width = (image.width * iheight) / image.height;
                    } else {
                        ImgD.width = image.width;
                        ImgD.height = image.height;
                    }
                }
            } else {
                return false;
            }
        }
function getElementLeft(Elem) {
		var elem;
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		xPos = elem.offsetLeft;
		tempEl = elem.offsetParent;
  		while (tempEl != null) {
  			xPos += tempEl.offsetLeft;
	  		tempEl = tempEl.offsetParent;
  		}
		return xPos;
}


function getElementTop(Elem) {
		if(document.getElementById) {	
			var elem = document.getElementById(Elem);
		} else if (document.all) {
			var elem = document.all[Elem];
		}
		yPos = elem.offsetTop;
		tempEl = elem.offsetParent;
		while (tempEl != null) {
  			yPos += tempEl.offsetTop;
	  		tempEl = tempEl.offsetParent;
  		}
		return yPos;
}