﻿if (!document.getElementById) {
document.getElementById = function(strID) {
if (document.layers) return document[strID];
if (document.all) return document.all[strID];
return null; // expect the unexpected
}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);}
function getElementByserverId(elementServerID){
    return getElementByclientId(clientIdhead+elementServerID);//document.getElementById(clientIdhead+elementServerID);
} 
function getElementByclientId(clientId)
{
    var ele;
    if(document.getElementById)
    {
        ele = document.getElementById(clientId);
    }
    else
    {
        ele = document.all[clientId];
    }
    return ele;
}
function LTrim(str){
    var whitespace = new String(" \t\n\r");
    var s = new String(str);
    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;
}
function RTrim(str){
var whitespace = new String(" \t\n\r");
var s = new String(str);
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;
}
function Trim(str){
    return RTrim(LTrim(str));
}
function setCookie(name,value,validdays)
{
  var Days = validdays; //此 cookie 将被保存 365 天
  var exp  = new Date();    //new Date("December 31, 9998");
  if(Days != "")
  {
     exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape(value) +";expires="+ exp.toGMTString();
  }
  else
  {
    document.cookie = name + "="+ escape(value);  
  }
}
function getCookie(name)
{
  var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
  if(arr != null) return unescape(arr[2]); return null;
}
function delCookie(name)
{
  var exp = new Date();
  exp.setTime(exp.getTime() - 1);
  var cval=getCookie(name);
  if(cval!=null) document.cookie=name +"="+cval+";expires="+exp.toGMTString();
}
function createCustomAlert(txt,thisobject,width,height,top,left,btnType) {
	// shortcut reference to the document object
	d = document;

	// if the modalContainer object already exists in the DOM, bail out.
	if(d.getElementById("modalContainer")) return;

	// create the modalContainer div as a child of the BODY element
	mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
	mObj.id = "modalContainer";
	 // make sure its as tall as it needs to be to overlay all the content on the page
	mObj.style.height = document.documentElement.scrollHeight + "px";

	// create the DIV that will be the alert 
	alertObj = mObj.appendChild(d.createElement("div"));
	alertObj.id = "alertBox";
	// MSIE doesnt treat position:fixed correctly, so this compensates for positioning the alert
	if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
	// center the alert box
	//alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px";
    alertObj.style.width = width;
    alertObj.style.height = height;
    alertObj.style.top = top;
    alertObj.style.left = left;
	alertObj.style.zIndex = 10000;
	h1 = d.createElement("h1");
	alertObj.appendChild(h1);
	h1.appendChild(d.createTextNode("随心呼"));
	h1.onmousedown = function(){MouseDownToRemove(this);}
	h1.onmousemove = function(){MouseMoveToRemove(this);}
	h1.onmouseup = function(){MouseUpToRemove(this);}
	var alertContent = alertObj.appendChild(d.createElement("div"));
	alertContent.id = "alertContent";
    //alertObj.style.top = thisobject.offsetTop;
    //alertObj.style.left = thisobject.offsetLeft;
	// create an H1 element as the title bar

	var xx = d.createElement("span");
	xx.id="x";
	xx.innerHTML = "×";
	xx.style.left = width-20 + "px";
	xx.onclick = function() {document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));}
	alertObj.appendChild(xx);

	// create a paragraph element to contain the txt argument
	//msg = alertObj.appendChild(d.createElement("p"));
	//msg.appendChild(txt);
    alertContent.appendChild(txt);

	var btnp = document.createElement("div");
	btnp.id = "btnp";
	alertObj.appendChild(btnp);

	if(btnType != "showmsg")
	{
		// create an anchor element to use as the confirmation button.
		btn = d.createElement("input");
		btn.type = "button";
		btn.id = "closeBtn";
		btn.value = "确定";
		btnp.appendChild(btn);
		// set up the onclick event to remove the alert when the anchor is clicked
		btn.onclick = function() { removeCustomAlert(thisobject);return false; }
	}
	
	closebtn = d.createElement("input");
	closebtn.type = "button";
	closebtn.id = "closeBtn2";
	btnp.appendChild(closebtn);
	closebtn.value = "取消";
	if(btnType == "showmsg")
	{
		closebtn.value = "确定";
		closebtn.style.align = "center";
	}
	closebtn.onclick = function() { document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));return false; }
	var framediv = d.createElement("IFRAME");
	framediv.id = "framediv";
	mObj.appendChild(framediv);
	//framediv.style.display = "none";
	framediv.style.height = document.documentElement.scrollHeight + "px";
	framediv.scroll = "none";
}
function fulltohalf(obj)
{
	var str=obj.value;
	var result="";
	for (var i = 0; i < str.length; i++)
	{
		if (str.charCodeAt(i)==12288)
		{
			result+= String.fromCharCode(str.charCodeAt(i)-12256);
			continue;
		}
		if (str.charCodeAt(i)>65280 && str.charCodeAt(i)<65375)
		{
			result+= String.fromCharCode(str.charCodeAt(i)-65248);
		}
		else 
		{
			result+= String.fromCharCode(str.charCodeAt(i));
		}
	}
	obj.value=result;
}
