function Pop(){

}
Pop.prototype={
	callParam: null,
	isIe: (document.all)?true:false,
	type: 1,
	content: "",
	event: null,
	title: "",
	left: -1,
	top: -1,
	width: 500,
	height: "auto",
	background: false,
	ifdrag: true,
	mode: "iframe",
	onSuccess: function(){},
//set the select tag hidden
setSelectState: function(state) 
{ 
	 var objl=document.getElementsByTagName('select'); 
	 for(var i=0;i<objl.length;i++) 
	 { 
	 objl[i].style.visibility=state; 
	 } 
},
mousePosition: function(ev) 
	 { 
	 if(ev.pageX || ev.pageY) 
	 { 
	 return {x:ev.pageX, y:ev.pageY}; 
	 } 
	 return { 
	 x:(ev.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft)),y:(ev.clientY + (document.documentElement.scrollTop || document.body.scrollTop)) 
	 }; 
 },
//pop main body
showMessageBox: function(wTitle,content,pos,leftPos,topPos,wWidth,wHeight,background) 
{ 
	 var left;
	 var top;
	 var styleStr;
	 this.closeWindow(); 
	 //var bWidth=parseInt(document.body.scrollWidth); 
	 //var bHeight=parseInt(document.body.offsetHeight);
	 
		 if(this.isIe){ 
		 this.setSelectState('hidden');} 
		 var back=document.createElement("div"); 
		 back.id="back";
		 var sWidth=parseInt(document.documentElement.scrollWidth); 
 		 var sHeight=parseInt(document.documentElement.scrollHeight);
		 if(background==true){
		 	styleStr="top:0px;left:0px;position:absolute;background:#000000;width:"+sWidth+"px;height:"+sHeight+"px;";
		 	styleStr+=(this.isIe)?"filter:alpha(opacity=50);":"opacity:0.5;"; 
		 	back.style.cssText=styleStr; 
		 	document.body.appendChild(back);
	 	 	this.showBackground(back,70);
		 }
		 else{
		 	styleStr="top:0px;left:0px;position:absolute;background:#FFFFFF;width:"+sWidth+"px;height:"+sHeight+"px;";
		 	styleStr+=(this.isIe)?"filter:alpha(opacity=0);":"opacity:0;";
		 	back.style.cssText=styleStr; 
		 	document.body.appendChild(back) 
		 }	
	if(leftPos!=-1)
		left=leftPos;
	else if(pos!=null)
		left=((pos.x+20+wWidth)>document.body.clientWidth)?(document.body.clientWidth-wWidth-50):(pos.x+20);
	else 
		left=(document.documentElement.clientWidth-wWidth)/2 + (document.documentElement.scrollLeft || document.body.scrollLeft);
	
	if(topPos!=-1)
		top=topPos;
	else if(pos!=null)
		top=pos.y+30;
	else 
   		//if top is not assigned,the messagewindow will be popped up in the middle of browser's window;
		top= (document.documentElement.clientHeight-wHeight)/2 + (document.documentElement.scrollTop || document.body.scrollTop);

	if(left<0)
		left=0;
	if(top<0)
		top=0;

	 var diagBox=document.createElement("div");
	 diagBox.id="diagBox";
	 diagBox.className="diagBox";
	 styleStr="border:5px solid #557597;background:#ffffff;z-index:2;padding:5px;left:50%;top:50%;margin-left:-330px!important;margin-top:-240px!important;margin-top:"+top+";position:fixed!important;position:absolute;" 
	 diagBox.style.cssText=styleStr; 

	 var mesW=document.createElement("div"); 
	 mesW.id="mesWindow"; 
	 mesW.className="mesWindow";
	 if(wHeight=="auto")
	 	styleStr="background:#ffffff;padding-bottom:10px;z-index:100;width:"+wWidth+"px;height:auto;clear:both;overflow:auto;"; 
	 else	 
	 	styleStr="background:#ffffff;padding-bottom:10px;z-index:100;width:"+wWidth+"px;height:"+wHeight+"px;"; 
	 mesW.style.cssText=styleStr;
	 mesW.innerHTML="";
	 mesW.innerHTML+="<div class='mesWindowTop' style='border-bottom:#fff 1px solid;height:20px;padding:1px;font-weight:bold;text-align:left;font-size:14px;background-color:#fff;'><table width='100%' height='100%'><tr><td id='mesWindowTitle'  style='padding:5px;'>"+wTitle+"</td><td align='right' width='20px' ><input type='image' src='templates/WebPromotionerIndia/images/close.png' onclick='pop.closeWindow();clearTimeout(timeout);' title='close' class='close' style='cursor:pointer;'/></td></tr></table></div>";
	 mesW.innerHTML+="<div class='mesWindowContent' id='mesWindowContent' style='height:auto;padding:10px;'></div>";
	
	 diagBox.appendChild(mesW);
	 document.body.appendChild(diagBox);

	 
},
showBackground: function(obj,endInt) 
{ 
	 if(this.isIe) 
	{
	 obj.filters.alpha.opacity+=1; 
	 if(obj.filters.alpha.opacity<endInt) 
	 { 
	 setTimeout(function(){pop.showBackground(obj,endInt)},10); 
	 } 
	 }else{ 
	 var al=parseFloat(obj.style.opacity);al+=0.01; 
	 obj.style.opacity=al; 
	 if(al<(endInt/100)) 
	 {setTimeout(function(){pop.showBackground(obj,endInt)},10);} 
	 } 
}, 
//close the messwindow 
closeWindow: function() 
{ 
	 if(document.getElementById('back')!=null) 
	 { 
	 document.getElementById('back').parentNode.removeChild(document.getElementById('back')); 
	 } 
	 if(document.getElementById('diagBox')!=null) 
	 {
		document.getElementById('diagBox').parentNode.removeChild(document.getElementById('diagBox')); 
	 } 	 
	 if(this.isIe){ 
	 this.setSelectState('');
	} 
},
close: function(param)
{
	this.callParam=param;
	this.closeWindow();
},

popWindow: function(ev,title,left,top,width,height,src,background,ifdrag) 
{ 
	 if(ev!=null)
	 	var objPos = this.mousePosition(ev);
	// messContent = "<iframe id='popiframe' name='popiframe' align='no' style='border:none' scrolling='no' frameborder='0' width='"+width+"' height='"+height+"'></iframe>";
		
	 this.showMessageBox(title,src,objPos,left,top,width,height,background);
},




getAjax: function(){
	try{
		return new ActiveXObject('Msxml2.XMLHTTP');
	}catch(e){
		try{
			return new ActiveXObject('Microsoft.XMLHTTP');
		}catch(e){
			try{
				return new XMLHttpRequest();
			}catch(e){}
		}
	}
},

init: function(popObj){
	this.event=popObj.event?popObj.event:null;
	this.title=popObj.title?popObj.title:"";
	this.left=popObj.left?popObj.left:-1;
	this.top=popObj.top?popObj.top:-1;
	this.width=popObj.width?popObj.width:500;
	this.height=popObj.height?popObj.height:"auto";
	this.background=(popObj.background==undefined)?false:popObj.background;
	this.ifdrag=(popObj.ifdrag==undefined)?true:popObj.ifdrag;
	this.mode = popObj.mode?popObj.mode:"iframe";
	this.onSuccess = popObj.onSuccess?popObj.onSuccess:function(){},
	this.content="";
	this.show();


	switch(popObj.type){
		case 1:
				if(popObj.mode!="div"){
					document.getElementById('mesWindowContent').innerHTML= "<iframe id='popiframe' src="+popObj.url+" align='no' style='border:none' scrolling='no' frameborder='0' width='"+(popObj.width-20)+"' height='"+(popObj.height-53)+"'></iframe>";
					/*判断ie6或ie7的版本 by yuanqian 2008-10-25*/
					var browser=navigator.appName 
					var b_version=navigator.appVersion 
					var version=b_version.split(";"); 
					var trim_Version=version[1].replace(/[ ]/g,""); 
					var ieType=0;
					if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE6.0") 
					{ 
						ieType=6;
					} 
					else if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE7.0"){
						ieType=7;
					}
					if(ieType==6){
						window.frames['popiframe'].location.reload();
					}
					break;
				}
				var response=null;
				var xmlHttp = this.getAjax();
				xmlHttp.onreadystatechange=function(){				
					if(xmlHttp.readyState==4){
						if(xmlHttp.status==200){
							document.getElementById('mesWindowContent').innerHTML=xmlHttp.responseText;
							pop.onSuccess();
						}
						else{
							alert(xmlHttp.status);
						}
					}
					else if (xmlHttp.readyState==3)
					{
						//show the waiting... information
					}

				}
				xmlHttp.open("get",popObj.url);
				xmlHttp.send(null);
				break;
		case 2:
				document.getElementById('mesWindowContent').innerHTML=popObj.src;
				break;
		case 3:
				document.getElementById('mesWindowContent').innerHTML="<table width='100%' border='0' cellspacing='2' cellpadding='0'><tr><td>"+popObj.src+"</td></tr><tr><td><div align='center' style='padding-top:10px; padding-bottom:20px; '><table width='100%' border='0' align='center'  cellspacing='7' cellpadding='0'> <tr><td><div align='right'><input class='buttonM_1 font14 pink weight700' type='button' value='确 定' name='imageField2' id='imageField2' onfocus='this.blur()' onclick='"+popObj.callback+"("+popObj.param+")"+"' /></div></td><td><div align='left'><input class='buttonM_1 font14' type='button' name='imageField' id='imageField' value='取 消' onfocus='this.blur()' onclick='pop.closeWindow()' /></div></td></tr></table></div></td></tr></table>";
				this.callback = popObj.callback;
				break;
		default:
				alert("the type must be [1,2,3]");
				break;

}
var sWidth = this.width;
var sHeight = parseInt(document.getElementById("diagBox").offsetHeight);
//this.showShadow(sWidth,sHeight);

},

show: function(){
	this.popWindow(this.event,this.title,this.left,this.top,this.width,this.height,this.content,this.background,this.ifdrag);	
}
}

var pop = new Pop();