function XPos(e) {
	posx=0;posy=0;
	var ev=(!e)?window.event:e;//IE:Moz
	if (ev.pageX){//Moz
		posx=ev.pageX+window.pageXOffset;
	}
	else if(ev.clientX){//IE
		posx=ev.clientX+document.body.scrollLeft;
	}
	return posx;
}
function PosY(e) {
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageY) 	{
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	return posy;
}
function show_coordsX(event)	{
	x=window.event.clientX;
	return x;
}
function show_coordsY(event)	{
	y=window.event.clientY;
	return y;
}
function windowHeight()	{
	Height=document.body.clientHeight+document.body.scrollTop;;
	return Height;
}
function windowWidth()	{

	Width=document.body.clientWidth+document.body.scrollLeft;
	return Width;
}
function StandardPopUp(child,parent,left,top,width,height){
	 x=left;
	 y=top;
	 var childdiv=document.createElement('DIV');
	 var parentdiv=document.createElement('DIV');
	 parentdiv.setAttribute('id',parent);
	 parentdiv.setAttribute('className','popupdivParent'); 
	 parentdiv.className='popupdivParent'; 
	 parentdiv.style.left = 0 + "px"; 
	 parentdiv.style.top = 0 + "px"; 
	 parentdiv.style.width = windowWidth() + "px"; 
	 parentdiv.style.height = windowHeight() + "px"; 
	 parentdiv.style.MozOpacity = 0.6;
	 
     childdiv.setAttribute('id',child);
	 childdiv.setAttribute('className','popupdiv'); 
	 childdiv.className='popupdiv'; 
	 childdiv.style.left = x + "px"; 
	 childdiv.style.top = y + "px"; 
	 childdiv.style.width = width + "px"; 
	 childdiv.style.height = height + "px"; 
	 tmpid='tmp'+child;
     childdiv.innerHTML='<div style="width:'+width+'px;height:auto;text-align:right;"><img src="Images/CloseIcon.png" onClick=hidePopupFrame(\''+child+'\',\''+parent+'\') /></div><div id=\''+tmpid+'\' style="width:100%;height:auto;float:right;"></div>';
	 
	 document.getElementsByTagName('body')[0].appendChild(parentdiv);
     document.getElementsByTagName('body')[0].appendChild(childdiv);
}

function displayPopupNegativeDiv(child,parent,left,top,width,height){
	 x=XPos();
	 x=x-width;
	 y=PosY();
	 var childdiv=document.createElement('DIV');
	 var parentdiv=document.createElement('DIV');
	 parentdiv.setAttribute('id',parent);
	 parentdiv.setAttribute('className','popupdivParent'); 
	 parentdiv.className='popupdivParent'; 
	 parentdiv.style.left = 0 + "px"; 
	 parentdiv.style.top = 0 + "px"; 
	 parentdiv.style.width = width + "px"; 
	 parentdiv.style.height = height + "px"; 
	 parentdiv.style.MozOpacity = 0.6;
	 
     childdiv.setAttribute('id',child);
	 childdiv.setAttribute('className','popupdiv'); 
	 childdiv.className='popupdiv'; 
	 childdiv.style.left = x + "px"; 
	 childdiv.style.top = y + "px"; 
	 childdiv.style.width = width + "px"; 
	 childdiv.style.height = height + "px"; 
     //childdiv.appendChild(document.createTextNode('dfssd'));
	 //div.appendChild(childdiv);
	 document.getElementsByTagName('body')[0].appendChild(parentdiv);
     document.getElementsByTagName('body')[0].appendChild(childdiv);
}
function PopUpFrame(child,parent,left,top,width,height,value,photoframe,folder){
	 //x=XPos();
	 //x=x-width;
	 //y=PosY();
	 x=left;
	 y=top;
	 var childdiv=document.createElement('DIV');
	 var parentdiv=document.createElement('DIV');
	 var iframe=document.createElement('IFRAME');
	 parentdiv.setAttribute('id',parent);
	 parentdiv.setAttribute('className','popupdivParent'); 
	 parentdiv.className='popupdivParent'; 
	 parentdiv.style.left = 0 + "px"; 
	 parentdiv.style.top = 0 + "px"; 
	 parentdiv.style.width = windowWidth() + "px"; 
	 parentdiv.style.height = windowHeight() + "px"; 
	 parentdiv.style.MozOpacity = 0.6;
	 
     childdiv.setAttribute('id',child);
	 childdiv.setAttribute('className','popupdiv'); 
	 childdiv.className='popupdiv'; 
	 childdiv.style.left = x - 200 + "px"; 
	 childdiv.style.top = y + "px"; 
	 childdiv.style.width = width + "px"; 
	 childdiv.style.height = height + "px"; 
	 childdiv.innerHTML='<div style="width:300px;height:auto;text-align:right;"><img src="Images/CloseIcon.png" onClick=hidePopupFrame(\''+child+'\',\''+parent+'\') /></div><iframe name="forUpload" id="forUpload"  src="test.php?child='+child+'&parent='+parent+'&value='+value+'&photoframe='+photoframe+'&folder='+folder+'"  ></iframe>';
	 
	 document.getElementsByTagName('body')[0].appendChild(parentdiv);
     document.getElementsByTagName('body')[0].appendChild(childdiv);
}
function PopUpFrameFlash(child,parent,left,top,width,height,value,photoframe,folder){
	 //x=XPos();
	 //x=x-width;
	 //y=PosY();
	 x=left;
	 y=top;
	 var childdiv=document.createElement('DIV');
	 var parentdiv=document.createElement('DIV');
	 var iframe=document.createElement('IFRAME');
	 parentdiv.setAttribute('id',parent);
	 parentdiv.setAttribute('className','popupdivParent'); 
	 parentdiv.className='popupdivParent'; 
	 parentdiv.style.left = 0 + "px"; 
	 parentdiv.style.top = 0 + "px"; 
	 parentdiv.style.width = windowWidth() + "px"; 
	 parentdiv.style.height = windowHeight() + "px"; 
	 parentdiv.style.MozOpacity = 0.6;
	 
     childdiv.setAttribute('id',child);
	 childdiv.setAttribute('className','popupdiv'); 
	 childdiv.className='popupdiv'; 
	 childdiv.style.left = x - 200 + "px"; 
	 childdiv.style.top = y + "px"; 
	 childdiv.style.width = width + "px"; 
	 childdiv.style.height = height + "px"; 
	 childdiv.innerHTML='<div style="width:300px;height:auto;text-align:right;float:right;"><img src="Images/CloseIcon.png" onClick=hidePopupFrame(\''+child+'\',\''+parent+'\') /></div><iframe name="forUpload" id="forUpload"  src="UploadFlash.php?child='+child+'&parent='+parent+'&value='+value+'&photoframe='+photoframe+'&folder='+folder+'"  ></iframe>';
	 
	 document.getElementsByTagName('body')[0].appendChild(parentdiv);
     document.getElementsByTagName('body')[0].appendChild(childdiv);
}

function PopUpMultiFrame(child,parent,left,top,width,height,value,photoframe,folder,addImage){
	 x=XPos();
	 x=x-width;
	 y=PosY();
	 var childdiv=document.createElement('DIV');
	 var parentdiv=document.createElement('DIV');
	 var iframe=document.createElement('IFRAME');
	 parentdiv.setAttribute('id',parent);
	 parentdiv.setAttribute('className','popupdivParent'); 
	 parentdiv.className='popupdivParent'; 
	 parentdiv.style.left = 0 + "px"; 
	 parentdiv.style.top = 0 + "px"; 
	 parentdiv.style.width = windowWidth() + "px"; 
	 parentdiv.style.height = windowHeight() + "px"; 
	 parentdiv.style.MozOpacity = 0.6;
	 
     childdiv.setAttribute('id',child);
	 childdiv.setAttribute('className','popupdiv'); 
	 childdiv.className='popupdiv'; 
	 childdiv.style.left = x - 200 + "px"; 
	 childdiv.style.top = y + "px"; 
	 childdiv.style.width = width + "px"; 
	 childdiv.style.height = height + "px"; 
	 childdiv.innerHTML='<div style="width:300px;height:auto;text-align:right;"><img src="Images/CloseIcon.png" onClick=hidePopupFrame(\''+child+'\',\''+parent+'\') /></div><iframe name="forUpload" id="forUpload"  src="UploadProcess.php?child='+child+'&parent='+parent+'&value='+value+'&photoframe='+photoframe+'&addImage='+addImage+'&folder='+folder+'"  ></iframe>';
	 
	 document.getElementsByTagName('body')[0].appendChild(parentdiv);
     document.getElementsByTagName('body')[0].appendChild(childdiv);/**/
}
function PopUpTextFrame(child,parent,left,top,width,height,value,photoframe,folder,addImage){
	 x=XPos();
	 x=x-width;
	 y=PosY();
	 var childdiv=document.createElement('DIV');
	 var parentdiv=document.createElement('DIV');
	 var iframe=document.createElement('IFRAME');
	 parentdiv.setAttribute('id',parent);
	 parentdiv.setAttribute('className','popupdivParent'); 
	 parentdiv.className='popupdivParent'; 
	 parentdiv.style.left = 0 + "px"; 
	 parentdiv.style.top = 0 + "px"; 
	 parentdiv.style.width = windowWidth() + "px"; 
	 parentdiv.style.height = windowHeight() + "px"; 
	 parentdiv.style.MozOpacity = 0.6;
	 
     childdiv.setAttribute('id',child);
	 childdiv.setAttribute('className','popupdiv'); 
	 childdiv.className='popupdiv'; 
	 childdiv.style.left = x - 200 + "px"; 
	 childdiv.style.top = y + "px"; 
	 childdiv.style.width = width + "px"; 
	 childdiv.style.height = height + "px"; 
	 childdiv.innerHTML='<div style="width:300px;height:auto;text-align:right;"><img src="Images/CloseIcon.png" onClick=hidePopupFrame(\''+child+'\',\''+parent+'\') /></div><iframe name="forUpload" id="forUpload"  src="UploadText.php?child='+child+'&parent='+parent+'&value='+value+'&photoframe='+photoframe+'&addImage='+addImage+'&folder='+folder+'"  ></iframe>';
	 
	 document.getElementsByTagName('body')[0].appendChild(parentdiv);
     document.getElementsByTagName('body')[0].appendChild(childdiv);/**/
}

function hidePopupFrame(child,parent){
   var childdiv=document.getElementById(child);
   var parentdiv=document.getElementById(parent);
   if(!childdiv){ return};
   if(!parentdiv){return};
  
   childdiv.parentNode.removeChild(childdiv); 
   parentdiv.parentNode.removeChild(parentdiv); 
} 

function hidePopupFrameParent(child,parent){
   var childdiv=parent.document.getElementById(child);
   var parentdiv=parent.document.getElementById(parent);
   if(!childdiv){ return};
   if(!parentdiv){return};
  
   childdiv.parentNode.removeChild(childdiv); 
   parentdiv.parentNode.removeChild(parentdiv); 
} 

function hidePopupFrameParent(child,parent){
   var childdiv=parent.document.getElementById(child);
   var parentdiv=parent.document.getElementById(parent);
   if(!childdiv){ return};
   if(!parentdiv){return};
   childdiv.parentNode.removeChild(childdiv); 
   parentdiv.parentNode.removeChild(parentdiv); 
}
function submitUpload(child,parent)	{
	if(document.frmUpload.fupload.value != '') {
		return true;
	} else {
		alert('Please Choose picture');
		return false;
	}
}
function displayPopupDiv(child,parent,text,left,top){
	 var div=document.getElementById(parent);
     var childdiv=document.createElement('div');
     childdiv.setAttribute('id',child);
	 childdiv.setAttribute('zIndex',ZINDEX);
	 parent.appendChild(childdiv);
}
function hidePopupDiv(child){
   var div=document.getElementById(child);
   if(!div){return};
   div.parentNode.removeChild(div); 
} 

function minimize(child_id,parent_id,width,left,top){
  document.getElementById(parent_id).style.visibility="hidden";
  PopUp_generate_minimize(child_id,parent_id,width,left,top) 
} 
function maximize(child_id,parent_id)	{
  document.getElementById(parent_id.id).style.visibility="visible";
  child_id.parentNode.removeChild(child_id); 
  //document.getElementById(id.id).style.visibility="hidden";
}
function resize(id)	{
	alert(id);
	document.getElementById(id).style.height="800px";
	//document.getElementById(id).style.background-position = "-200px -500px";
}

function set_transparency(layer)
{
	document.getElementById(layer).ondeactivate=function(){this.style.filter ='progid:DXImageTransform.Microsoft.Alpha(opacity=40)';}
	document.getElementById(layer).onactivate=function(){this.style.filter ='progid:DXImageTransform.Microsoft.Alpha(opacity=100)';}
}
/***********************************************************************************************/
isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;
isHot=false;
var ZINDEX=1;
function ddInit(e){
  topDog=isIE ? "BODY" : "HTML";
  eve=event.srcElement;
	while(!eve || eve.tagName!='DIV'){
		  if(eve.parentElement)
			eve=eve.parentElement;
		  else
			break;	
	  } 
  whichDog= eve;  
  hotDog=isIE ? event.srcElement : e.target;
  if(hotDog.parentElement && document.getElementById('LayerTitleBar'))
	while (hotDog.id!="LayerTitleBar" && hotDog.tagName!=topDog){
			hotDog=(isIE) ? (hotDog.parentElement) : (hotDog.parentNode);
				
	}  
  if (hotDog.id=="LayerTitleBar"){
    offsetx=isIE ? event.clientX : e.clientX;
    offsety=isIE ? event.clientY : e.clientY;
    nowX=parseInt(whichDog.style.left);
    nowY=parseInt(whichDog.style.top);
    ddEnabled=true;
    document.onmousemove=dd;
  }
}

function dd(e){	
  if (!ddEnabled) return;
  whichDog.style.left=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx; 
  whichDog.style.top=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
  return false;  
}

function ddN4(whatDog){
  if (!isN4) return;
  N4=eval(whatDog);
  N4.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  N4.onmousedown=function(e){
    N4.captureEvents(Event.MOUSEMOVE);
    N4x=e.x;
    N4y=e.y;
  }
  N4.onmousemove=function(e){
    if (isHot){
      N4.moveBy(e.x-N4x,e.y-N4y);
      return false;
    }
  }
  N4.onmouseup=function(){
    N4.releaseEvents(Event.MOUSEMOVE);
  }
}

function hideMe(){
  if (isIE||isNN) whichDog.style.visibility="hidden";
  else if (isN4) document.theLayer.visibility="hide";
}

function showMe(){
  if (isIE||isNN) whichDog.style.visibility="visible";
  else if (isN4) document.theLayer.visibility="show";
}
document.onmousedown=ddInit;
//document.onmousedown=Function("(event.srcElement.id=='titleBar')?(ddInit()):(ddEnabled=false);");
document.onmouseup=Function("ddEnabled=false");
