﻿// Get DOM
var timer;
var popFlag=false;
var selectid=-1;

function $ID(s){return document.getElementById(s);}
function getElementByClassName(cls,eleID,elm) 
{
var arrCls =[];
var seeElm = typeof eleID=='object'?eleID:$ID(eleID);
var rexCls = new RegExp('(^|\\\\s)' + cls + '(\\\\s|$)','i');
var lisElm = seeElm.getElementsByTagName(elm);
for (var i=0; i<lisElm.length; i++ ) {
var evaCls = lisElm[i].className;
if(evaCls.length > 0 && (evaCls == cls || rexCls.test(evaCls))) {
arrCls.push(lisElm[i]);
}
}
return arrCls;
} 

function checkObj() { 
if(navigator.userAgent.indexOf("IE")>0) { 
    return "IE"; 
} 
if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){ 
    return "Firefox"; 
} 
if(isSafari=navigator.userAgent.indexOf("Safari")>0) { 
    return "Safari"; 
} 
if(isCamino=navigator.userAgent.indexOf("Camino")>0){ 
    return "Camino"; 
} 
if(isMozilla=navigator.userAgent.indexOf("Gecko")>0){ 
    return "Gecko"; 
} 

} 

////CreatDiv
function f_createdivs(divcnt,leftPx,topPx,widthPx,Flag){
  for(var i=0;i<divcnt;i++){
   var objdiv = document.createElement("DIV");
   var objname="greatDiv_" + i
   objdiv.id = objname;
   objdiv.style.top = (parseInt(topPx) + 25) +"px";
   objdiv.style.left = (parseInt(leftPx)-200)+"px";
   objdiv.style.background = '#f2f2f2';
   objdiv.style.visibility = 'visible';
   objdiv.style.position = 'absolute';
   objdiv.style.width = widthPx;
   objdiv.style.height = "auto";
   objdiv.style.border = "2 solid #BEB09C";
   objdiv.innerHTML="loading...";
   document.body.appendChild(objdiv);
   if(Flag)
   {
       document.getElementById(objname).onmouseout = function()
       {
         hiddendivd(this.id);
       };
   }
  }
 }

function deleteDiv(eleID)
{
    var Div=$ID(eleID);
    Div.parentNode.removeChild(Div);
}

function $Tarname(eleID,targetName){return eleID.getElementsByTagName(targetName);}
//得到期所在左边距和上边距 定位
function getPosTop(obj)
{
var t = obj.offsetTop;
while(obj = obj.offsetParent)
{t += obj.offsetTop;}
return t;
}

function getPosLeft(obj)
{
var l = obj.offsetLeft;
while(obj = obj.offsetParent)
{l += obj.offsetLeft;}
return l;
}

//checkEmail
 function isEmail(strEmail) {
    if(strEmail=="LightakeShare"||strEmail=="lightakeshare")
    {
        return true;
    }else{
        if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
            return true;
        else
            return null;
    }
}

// 隐藏和显示相关
function SetDivCss(obj,cssName){
	if(typeof(obj)=="object")
		obj.className = cssName;		
	else
		$ID(obj).className = cssName;
}

// Cookie
function setLongCookie(names,value)
{
	var  days=30; 
	var  expire_date=new Date(); 
	var ms_from_now=days*24*60*60*1000;
	expire_date.setTime(expire_date.getTime()+ms_from_now);
	var expire_string=expire_date.toGMTString();
	document.cookie=names+"="+value+";expires="+expire_string+";path=/";
}
  
function getCookieVal(name)
{
    var firstCharPos,lastCharPos;
    var theBigCookie = document.cookie;
    firstCharPos = theBigCookie.indexOf(name);
    if(firstCharPos != -1)
    {
    firstCharPos +=name.length + 1;    
    lastCharPos = theBigCookie.indexOf(';', firstCharPos);
    if(lastCharPos == -1) lastCharPos = theBigCookie.length;
    return theBigCookie.substring(firstCharPos, lastCharPos);
    }
    else
    { return false;}
}  

function trim(str){ //删除左右两端的空格
    return str.replace(/(^\s*)|(\s*$)/g, "");
}
function ltrim(str){ //删除左边的空格
    return str.replace(/(^\s*)/g,"");
}
function rtrim(str){ //删除右边的空格
    return str.replace(/(\s*$)/g,"");
}


//页面内容设置
/////////////返回页面顶部///////////////////
function ReturntoPagetop()
{
    window.scrollTo(0,0);
}

///////////////////跳转指定页/////////////////////////////////
function GoUrl(str)
{
    parent.document.location.href = str;
}

function YanFun(FunName,mytime)
{
    clearTimeout(timer);
    timer = setTimeout(function(){eval(""+FunName+"");},mytime);
}

////////////////////////得到父级DOM//////////////////////////////
function getParentNode(eleID)
{
   return eleID.parentNode;
}

function showdiv(eleID)
{
    if(typeof(eleID)=="object")
    {
        eleID.style.display="block";
    }else{
        $ID(eleID).style.display="block";
    }
}

function hiddendiv(eleID)
{
    if(typeof(eleID)=="object")
    {
        eleID.style.display="none";
    }else{
        $ID(eleID).style.display="none";
    }
}

function ToDecimal(x)
{
   var f_x = parseFloat(x);
   if (isNaN(f_x))
   {
      alert('function:changeTwoDecimal->parameter error');
      return false;
   }
   var f_x = Math.round(x*100)/100;
   var s_x = f_x.toString();
   var pos_decimal = s_x.indexOf('.');
   if (pos_decimal < 0)
   {
      pos_decimal = s_x.length;
      s_x += '.';
   }
   while (s_x.length <= pos_decimal + 2)
   {
      s_x += '0';
   }
   return s_x;
}




Array.prototype.clear=function(){    
    this.length=0;    
}    
Array.prototype.insertAt=function(index,obj){    
    this.splice(index,0,obj);    
}    
Array.prototype.removeAt=function(index){    
    this.splice(index,1);    
}    
Array.prototype.remove=function(obj){    
    var index=this.indexOf(obj);    
    if (index>=0){    
    this.removeAt(index);    
    }    
}    




//domisready
new function(){  
dom = [];  
dom.isReady = false;  
dom.isFunction = function(obj){  
return Object.prototype.toString.call(obj) === "[object Function]";  
}  
dom.Ready = function(fn){  
dom.initReady();//如果没有建成DOM树，则走第二步，存储起来一起杀  
if(dom.isFunction(fn)){  
if(dom.isReady){  
fn();//如果已经建成DOM，则来一个杀一个  
}else{  
dom.push(fn);//存储加载事件  
}  
}  
}  
dom.fireReady =function(){  
if (dom.isReady)  return;  
dom.isReady = true;  
for(var i=0,n=dom.length;i<n ;i++){  
var fn = dom[i];  
fn();  
}  
dom.length = 0;//清空事件  
}  
dom.initReady = function(){  
if (document.addEventListener) {  
document.addEventListener( "DOMContentLoaded", function(){  
document.removeEventListener( "DOMContentLoaded", arguments.callee, false );//清除加载函数  
dom.fireReady();  
}, false );  
}else{  
if (document.getElementById) {  
document.write("<script id=\"ie-domReady\" defer='defer'src=\"//:\">< \/script>");  
document.getElementById("ie-domReady").onreadystatechange = function() {  
if (this.readyState === "complete") {  
dom.fireReady();  
this.onreadystatechange = null;  
this.parentNode.removeChild(this)  
}  
};  
}  
}  
}  
}

function showbig()
{
    $ID("popscreen").style.height=document.body.clientHeight+"px";
    $ID("popscreen_content").className="popscreen_content";
    $ID("popscreen").className="popscreen";
}

function hiddenpan()
{
    $ID("popscreen").className="hiddendiv";
    $ID("popscreen_content").className="hiddendiv";
}


function findObj(theObj, theDoc)
{
var p, i, foundObj;
if(!theDoc) theDoc = document;
if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
{ 
   theDoc = parent.frames[theObj.substring(p+1)].document;   
   theObj = theObj.substring(0,p); 
} 
if(!(foundObj = theDoc[theObj]) && theDoc.all) 
   foundObj = theDoc.all[theObj]; 

for (i=0; !foundObj && i < theDoc.forms.length; i++)    
   foundObj = theDoc.forms[i][theObj]; 

for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)    
   foundObj = findObj(theObj,theDoc.layers[i].document); 
   
if(!foundObj && document.getElementById) 
   foundObj = document.getElementById(theObj);   

return foundObj;
}

