﻿/***************************************
Creator: leo(linhui)
Created Date: 2007-10-25
Description: Show the one or more than one images by interval time. the <img> must have the attribute "images", which store the image url.
****************************************/
function ShowMoreImages(obj, intervalSecond)
{
    if (obj.tagName.toLowerCase() == "span")
	{
		return;
	}
	var index = 0;
	var images;
	var param;
	if (obj != null && obj.images != null && obj.images.length > 0)
	{
//	    obj.onload = function(){LoadObject();}
//	    obj.onerror = function(){ErrorObject();}
		images = obj.images.split(""|"");
		if (images.length > 0)
		{
			param = window.setInterval(IntervalShow, intervalSecond);
			obj.onmouseover = function(){window.clearInterval(param) }
			obj.onmouseout = function(){ param = window.setInterval(IntervalShow, intervalSecond); }
		}
		else
		{
			IntervalShow();
		}
	}
	
	function IntervalShow()
	{
		obj.src = images[index];
		index += 1;
		if (index >= images.length)
		{
			index = 0;
		}
	}
	
	function LoadObject()
	{
	    
	}
	
	function ErrorObject()
	{
	    IntervalShow();
	}
}

/*****************************************************************
* remove the blank from the top or end of string 
****************************************************************/
function lTrim(str) 
{ 
	if(str.length>0)
	{
		if (str.charAt(0) == " ") 
		{ 
			str = str.slice(1);
			str = lTrim(str);  
		}
	} 
	return str; 
} 

function rTrim(str) 
{ 
	if(str.length>0)
	{
		var iLength; 
	
		iLength = str.length; 
		if (str.charAt(iLength - 1) == " ") 
		{ 
			str = str.slice(0, iLength - 1);
			str = rTrim(str);  
		} 
	}
	return str; 
} 

function trim(str) 
{ 
	return lTrim(rTrim(str)); 
}

/**********************************************
* Tool method
****************************************/
function GetStringByObject(obj)
{
    if (obj == null)
        return "";
    else
        return obj.toString();
}

/******************************************
 Open a widonw, like the method "showModalDialog", but here it can maximize
parameters: the default of width is 600; the default of height is 500.
*****************************************/
function OpenUrl(url,width,height)
{
	try{
		if(!url) return;
        if (GetBrowse() == "MSIE")
            window.event.cancelBubble=true;
		var swd = screen.width;
		var shg = screen.height;
		if(!width)	width = 650;
		if(!height) height = 500;
		var top = (shg-height)/2;
		var left = (swd-width)/2;
		var w = window.open("Loading.htm?"+encodeURIComponent(url),"","height="+height+",width="+width+",top="+top+",left="+left+",resizable=1,scrollbars=1") ;
		w.focus();
	} catch (exception) {}
}

/**************************************************
* Get sub-node from DOM object.
***************************************************/
function GetObjectByTag(sourceObject, tagName, type)
{
    var sourceObjects = new Array();
    GetAllChildren(sourceObject, sourceObjects);
    var strTagName = tagName == null ? "" : tagName.toUpperCase();
    var strType = type == null ? "" : type.toUpperCase();
    var result = new Array();
    for ( var i = 0; sourceObjects.length > 0 && i < sourceObjects.length; i++)
    {
        if (sourceObjects[i].tagName != null && sourceObjects[i].tagName.toUpperCase() == strTagName)
        {
            if (null != sourceObjects[i].type && sourceObjects[i].type.toUpperCase() == strType && strType.length > 0)
                result[result.length] = sourceObjects[i];
            else if (strType.length <= 0)
                result[result.length] = sourceObjects[i];
        }
    }
    return result; 
}

function GetAllChildren(sourceObject, destArray)
{
    if (sourceObject.childNodes.length > 0)
    {
        if (GetObject(sourceObject))
            destArray[destArray.length] = sourceObject;
        for (var i = 0; i < sourceObject.childNodes.length; i++)
        {
            GetAllChildren(sourceObject.childNodes[i], destArray);
        }
    }
    else
    {
        if (GetObject(sourceObject))
            destArray[destArray.length] = sourceObject;
    }
    function GetObject(object)
    {
        try
        {
            if (object.tagName.length > 0)
                return true;
        }
        catch(e)
        {
            return false;
        }
    }
}

/****************************************************
* indicate the select location
*****************************************************/
function InitSelect(select, text, value)
{
    if (null == select || select.length == 0)
        return;
    var index = -1;
    if (trim(text).length > 0)
    {
        for (var i = 0; i < select.length; i++)
        {
            if (trim(select.options[i].text).toUpperCase() == trim(text).toUpperCase())
            {
                index = i;
                break;
            }
        }
    }
    if (trim(value).length > 0 && index == -1)
    {
        for (var i = 0; i < select.length; i++)
        {
            if (trim(select.options[i].value).toUpperCase() == trim(value).toUpperCase())
            {
                index = i;
                break;
            }
        }
    }
    select.selectedIndex = index;
}

function DoDefaultKeyPress(input) 
{
    if (input.tagName.toLowerCase() != "textarea" && input.tagName.toLowerCase() != "input")
    {
        return;
    }
    function append() 
    {
		// do some format
	}
	if (input.charSet=="Float") 
	{
		if (event.keyCode!=13 && event.keyCode!=46 && (event.keyCode<48 || event.keyCode>57)) 
		    event.keyCode=0;
		else 
		    append();
	} 
	else if (input.charSet=="Int") 
	{
		if (event.keyCode!=13 && event.keyCode<48 || event.keyCode>57) 
		    event.keyCode=0;
		else 
		    append();
	} 
	else if (input.charSet=="Date")  
	{
		if (event.keyCode!=13 && event.keyCode!=47 && event.keyCode!=32 && event.keyCode!=45 && event.keyCode!=58 && (event.keyCode<48 || event.keyCode>57)) 
		    event.keyCode=0;
		else 
		    append();
	} 
	else if (input.charSet=="expr")  
	{
		if (event.keyCode!=13 && (event.keyCode<40 || event.keyCode==44 || event.keyCode>57)) 
		    event.keyCode=0;
		else 
		    append();
    }
    else if (input.charCase=="UpperCase") 
    {
		if (event.keyCode>=97 && event.keyCode<=122) 
		    event.keyCode=event.keyCode-32;
		append();
	}
	else if (input.charCase=="LowerCase") 
	{
		if (event.keyCode>=65 && event.keyCode<=90) 
		    event.keyCode=event.keyCode+32;
		append();
	}
	else 
	{
		append();
	}
}

/*************************************************************
Created By: linhui
Created Date: 2007-08-09
Description: 
when mouse move over objecct, pop up a div.
How to user(two method)
1. onmousemove="MouseOverForPrompt(this, "content", "title"); in ojbect. also no "content", "title", but in object, it must have title property;
2. InitPromptObject(document.all.text, "content", "title");

**************************************************************/
function InitPromptObject(obj, content, title, divId)
{
	function AddPromptDiv(content, title, divId) 
	{ 
		if (content == null || content.length <= 0)
			return;
		if (divId == null || divId.length <= 0)
		{
			divId = "PromptDiv";
		}
		var table = '';
		table = '<table class="PromptTable" width="100%" height="100%" border"=0" cellpadding="0" cellspacing="0">';
		if (title != null && title.length > 0)
		{
			table += '<tr class="TitleTr"><td class="TitleTd"><b>';
			table += title;
			table += '</b></td></tr>';
		}
		table += '<tr class="ContentTr"><td class="ContentTd">';
		table += content;
		table += '</td></tr></table>';

		var PromptDiv =document.getElementById(divId);
		if (PromptDiv == null)
		{
			var newDiv = document.createElement("div");
			newDiv.setAttribute("id", divId);
			document.body.appendChild(newDiv);
			PromptDiv =document.getElementById(divId);
		}
		PromptDiv.innerHTML = table;
		return PromptDiv;
	}
	
	function RemovePromptDiv(id)
	{
		if (id == null || id.length <= 0)
		{
			id = "PromptDiv";
		}
		var obj = document.getElementById(id);  	
		if (obj != null)
		{ 
			obj.style.display = "none";   // hidden not delete
			obj.style.visibility = "hidden";
			// obj.parentNode.removeChild(obj);   // delete
		}
	}
	
	function MouseMove(obj)
	{
		if (typeof(obj) == "object" && obj != null)
		{
			var x = event.x + document.body.scrollLeft + 10; 
			var y = event.y + document.body.scrollTop + 5;
			obj.style.left = x;
			obj.style.top = y;
			obj.style.display = "block";
			obj.style.visibility = "visible";
		}
	}

    if (title == null || title.length <= 0)
	{	
		if (obj.title != null && obj.title != "")
		{
			title = obj.title;
		}
	}
	if (content == null || content.length <= 0)
	{	
		if (obj.content != null && obj.content != "")
		{
			content = obj.content;
		}
		else
		{
		    content = title;
		}
	}
	
	if (content != null && content.length > 0)
	{
		var promptDiv;
		obj.onmouseover = function(){promptDiv = AddPromptDiv(content, title);};
		obj.onmousemove = function(){MouseMove(promptDiv);};
		obj.onmouseout = function(){RemovePromptDiv();};
		obj.onclick = function(){RemovePromptDiv();};
	}
}

function MouseOverForPrompt(obj,content, title, divId)
{
	InitPromptObject(obj, content, title, divId)
}
/**************************************************************************************
Created By: linhui
Created Date: 2007-09-29
Description: judge the browse type.
***************************************************************************************/
function GetBrowse() 
{
   var result = "MSIE"; 
   if(navigator.userAgent.indexOf("MSIE")>0) { 
        result = "MSIE"; 
   } 
   else if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){ 
        result = "FIREFOX"; 
   } 
   else if(isSafari=navigator.userAgent.indexOf("Safari")>0) { 
        result = "SAFARI"; 
   }  
   else if(isCamino=navigator.userAgent.indexOf("Camino")>0){ 
        result = "CAMINO"; 
   } 
   else if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){ 
        result = "GECKO"; 
   } 
   return result;
} 
function IsIE()
{
	var ie4 = (document.all)? true:false;
	return ie4;
}
function IsIe5()
{
	var ie5 = true;
	if (IsIE()) { 
		if (navigator.userAgent.indexOf('MSIE 5')>0) 
		{ 
			ie5 = true; 
		} 
		else 
		{ 
			ie5 = false; 
		} 
	} 
	else 
	{ 
		ie5 = false; 
	}
	return ie5;
}
function IsNs()
{
	var ns4 = (document.layers)? true:false;
	return ns4;
}
/****************************  end prompt *****************************************/

/************************** ******* ******* ******* ******* ******* ******* ******* 
Created By: linhui
Created Date: 2007-08-29
Description: 
div always is in the some place of screen
How to use
first initial the div in the body onload
InitScrollDiv(div);
div.Scroll(); // this can begin to scroll.
div.Remove(); // this can stop to scroll.

css: the css is "FloatedDiv";
************/
function InitScrollDiv(obj)
{
	obj.varScroll = null;
	function Scroll()
	{
		var posX,posY;
		if (window.innerHeight) {
			posX = window.pageXOffset;
			posY = window.pageYOffset;
		}
		else if (document.documentElement && document.documentElement.scrollTop) {
			posX = document.documentElement.scrollLeft;
			posY = document.documentElement.scrollTop;
		}
		else if (document.body) {
			posX = document.body.scrollLeft;
			posY = document.body.scrollTop;
		}
		obj.style.top=(posY+100)+"px";
		obj.style.left=(posX+50)+"px";
		obj.varScroll = setTimeout(Scroll,100);
	}
	obj.Scroll = function(){
		Scroll();
	};
	
	obj.Remove = function(){
		if (obj.varScroll != null)
			clearTimeout(obj.varScroll);
	}
}

/******************************************
Creater: linhui
Created Date: 2007-09-05
Description: Format the date
***************************************/
function GetDateByFormat(str,oldFormat,newFormat) 
{
    try
    {
        var year = "";
        var month = "";
        var day = "";
        var hour = "00";
        var minute = "00";
        var second = "00";
        
        if (oldFormat == null || oldFormat == "")
        {
            return str;
        }
        oldFormat = oldFormat.toUpperCase();
        if (newFormat == null || newFormat == "")
        {
            // default
            newFormat = "YYYYMMDD";
        }
        newFormat = newFormat.toUpperCase();

        if (oldFormat == "YYYYMMDD")
        {
            year = str.substr(0, 4);
            month = str.substr(4, 2);
            day = str.substr(6, 2);
        }
        else if (oldFormat == "MMDDYYYY")
        {
            year = str.substr(4, 4);
            month = str.substr(0, 2);
            day = str.substr(2, 2);
        }
        else if (oldFormat == "YYYYMMDDHHMM")
        {
            year = str.substr(0, 4);
            month = str.substr(4, 2);
            day = str.substr(6, 2);
            hour = str.substr(8, 2);
            minute = str.substr(10, 2);
        }
        else if (oldFormat == "YYYYMMDDHHMMSS")
        {
            year = str.substr(0, 4);
            month = str.substr(4, 2);
            day = str.substr(6, 2);
            hour = str.substr(8, 2);
            minute = str.substr(10, 2);
            second = str.substr(12, 2);
        }
        else if (oldFormat == "YYYY/MM/DD")
        {
            year = str.substr(0, 4);
            month = str.substr(5, 2);
            day = str.substr(8, 2);
        }
        else if (oldFormat == "MM/DD/YYYY")
        {
            year = str.substr(6, 4);
            month = str.substr(0, 2);
            day = str.substr(3, 2);
        }
        else if (oldFormat == "YYYY-MM-DD")
        {
            year = str.substr(0, 4);
            month = str.substr(5, 2);
            day = str.substr(8, 2);
        }               
        else if (oldFormat == "MM-DD-YYYY")
        {
            year = str.substr(6, 4);
            month = str.substr(0, 2);
            day = str.substr(3, 2);
        }               
        else if (oldFormat == "MM-DD-YYYY HH:MM")
        {
            year = str.substr(6, 4);
            month = str.substr(0, 2);
            day = str.substr(3, 2);
            hour = str.substr(11, 2);
            minute = str.substr(14, 2);
        }
        else
        {
            return str;
        }

        if (newFormat == "YYYYMMDD")
        {
            return year + month + day;
        }
        else if (newFormat == "MMDDYYYY")
        {
            return month + day + year;
        }
        else if (newFormat == "YYMMDDHHMM")
        {
            return year.substr(2, 2) + month + day + hour + minute;
        }
        else if (newFormat == "YYYYMMDDHHMM")
        {
            return year + month + day + hour + minute;
        }
        else if (newFormat == "YYYYMMDDHHMMSS")
        {
            return year + month + day + hour + minute + second;
        }
        else if (newFormat == "MMDDYYYY HH:MM:SS")
        {
            return month + day + year + " " + hour + ":" + minute + ":" + second;
        }
        else if (newFormat == "YYYY/MM/DD")
        {
            return year + "/" + month + "/" + day;
        }
        else if (newFormat == "MM/DD/YYYY")
        {
            return month + "/" + day + "/" + year;
        }
        else if (newFormat == "MM-DD-YYYY")
        {
            return month + "-" + day + "-" + year;
        }
        else if (newFormat == "MM-DD-YYYY HH:MM")
        {
            return month + "-" + day + "-" + year + " " + hour + ":" + minute;
        }
        else if (newFormat == "YYYY-MM-DD HH:MM")
        {
            return year + "-" + month + "-" + day + " " + hour + ":" + minute;
        }
        else if (newFormat == "MM-DD-YYYY HH:MM:SS")
        {
            return month + "-" + day + "-" + year + " " + hour + ":" + minute + ":" + second;
        }
        else
        {
            return str;
        }
    }
    catch(exception)
    {
        return str;
    }
}

/**********************************

*********************************/
function bookmark1(url,description)
   {
        var URL=url;
        var des =  description;
        window.external.AddFavorite(URL, des);
   }