﻿//Start Suryani
var Suryani={};
Suryani.extend=function(destination, source) 
{
	for (var property in source)
  	{
  		if(destination[property])
		{
			continue;
		}
    	destination[property] = source[property];
	}
  	return destination;
};
Suryani.clone=function(matrix)
{
	if(typeof(matrix)=="function")
	{
		return new matrix();
	}
	else if(typeof(matrix)=="object")
	{
		var cloning=new Object();
		for(var member in matrix)
		{
			switch(typeof(matrix[member]))
			{
				case "object":
					cloning[member]=clone(matrix[member]);
					break;
				default:
					cloning[member]=matrix[member];
			}
		}
		return cloning;
	}
	else
	{
		var cloning = matrix;
		return cloning;
	}
}
Suryani.getWindowWidth=function(objWindow)
{
	if(objWindow.innerWidth)
	{
		return Math.min(objWindow.innerWidth,objWindow.document.documentElement.clientWidth);
	}
	else
	{
		return objWindow.document.documentElement.clientWidth;
	}
}

Suryani.getWindowHeight=function(objWindow)
{
	if(objWindow.innerHeight)
	{
		return Math.min(objWindow.innerHeight,objWindow.document.documentElement.clientHeight);
	}
	else
	{
		return objWindow.document.documentElement.clientHeight;
	}
}

Suryani.getDocumentScrollTop=function(objDocument)
{
	return Math.max(objDocument.documentElement.scrollTop,objDocument.body.scrollTop);
}

Suryani.getDocumentScrollLeft=function(objDocument)
{
	return Math.max(objDocument.documentElement.scrollLeft,objDocument.body.scrollLeft);
}

Suryani.getDocumentWidth=function(objDocument)
{
	return objDocument.documentElement.scrollWidth;
}

Suryani.getDocumentHeight=function(objDocument)
{
	return objDocument.documentElement.scrollHeight;
}

Suryani.maxZIndex=function(objDocument)
{
	var zIndex=0;
	var elments=objDocument.getElementsByTagName("*");
	for(var i=0;i<elments.length;i++){
        if(elments[i].currentStyle) {
	        elementZIndex = elments[i].currentStyle.zIndex; //get z-index on IE
        } else if(window.getComputedStyle) {
	        elementZIndex = window.getComputedStyle(elments[i] , null).zIndex; //get z-index on Firfox, Safari and Chrome
        }
		if(elementZIndex)
		{
			if(zIndex<parseInt(elementZIndex))
			{
				zIndex=elementZIndex;
			}
		} 
	}
	return parseInt(zIndex);
}

Suryani.BindEvent=function(element,type,listener)
{
	if (window.addEventListener) 
	{
   		element.addEventListener(type, listener, false);
	} 
	else if (window.attachEvent) 
	{
		element.attachEvent('on'+type, listener);
	}
}
Suryani.userAgent = navigator.userAgent.toLowerCase();
Suryani.browser = {
    version: (Suryani.userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1],
    safari: /webkit/.test(Suryani.userAgent),
    opera: /opera/.test(Suryani.userAgent),
    msie: /msie/.test(Suryani.userAgent) && !/opera/.test(Suryani.userAgent),
    mozilla: /mozilla/.test(Suryani.userAgent)&&!/(compatible|webkit)/.test(Suryani.userAgent)
};
//End Suryani

//Start List
function List()
{
	this.data=new Array();
}
List.prototype.count=function()
{
	return this.data.length;
}

List.prototype.indexOf=function(item)
{
	var index=-1;
	for(var i=this.count();i>=0;)
	{
		if(this.data[--i]==item)
		{
			index=i;
			break;
		}
	}
	return index;
}
List.prototype.contain=function(item)
{
	return this.indexOf(item)==-1?false:true;
}
List.prototype.add=function(item)
{
	if(this.contain(item))
	{
		return;
	}
	this.data.push(item);
}
List.prototype.removeAt=function(index)
{
	for(var i=index;i<this.count()-1;i++)
	{
		this[i]=this[i+1];
	}
	return this.data.pop();
}
List.prototype.item=function(index)
{
	if(index>=0 && index<=this.count()-1)
	{
		return this.data[index]
	}
}
List.prototype.remove=function(item)
{
	var index=this.indexOf(item);
	if(index!=-1)
	{
		return this.removeAt(index);
	}
	return null;
}
//End List

//Start MaskPopup
function MaskPopup(param)
{
	this.targetWindow=param["targetWindow"]||window;
	this.elementKey=new Array();
	this.element=new Object();
	this.style=new Object();
	this.cssClass=new Object();
	
	this.elementKey.push("maskSpan");
	this.elementKey.push("maskDiv");
	this.element["maskSpan"]=this.targetWindow.document.createElement("span");
	this.element["maskDiv"]=this.targetWindow.document.createElement("div");
    this.element["maskDiv"].setAttribute("class","maskBackground");
	this.element["maskDiv"].setAttribute("className","maskBackground");
    this.style["maskDiv"]={zIndex:Suryani.maxZIndex(this.targetWindow.document)+1,display:"block"};
}
MaskPopup.prototype.setStyle=function()
{
	this.element.maskDiv.style.zIndex=this.style["maskDiv"]["zIndex"];
	this.element.maskDiv.style.display=this.style["maskDiv"]["display"];
}

MaskPopup.prototype.setSize=function()
{
	this.element.maskDiv.style.width="100%";
	this.element.maskDiv.style.height=Math.max(Suryani.getWindowHeight(this.targetWindow),Suryani.getDocumentHeight(this.targetWindow.document))+"px";
}

MaskPopup.prototype.setPosition=function()
{
	this.element.maskDiv.style.left="0px";
	this.element.maskDiv.style.top="0px";
}
MaskPopup.prototype.build=function()
{
	//IE6SelectHack
	if(Suryani.browser.msie && parseInt(Suryani.browser.version)<=6)
	{
		var html="<iframe src=\"\" style=\"z-index:-1;background-color:transparent;width:100%;height:100%\"></iframe>";
		this.element.maskDiv.insertAdjacentHTML("beforeEnd",html);
	}
	this.element.maskSpan.appendChild(this.element.maskDiv);
	this.targetWindow.document.body.appendChild(this.element.maskSpan);
}
MaskPopup.prototype.bindEvent=function()
{
	var me=this;
	Suryani.BindEvent(this.targetWindow,"resize",function(){ me.setSize();});
}
MaskPopup.prototype.show=function()
{
	this.setSize();
	this.setStyle();
	this.build();
	this.setPosition();
	this.bindEvent();
}
MaskPopup.prototype.close=function()
{
	this.targetWindow.document.body.removeChild(this.element.maskSpan);
}
//End MaskPopup

//Start Popup
function Popup(param)
{
	this.targetWindow=param["targetWindow"]||window;
	this.elementKey=new Array();
	this.config=new Object();
	this.element=new Object();
	this.callBack=new Object();
	this.cssClass=new Object();
	this.style=new Object();
	this.size=new Object();
	this.position=new Object();
	this.action=new Object();
	this.actionData=new Object();
	
	if(param.showMask)
	{
		this.config["showMask"]=param.showMask;
		this.mask=new MaskPopup({targetWindow:this.targetWindow});
	}
	this.config["title"]=param.title;
	this.config["content"]=param.content;
	this.config["language"]=param["language"]||"en-us";
	this.config["autoSize"]=false;
	this.config["moveable"]=!!param["moveable"];
	this.callBack["closeCallBack"]=param.closeCallBack;
	
	this.size["width"]=param.width||300;
	this.size["height"]=param.height||180;
	
	this.position["top"]=param.top;
	this.position["left"]=param.left;
	this.init();
}

Popup.language=new Object();

Popup.language["en-us"]=new Object();
Popup.language["en-us"]["ok"]="OK";
Popup.language["en-us"]["cancel"]="Cancel";
Popup.language["en-us"]["close"]="Close";
Popup.language["en-us"]["yes"]="Yes";
Popup.language["en-us"]["no"]="No";

Popup.prototype.init=function()
{
	this.action["hasShow"]=false;
	this.action["isMoving"]=false;
	
	this.actionData["moveStart"]=null;
	this.actionData["moveEnd"]=null;
	
	this.elementKey.push("popupSpan");
	this.elementKey.push("popupDiv");
	this.elementKey.push("popupBorderTop");
	this.elementKey.push("popupBorderBottom");
	this.elementKey.push("popupContent");

	this.elementKey.push("closeDiv");
	this.elementKey.push("headerDiv");

	this.elementKey.push("contentDiv");
	this.element["popupSpan"]=this.targetWindow.document.createElement("span");
	this.element["popupDiv"]=this.targetWindow.document.createElement("div");
	this.element["popupBorderTop"]=this.targetWindow.document.createElement("div");
	this.element["popupBorderBottom"]=this.targetWindow.document.createElement("div");
	
	this.element["popupContent"]=this.targetWindow.document.createElement("div");
	this.element["popupContent"].setAttribute("class","stickyTooltipContent");
	this.element["popupContent"].setAttribute("className","stickyTooltipContent");
	
	this.element["headerDiv"]=this.targetWindow.document.createElement("h2");
	this.element["headerDiv"].setAttribute("class","stickyTooltipTitle");
	this.element["headerDiv"].setAttribute("className","stickyTooltipTitle");

	this.element["closeDiv"]=this.targetWindow.document.createElement("div");
	this.element["closeDiv"].setAttribute("class","closeBtn");
	this.element["closeDiv"].setAttribute("className","closeBtn");
	
	this.element["contentDiv"]=this.targetWindow.document.createElement("div");
	this.element["contentDiv"].setAttribute("class","iframeContent");
	this.element["contentDiv"].setAttribute("className","iframeContent");
	
	this.style["popupDiv"]={position:"absolute"};
	
	this.style["popupDiv"]["zIndex"]=Suryani.maxZIndex(this.targetWindow.document)+3;
}

//initBackground
Popup.prototype.initBackground=function(){}
//initContent
Popup.prototype.initContent=function(){}
//setStyle
Popup.prototype.setStyle=function()
{
	for(var i=this.elementKey.length-1;i>0;i--)
	{
		var key=this.elementKey[i];
		if(!this.style[key])
		{
			continue;
		}
		for(var styleItem in this.style[key])
		{
			try
			{
				this.element[key].style[styleItem]=this.style[key][styleItem];
			}
			catch(e)
			{}
		}
	}
}
Popup.prototype.setClass=function()
{
	for(var i=this.elementKey.length-1;i>0;i--)
	{
		var key=this.elementKey[i];
		if(!this.cssClass[key])
		{
			continue;
		}
		try
		{
			this.element[key].className=this.cssClass[key];
		}
		catch(e)
		{}
	}
}
//setSize
Popup.prototype.setSize=function()
{
	this.element.popupDiv.style["width"]=(parseInt(this.size.width) + 31) +"px";
	this.element.popupDiv.style["height"]=this.size.height+"px";
}
//setSize with URL iframe
Popup.prototype.setUrlSize=function()
{
	this.element.popupDiv.style["height"]=this.size.height+"px";
}
//setPosition
Popup.prototype.setPosition=function()
{
        if(this.position.top)
        {
            this.element.popupDiv.style["top"]=this.position.top+"px";
        }
        else
        {
			var availHeight=Suryani.getWindowHeight(this.targetWindow);
			var availTop=0;
			if(availHeight-this.size.height>0)
			{
				availTop=(availHeight-this.size.height)/2+Suryani.getDocumentScrollTop(this.targetWindow.document);
				this.element.popupDiv.style["top"]=availTop+"px";
			}
			else
			{
			    availTop = 20 + Suryani.getDocumentScrollTop(this.targetWindow.document);
			    this.element.popupDiv.style["top"]=availTop+"px";
			    if(this.config["showMask"]){
			        this.mask.setSize();
			    }
			}
        }
        if(this.position.left)
        {
            this.element.popupDiv.style["left"]=this.position.left+"px";
        }
        else
        {
			var availWidth=Suryani.getWindowWidth(this.targetWindow);
			var availLeft=0;
			if(availWidth-this.size.width>0)
			{
				availLeft=(availWidth-this.size.width)/2+Suryani.getDocumentScrollLeft(this.targetWindow.document);
			}
            this.element.popupDiv.style["left"]=availLeft+"px";
        }
}
//reset the size of popup
Popup.prototype.resetPopupSize=function(width, height)
{
    if (width){
        this.size.width = width;
        this.element["url"].setAttribute("width", width + "px");
    }
    if (height){
        this.size.height = height;
        this.element["url"].setAttribute("height", height + "px");
    }
    this.setSize();
    this.setPosition();
}
//The user can close the hopup window by clicking the outside area of the hopup window
Popup.prototype.closePopupByClickingOutside=function(thisCloseCallBack){
    if(this.config.showMask)
	{
        var me = this;
		Suryani.BindEvent(this.mask.element["maskDiv"],"click",function(){
            if (thisCloseCallBack)
            {            
                thisCloseCallBack();
            }
			me.close();
			if(me.callBack.closeCallBack)
			{
				me.callBack.closeCallBack();
			}
	    });
	}
}

//build
Popup.prototype.build=function()
{
	//IE6SelectHack
	if(Suryani.browser.msie && parseInt(Suryani.browser.version)<=6)
	{
		var html="<iframe src=\"\" style=\";position:'absolute';top:0;left:0;z-index:-1;filter:mask();width:100%;height:100%\"></iframe>";
		this.element["popupDiv"].insertAdjacentHTML("beforeEnd",html);
	}
	
    this.element["popupBorderTop"].innerHTML = "<div class=\"stickyTooltipTopLeft\"></div><div class=\"stickyTooltipTopRight\"></div>";
    this.element["popupBorderTop"].setAttribute("class","stickyTooltipTop clearfix");
    this.element["popupBorderTop"].setAttribute("className","stickyTooltipTop");
    this.element["popupDiv"].appendChild(this.element["popupBorderTop"]);
    
    if (this.config["title"]!="")
    {
        this.element["headerDiv"].innerHTML=this.config["title"];
        this.element["popupContent"].appendChild(this.element["headerDiv"]);
    }
    this.element["popupContent"].appendChild(this.element["contentDiv"]);
    this.element["popupContent"].appendChild(this.element["closeDiv"]);
    this.element["popupDiv"].appendChild(this.element["popupContent"]);
	
	this.element["popupSpan"].appendChild(this.element["popupDiv"]);
	try{
		this.targetWindow.document.body.appendChild(this.element["popupSpan"]);
	}
	catch(ex){
		//alert(this.targetWindow.document.body.innerHTML);
		//alert(ex.message);
	}
	
    this.element["popupBorderBottom"].innerHTML = "<div class=\"stickyTooltipBtmLeft\"></div><div class=\"stickyTooltipBtmRight\"></div>";
    this.element["popupBorderBottom"].setAttribute("class","stickyTooltipBtm clearfix");
    this.element["popupBorderBottom"].setAttribute("className","stickyTooltipBtm");
    this.element["popupDiv"].appendChild(this.element["popupBorderBottom"]);  
}
//buildContent
Popup.prototype.buildContent=function(){}
//bindEvents
Popup.prototype.bindEvents=function()
{
	var me=this;
	Suryani.BindEvent(this.element["closeDiv"],"click",function(){
			me.close();
			if(me.callBack.closeCallBack)
			{
				me.callBack.closeCallBack();
			}
	});
    if(me.config["moveable"])
    {
        Suryani.BindEvent(this.element["headerDiv"],"mousedown",function(event){
                me.action["isMoving"]=true;
                me.actionData["moveStart"]={left:event.clientX,top:event.clientY};
                me.element["headerDiv"].style["cursor"]='move';
        });
        Suryani.BindEvent(this.targetWindow.document,"mousemove",function(event){
                if(me.action["isMoving"])
                {
                    var srcelement = event.srcelement || event.target;
                    me.actionData["moveEnd"]={left:event.clientX,top:event.clientY};
                    var targetLeft=parseInt(me.element.popupDiv.style["left"])+event.clientX-me.actionData["moveStart"].left;
                    var targetTop=parseInt(me.element.popupDiv.style["top"])+event.clientY-me.actionData["moveStart"].top;
                    if(targetLeft>=0 && targetLeft<=Suryani.getDocumentWidth(me.targetWindow.document)-me.element.popupDiv.clientWidth)
                    {
                        me.element.popupDiv.style["left"]=targetLeft+"px";
                    }
                    else
                    {
                        me.action["isMoving"]=false;
                        me.element["headerDiv"].style["cursor"]='auto';
                    }
                    if(targetTop>=0 && targetTop<=Suryani.getDocumentHeight(me.targetWindow.document)-me.element.popupDiv.clientHeight)
                    {
                        me.element.popupDiv.style["top"]=targetTop+"px";
                    }
                    else
                    {
                        me.action["isMoving"]=false;
                        me.element["headerDiv"].style["cursor"]='auto';
                    }
                    me.actionData["moveStart"]=me.actionData["moveEnd"];
                }
        });
        Suryani.BindEvent(this.targetWindow.document,"mouseup",function(){
            me.action["isMoving"]=false;
            me.element["headerDiv"].style["cursor"]='auto';
        });
    }
}
Popup.prototype.bindContentEvents=function(){}
//show
Popup.prototype.show=function()
{
	this.initBackground();
//	this.init();
//	this.initContent();
	this.setStyle();
	this.setClass();
	this.setSize();
	this.setPosition();
	this.bindEvents();
	this.bindContentEvents();
	this.build();
	this.buildContent();
	if(this.config.showMask)
	{
		this.mask.show();
	}
}
Popup.prototype.showModalDialog=function()
{
    this.show();
    this.mask.show();
}
//close
Popup.prototype.close=function()
{
	this.targetWindow.document.body.removeChild(this.element.popupSpan);
	if(this.config["showMask"])
	{
		this.mask.close();
	}
}
//addCallBack
Popup.prototype.addCallBack=function(elementKey,listener)
{
	elementKey=elementKey.toLowerCase();
	if(this.element[elementKey])
	{
		this.callBack[elementKey].add(listener);
	}
}
//removeCallBack
Popup.prototype.removeCallBack=function(elementKey,listener)
{
	elementKey=elementKey.toLowerCase();
	if(this.element[elementKey])
	{
		this.callBack[elementKey].remove(listener);
	}
}
//End Popup

//Start TipPopup
function TipPopup(param)
{
	this.base = new Popup(param);
	Suryani.extend(this,this.base);
    this.config["autoClose"]=param["autoClose"]||0;
	this.initContent();
}
TipPopup.prototype.initContent=function()
{
	this.elementKey.push("tipDiv");
	this.element["tipDiv"]=this.targetWindow.document.createElement("div");
	this.element["tipDiv"].innerHTML=this.config["content"];
	this.element["tipDiv"].setAttribute("class","lightRedText bold font13Text");
    this.element["tipDiv"].setAttribute("className","lightRedText bold font13Text");
	this.style["tipDiv"]={padding:"25px 20px 20px 20px"}
}
TipPopup.prototype.bindContentEvents=function(){
    var me=this;
    if(me.config["autoClose"])
    {
        setTimeout(function(){try{me.close()}catch(ex){}},me.config["autoClose"]);
    }
}
TipPopup.prototype.buildContent=function()
{
	this.element["contentDiv"].appendChild(this.element["tipDiv"]);
}

//End TipPopup

//Start AlertPopup
function AlertPopup(param)
{
	this.base = new Popup(param);
	Suryani.extend(this,this.base);
	this.initContent();
}
AlertPopup.prototype.initContent=function()
{
	this.elementKey.push("tipDiv");
	this.elementKey.push("ok");
	this.elementKey.push("innerContentDiv");
	this.elementKey.push("innerButtonDiv");
	this.element["tipDiv"]=this.targetWindow.document.createElement("div");
	this.element["tipDiv"].innerHTML=this.config["content"];
	//this.element["tipDiv"].setAttribute("class","redText bold");
	//this.element["tipDiv"].setAttribute("className","redText bold");
	//this.style["tipDiv"]={fontSize:"17px",lineHeight:"30px",padding:"0 0 0 10px"};
	this.element["ok"]=this.targetWindow.document.createElement("input");
	this.element["ok"].setAttribute("type","button");
	this.element["ok"].setAttribute("value",Popup.language[this.config["language"]]["ok"]);
	this.element["ok"].setAttribute("class","redBtn");
	this.element["ok"].setAttribute("className","redBtn");
	this.element["innerContentDiv"]=this.targetWindow.document.createElement("div");
	this.element["innerButtonDiv"]=this.targetWindow.document.createElement("div");
	this.element["innerButtonDiv"].setAttribute("class","btnsBox alertHopupWinBtn textCenter");
	this.element["innerButtonDiv"].setAttribute("className","btnsBox alertHopupWinBtn textCenter");
	this.callBack["ok"]=new List();
}
AlertPopup.prototype.bindContentEvents=function()
{
	var me=this;
	Suryani.BindEvent(me.element["ok"],"click",function(){
		for(var i=0;i<me.callBack["ok"].count();i++)
		{
			me.callBack["ok"].item(i)();
		}
		me.close();
	});
}
AlertPopup.prototype.buildContent=function()
{
	this.element["innerContentDiv"].appendChild(this.element["tipDiv"]);
	this.element["innerButtonDiv"].appendChild(this.element["ok"]);
	this.element["innerContentDiv"].appendChild(this.element["innerButtonDiv"]);
	this.element["contentDiv"].appendChild(this.element["innerContentDiv"]);
}

//End AlertPopup

//Start ConfirmPopup
function ConfirmPopup(param)
{
	this.base = new Popup(param);
	Suryani.extend(this,this.base);
	this.initContent();
}
ConfirmPopup.prototype.initContent=function()
{
	this.elementKey.push("tipDiv");
	this.elementKey.push("ok");
	this.elementKey.push("cancel");
	this.elementKey.push("innerContentDiv");
	this.elementKey.push("innerButtonDiv");
	this.element["tipDiv"]=this.targetWindow.document.createElement("div");
	this.element["tipDiv"].innerHTML=this.config["content"];
	this.element["tipDiv"].setAttribute("class","confirmPopupContent");
	this.element["tipDiv"].setAttribute("className","confirmPopupContent");
	this.element["ok"]=this.targetWindow.document.createElement("input");
	this.element["ok"].setAttribute("type","button");
	//this.element["ok"].setAttribute("value",Popup.language[this.config["language"]]["yes"]);
	this.element["ok"].setAttribute("class","yesBtn");
	this.element["ok"].setAttribute("className","yesBtn");
	this.element["cancel"]=this.targetWindow.document.createElement("input");
	this.element["cancel"].setAttribute("type","button");	
	//this.element["cancel"].setAttribute("value",Popup.language[this.config["language"]]["no"]);
	this.element["cancel"].setAttribute("class","noBtn");//for firefox and safari
	this.element["cancel"].setAttribute("className","noBtn");//for IE
	this.element["innerContentDiv"]=this.targetWindow.document.createElement("div");
	this.element["innerButtonDiv"]=this.targetWindow.document.createElement("div");
	this.element["innerButtonDiv"].setAttribute("class","btnsBox alertHopupWinBtn textCenter");
	this.element["innerButtonDiv"].setAttribute("className","btnsBox alertHopupWinBtn textCenter");
	this.callBack["ok"]=new List();
	this.callBack["cancel"]=new List();
}
ConfirmPopup.prototype.bindContentEvents=function()
{
	var me=this;
	Suryani.BindEvent(me.element["ok"],"click",function(){
		for(var i=0;i<me.callBack["ok"].count();i++)
		{
			me.callBack["ok"].item(i)();
		}
		me.close();
	});
	Suryani.BindEvent(me.element["cancel"],"click",function(){
		for(var i=0;i<me.callBack["cancel"].count();i++)
		{
			me.callBack["cancel"].item(i)();
		}
		me.close();
	});
}
ConfirmPopup.prototype.buildContent=function()
{
	this.element["innerContentDiv"].appendChild(this.element["tipDiv"]);
	this.element["innerButtonDiv"].appendChild(this.element["cancel"]);
	this.element["innerButtonDiv"].appendChild(this.element["ok"]);
	this.element["innerContentDiv"].appendChild(this.element["innerButtonDiv"]);
	this.element["contentDiv"].appendChild(this.element["innerContentDiv"]);
}
//End ConfirmPopup

//Start PromptPopup
function PromptPopup(param)
{
	this.base = new Popup(param);
	Suryani.extend(this,this.base);
	this.initContent();
}
PromptPopup.prototype.initContent=function()
{
	this.elementKey.push("tipDiv");
	this.elementKey.push("ok");
	this.elementKey.push("text");
	this.elementKey.push("innerContentDiv");
	this.elementKey.push("innerButtonDiv");
	this.element["tipDiv"]=this.targetWindow.document.createElement("div");
	this.element["ok"]=this.targetWindow.document.createElement("input");
	this.element["ok"].setAttribute("type","button");
	this.element["ok"].setAttribute("value",Popup.language[this.config["language"]]["ok"]);
	this.element["ok"].setAttribute("class","redBtn");
	this.element["ok"].setAttribute("className","redBtn");
	this.element["text"]=this.targetWindow.document.createElement("input");
	this.element["text"].setAttribute("type","text");	
	this.element["tipDiv"].innerHTML=this.config["content"];
	this.element["innerContentDiv"]=this.targetWindow.document.createElement("div");
	this.element["innerButtonDiv"]=this.targetWindow.document.createElement("div");
	this.element["innerButtonDiv"].setAttribute("class","btnsBox alertHopupWinBtn textCenter");
	this.element["innerButtonDiv"].setAttribute("className","btnsBox alertHopupWinBtn textCenter");
	this.callBack["ok"]=new List();
	this.callBack["text"]=new List();
	this.input="";
}
PromptPopup.prototype.bindContentEvents=function()
{
	var me=this;
	Suryani.BindEvent(me.element["ok"],"click",function(){
		for(var i=0;i<me.callBack["ok"].count();i++)
		{
			me.callBack["ok"].item(i)();
		}
		me.close();
	});
	Suryani.BindEvent(me.element["text"],"keyup",function(){
		me.input=me.element["text"].value;
	});
}
PromptPopup.prototype.buildContent=function()
{
	this.element["innerContentDiv"].appendChild(this.element["tipDiv"]);
	this.element["innerContentDiv"].appendChild(this.element["text"]);
	this.element["innerButtonDiv"].appendChild(this.element["ok"]);
	this.element["innerContentDiv"].appendChild(this.element["innerButtonDiv"]);
	this.element["contentDiv"].appendChild(this.element["innerContentDiv"]);
}
//End PromptPopup

//Start HtmlPopup
function HtmlPopup(param)
{
	this.base = new Popup(param);
	Suryani.extend(this,this.base);
	this.initContent();
}
HtmlPopup.prototype.initContent=function()
{
	this.element["contentDiv"].innerHTML=this.config["content"];
}
HtmlPopup.prototype.bindContentEvents=function(){}
HtmlPopup.prototype.buildContent=function(){}
//End HtmlPopup

//Start UrlPopup
function UrlPopup(param)
{
	this.base = new Popup(param);
	Suryani.extend(this,this.base);
	this.config["autoSize"]=true;
	this.initContent();
}
UrlPopup.prototype.initContent=function()
{ 
    this.elementKey.push("loading");
    this.element["loading"]=this.targetWindow.document.createElement("div");
    this.element["loading"].setAttribute("class","loadingDiv");
    this.element["loading"].setAttribute("className","loadingDiv");
	this.elementKey.push("url");
	this.element["url"]=this.targetWindow.document.createElement("iframe");
	this.element["url"].setAttribute("border","0");
	this.element["url"].setAttribute("frameBorder","0");
	this.element["url"].setAttribute("scrolling","no");
	this.element["url"].setAttribute("src",this.config["content"]);
	this.element["url"].setAttribute("width",(this.size.width)+"px");
    if (this.config["autoSize"]) {
        this.element["url"].setAttribute("height", "0");
        this.element["loading"].setAttribute("class","loadingDiv urlPopupLoading");
        this.element["loading"].setAttribute("className","loadingDiv urlPopupLoading");
    }
}
UrlPopup.prototype.bindContentEvents=function(){
	var me=this;
	Suryani.BindEvent(me.element["url"],"load",function(){
	                   me.element["loading"].style.display="none";
	                 });
	if(this.config["autoSize"])
	{
		Suryani.BindEvent(me.element["url"],"load",function(){
			try{
				var obj=me.element["url"];	
				if (obj.contentDocument && obj.contentDocument.body.offsetHeight)
				{
					obj.height = obj.contentDocument.body.scrollHeight;
					obj.width = obj.contentDocument.body.scrollWidth;
				}
				else
				{
					obj.height = obj.Document.body.scrollHeight;
					obj.width = obj.Document.body.scrollWidth;
				}
				me.setUrlSize();
				me.size.height=obj.height;
				me.size.width=obj.width;
				me.setPosition();
				
				var contentWindow=obj.contentWindow;
	            contentWindow.closeParent=function () {
	                me.close();
	            };
	            contentWindow.customerFunction=function () {
		            for(var i=0;i<me.callBack["url"].count();i++){
			            me.callBack["url"].item(i)();
		            }
	            };
			}catch(e){
			}
		});
	}
}
UrlPopup.prototype.buildContent=function()
{
    this.element["loading"].innerHTML="<span><img src='/Images/loading.gif'></span><span>Please Wait ...</span>";
    this.element["contentDiv"].appendChild(this.element["loading"]);
	this.element["contentDiv"].appendChild(this.element["url"]);
}
//End UrlPopup
//Start ImagePopup
function ImagePopup(param)
{
	this.base = new Popup(param);
	Suryani.extend(this,this.base);
	this.initContent();
}
ImagePopup.prototype.initContent=function()
{
	this.elementKey.push("imageBox");
	this.element["imageBox"]=this.targetWindow.document.createElement("div");
	this.element["imageBox"].innerHTML="<img src='"+ this.config["content"] +"' />";
    this.element["imageBox"].setAttribute("class","imageHopup");
    this.element["imageBox"].setAttribute("className","imageHopup");
}
ImagePopup.prototype.bindContentEvents=function(){}
ImagePopup.prototype.buildContent=function()
{
	this.element["contentDiv"].appendChild(this.element["imageBox"]);
}
//End ImagePopup

//Start LoadingPopup
function LoadingPopup(param) {
	this.base = new Popup(param);
	Suryani.extend(this, this.base);
	this.initContent();
}
LoadingPopup.prototype.initContent = function () {
	this.element["popupSpan"].setAttribute("class", "loadingHopup");
	this.element["popupSpan"].setAttribute("className", "loadingHopup");
	this.element["contentDiv"].innerHTML = "<div class='loadingTitle'>" + this.config["content"] + "</div><div class='loadingBar'></div>";
}
LoadingPopup.prototype.bindContentEvents = function () { }
LoadingPopup.prototype.buildContent = function () { }
//End LoadingPopup


//Start of open popup function
function PopupWindow()
{
    var popupPara={width:null,height:null,top:null,left:null,title:'Popup Test',content:'This is a Popup demo.',showMask:true,language:'en-us',moveable:true,closeCallBack:function(){alert("close");}};
    var popup = new Popup(popupPara);
    popup.show();
}
function TipPopupWindow(width,height,title,content,showMask){
    var tipPopupPara={autoClose:5000,width:width,height:height,top:null,left:null,title:title,content:content,showMask:showMask,language:'en-us',closeCallBack:null};
    var tipPopup = new TipPopup(tipPopupPara);
    tipPopup.show();
}
function AlertPopupWindow(width,height,title,content,showMask){
    var alertPopupPara={width:width,height:height,top:null,left:null,title:title,content:content,showMask:showMask,language:'en-us',closeCallBack:null};
    var alertPopup = new AlertPopup(alertPopupPara);
    alertPopup.addCallBack("ok",function(){alert("OK");});
    alertPopup.show();
}
function ConfirmPopupWindow(){
    var confirmPopupPara={width:430,height:145,top:null,left:null,title:'',content:'Are you sure you want to REMOVE this item?',showMask:true,language:'en-us',closeCallBack:null};
    var confirmPopup = new ConfirmPopup(confirmPopupPara);
    confirmPopup.addCallBack("ok",function(){alert("OK");});
    confirmPopup.addCallBack("cancel",function(){alert("cancel");});
    confirmPopup.show();
}
function PromptPopupWindow(){
    var promptPopupPara={width:null,height:null,top:null,left:null,title:'Prompt Test',content:'This is a PromptPopup demo.',showMask:true,language:'en-us',closeCallBack:null};
    var promptPopup = new PromptPopup(promptPopupPara);
    promptPopup.addCallBack("ok",function(){alert(promptPopup.input);});
    promptPopup.show();
}
var htmlPopup;
function HtmlPopupWindow(){
    var htmlPopupPara={width:null,height:null,top:null,left:null,title:'Html Test',content:'<div style="color:#999999">This is a HtmlPopup demo.<div>',showMask:true,language:'en-us',closeCallBack:null};
    var htmlPopup = new HtmlPopup(htmlPopupPara);
    htmlPopup.show();
}
var urlPopup;
function UrlPopupWindow(width,url,showMask){
    var urlPopupPara={width:width,height:null,top:null,left:null,title:'',content:url,showMask:showMask,language:'en-us',closeCallBack:null};
    urlPopup = new UrlPopup(urlPopupPara);
    urlPopup.show();
}
var imagePopup;
function ImagePopupWindow(sWidth, sHeight, sTop, sLeft, sTitle, sUrl, showMask){
    var imagePopupPara={width:sWidth,height:sHeight,top:sTop,left:sLeft,title:sTitle,content:sUrl,showMask:showMask,language:'en-us',closeCallBack:null};
    imagePopup = new ImagePopup(imagePopupPara);
    imagePopup.show();
}
var urlNoMarginPopup;
function noMarginPopupWindow(width,url,showMask,closeCallback){
    var urlPopupPara={width:width,height:null,top:null,left:null,title:'',content:url,showMask:showMask,language:'en-us',closeCallBack:closeCallback};
    urlNoMarginPopup = new UrlPopup(urlPopupPara);
	urlNoMarginPopup.size.width = width - 8;
    urlNoMarginPopup.show();
}
function reopenNoMarginPopup(width,url,showMask){
	urlNoMarginPopup.close();
    noMarginPopupWindow(width,url,showMask);
}
var noMarginSpecialClosePopup;
function noMarginSpecialClosePopupWindow(width, url, showMask, closeCallback) {
    var urlPopupPara = { width: width, height: null, top: null, left: null, title: '', content: url, showMask: showMask, language: 'en-us', closeCallBack: closeCallback };
    noMarginSpecialClosePopup = new UrlPopup(urlPopupPara);
    noMarginSpecialClosePopup.size.width = width - 8;
    noMarginSpecialClosePopup.show();
    noMarginSpecialClosePopup.element["popupDiv"].setAttribute("class", "hopupSpecialClose");
    noMarginSpecialClosePopup.element["popupDiv"].setAttribute("className", "hopupSpecialClose");
}

var urlSpecialTitlePopup;
function noBorderPopupWindow(width, titleContent, url, showMask, closeCallback) {
    var urlPopupPara = { width: width, height: null, top: null, left: null, title: titleContent, content: url, showMask: showMask, language: 'en-us', closeCallBack: closeCallback };
    urlSpecialTitlePopup = new UrlPopup(urlPopupPara);
    urlSpecialTitlePopup.size.width = width - 8;
    urlSpecialTitlePopup.show();
    urlSpecialTitlePopup.element["popupDiv"].setAttribute("class", "hopupWithSpecialTitle");
    urlSpecialTitlePopup.element["popupDiv"].setAttribute("className", "hopupWithSpecialTitle");
    urlSpecialTitlePopup.element.headerDiv.style.width = parseInt(width + 1) + "px";
}

var loadingPopup;
function loadingPopupWindow(sContent, sShowMask, sTop) {
	var loadingPopupPara = { width: 456, height: 300, top: sTop, left: null, title: '', content: sContent, showMask: sShowMask, language: 'en-us', closeCallBack: null };
	loadingPopup = new LoadingPopup(loadingPopupPara);
	loadingPopup.show();
}
function preloadLoadingImages() {
	$("body").append("<div class='preloadImagesBox'><div class='loadingHopup'><div class='loadingBar'></div></div></div>");
}
//End of open popup function

function resetUrlNoMarginWidth(width)
{
    urlNoMarginPopup.size.width = width - 8;
    urlNoMarginPopup.element["url"].setAttribute("width", width + "px");
	urlNoMarginPopup.setPosition();
}

function resetUrlNoMarginHeight(height)
{
	urlNoMarginPopup.element["url"].setAttribute("height",height+"px");
	urlNoMarginPopup.size.height= height;
	urlNoMarginPopup.setPosition();
}

function resetUrlNoMarginSize(width, height) {
    urlNoMarginPopup.size.width = width - 8;
    urlNoMarginPopup.element["url"].setAttribute("width", width + "px");
    urlNoMarginPopup.element["url"].setAttribute("height", height + "px");
    urlNoMarginPopup.setPosition();
}

//Start of small tip window function
function showClickWindow(obj){
    var showWindow = $(obj).parent().find(".rolloverWindow");
    var objShow = (showWindow.css("visibility")=="visible")?true:false;
    $(".rolloverWindow").css("visibility","hidden");
    $(".clickWindow").find(".rolloverWindow").parent().css("z-index","0");
    if (!objShow){
        showWindow.css("visibility","visible");
        $(obj).parent().css("z-index", "1");
    }
}
function closeClickWindow(obj){
    var showWindow = $(obj).parent().parent().find(".rolloverWindow");
    showWindow.css("visibility","hidden");
}
function showClickWindowAutoPosition(obj,outBoxObj,align){
    if ($(obj).parents(outBoxObj).length>=1){
        if (align == "all" || align == "vertical")
            setVerticalPosition(obj,outBoxObj);
        if (align == "all" || align == "horizontal")
            setHorizontalPosition(obj,outBoxObj);
    }
    showClickWindow(obj);
}
function setVerticalPosition(obj,outBoxObj){
    var showWindow = $(obj).parent().find(".rolloverWindow");
    showWindow.css("display","inline-block");
    
    var outBoxBottom = $(outBoxObj).offset().top + $(outBoxObj).height();
    var showWindowBottom = $(obj).offset().top + $(obj).height() + showWindow.height();// the bottom of roll over window
    var restWindowTop = $(obj).offset().top - $(outBoxObj).offset().top - showWindow.height();

    showWindow.find(".closeText").remove();
    if (showWindowBottom <= outBoxBottom || restWindowTop < 0){
        showWindow.find(".top").after("<span class='closeText' onclick='closeClickWindow(this);'> Close <b>x</b></span>");
        showWindow.removeClass("rolloverWindowUp");
    }
    else{
        showWindow.find(".bottom").before("<span class='closeText' onclick='closeClickWindow(this);'> Close <b>x</b></span>");
        showWindow.addClass("rolloverWindowUp");
    }
}
function setHorizontalPosition(obj,outBoxObj){
    var showWindow = $(obj).parent().find(".rolloverWindow");
    showWindow.css("display","inline-block");

    var outBoxRight = $(outBoxObj).offset().left + $(outBoxObj).width() - 20;
    var showWindowRight = $(showWindow).offset().left + $(showWindow).width() + 5;// the right position of roll over window
    
    if (showWindow.offset().left < $(outBoxObj).offset().left){
        showWindow.css("right",(eval(showWindow.css("right").replace("px","")) + showWindow.offset().left - $(outBoxObj).offset().left) + "px");
        setWindowArrow(showWindow);
    }
    else if (showWindowRight > outBoxRight){
        showWindow.css("right",(eval(showWindow.css("right").replace("px","")) + showWindowRight - outBoxRight - 10 ) + "px");
        setWindowArrow(showWindow);
    }
}
function setWindowArrow(obj){
        obj.find(".bottom").attr("class","bottom bottomCenter");
        obj.find(".top").attr("class","top topCenter"); 
}

