function LTrim(l){
    for(var k=0;k<l.length&&l.charAt(k)<=" ";k++){
    
    }
    return l.substring(k,l.length);
}

function RTrim(m){
    for(var j=m.length-1;j>=0&&m.charAt(j)<=" ";j--){
    
    }
    return m.substring(0,j+1);
}

function Trim(n){
	return LTrim(RTrim(n));
}

function IsValidEmail(v){
	var tsEM=Trim(v);
	var iA=tsEM.indexOf("@");
	var aE=tsEM.split("@");
	if(iA==-1||tsEM.charAt(0)>"~"||tsEM.indexOf(".",iA)==-1||tsEM.indexOf(" ",0)!=-1||aE.length>2) 
		return false;
	else {
		if(aE[0].length>0&&aE[1].length>0)
			return true;
		else 
			return false;
	}
//if　(strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)　!=　-1)
//　　return true;
//else
//　　return false;
//}
}
function IsValid(sV,sR){
	var sTmp;
	if(sV.length == 0){ 
		return false;
	}
	for (var i=0; i < sV.length; i++){
		sTmp = sV.substring (i, i+1);
		if (sR.indexOf (sTmp, 0)==-1){
			return false;
		}
	}
	return true;
}
	

function SetDefCoverImage(e){
	//var img=event.srcElement;
	//alert(e.src);
	e.src = "/images/covers/no-image.gif";
}

function LoadUrl(id,url,params,callback){
	//alert(params);
	var e = $("#" + id);
	//<img src='../images/icons/loading.gif' border='0' />
	//e.prepend("<div align='center'>正在加载...</div>");
	e.load(url,params,callback);
}

function GetRand(){
	return (new Date()).getTime();
}

function ToggleCat(theid,level) {
  if (document.getElementById) {
    var switch_id = document.getElementById(theid);
    var imgid = 'button_' + theid;
    var button_id = document.getElementById(imgid);
    if (switch_id == null) {
    	return;
    }
    if (switch_id.className != 'showSwitch') {
      button_id.className = 'rolldown' + level;
      switch_id.className = 'showSwitch';
    } else {
      button_id.className = 'rollup' + level;
      switch_id.className = 'hideSwitch';
    }
  }
}

function SetCookie (name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) + (expires ? "; expires=" + expires : "") + (path ? "; path=" + path : "") + (domain ? "; domain=" + domain : "") + (secure ? "secure" : "");
    document.cookie = curCookie;
}

function GetCookie (name) {
    var prefix = name + '=';
    var c = document.cookie;
    var nullstring = '';
    var cookieStartIndex = c.indexOf(prefix);
    if (cookieStartIndex == -1)
        return nullstring;
    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
    if (cookieEndIndex == -1)
        cookieEndIndex = c.length;
    return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function DeleteCookie (name, path, domain) {
    if (getCookie(name))
        document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function WriteIfrmae(frameId,html) {
    var frame = $("iframe#" + frameId).get(0);
    var frameWindow = $("iframe#" + frameId).get(0).contentWindow;
    var frameDocument = $("iframe#" + frameId).get(0).contentWindow.document;
    
    try {
        // 针对IE浏览器, make it editable
         frameDocument.designMode = "On";
         frameDocument.contentEditable = true;
        // For compatible with FireFox, it should open and write something to make it work
         frameDocument.open();
         frameDocument.writeln(html);
         frameDocument.close();                
         frameDocument.designMode = "Off";
         frameDocument.contentEditable = false
    } catch (e) {
    
    }
}
