var ieB = (document.all) ? 1 : 0;

siteUrl = "http://tcyonline.com";

var dragapproved=false
var minrestore=0
var initialwidth,initialheight
var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all

function iecompattest(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function drag_drop(e){
	if (ie5&&dragapproved&&event.button==1){
		document.getElementById("dwindow").style.left=tempx+event.clientX-offsetx+"px"
		document.getElementById("dwindow").style.top=tempy+event.clientY-offsety+"px"
	}else if (ns6&&dragapproved){
		document.getElementById("dwindow").style.left=tempx+e.clientX-offsetx+"px"
		document.getElementById("dwindow").style.top=tempy+e.clientY-offsety+"px"
	}
}

function initializedrag(e){
	offsetx=ie5? event.clientX : e.clientX
	offsety=ie5? event.clientY : e.clientY
	document.getElementById("dwindowcontent").style.display="none" //extra
	tempx=parseInt(document.getElementById("dwindow").style.left)
	tempy=parseInt(document.getElementById("dwindow").style.top)
	dragapproved=true
	document.getElementById("dwindow").onmousemove=drag_drop
}


function loadwindow(url, wid, he, headText){
	if(typeof headText == 'undefined') var headText = 'Select any categories and sub-categories.';
	// INVITE MAIN DIV
	var already = document.body.getElementsByTagName("div")['dwindow1'];
	if(typeof already=='undefined'){
		var divTag = document.createElement("div");
		divTag.id = "divInviteFrnd";
		var divData = '<div class="dwindowCls" style="height:'+he+'px;width:'+wid+'px;" align="center" id="dwindow1">'
		divData += '<div class="Create_headingMain">'
		divData += '<div class="Create_heading"><h1>'+headText+'</h1></div>'
		divData += '<div class="namechg"><a onclick="closeInviteFrndDiv();">Close [X]</a></div>'
		divData += '</div>'
		divData += '<div align="center" id="dwindowcontent">'
		divData += '<iframe id="cframe1" src=""  frameborder="0" style="height:'+he+'px;width:'+wid+'px;background-color:#FFFFFF; "></iframe>'
		divData += '</div>'
		divData += '</div>'
		divTag.innerHTML = divData
		document.body.appendChild(divTag);
		// INVITE MAIN DIV
		// BACK BLACK DIV
		var divBacTag = document.createElement("div");
		divBacTag.id = "dullDiv";
		document.body.appendChild(divBacTag);
		// BACK BLACK DIV
	}
	
	document.getElementById('dwindow1').style.display = 'block'
	document.getElementById('dullDiv').style.display = 'block'
	if(ieB == 1){
		document.getElementById('dullDiv').style.opacity = 2;
		document.getElementById('dullDiv').style.filter = 'alpha(opacity=' + 20 + ')';
	}else document.getElementById('dullDiv').style.opacity = '0.2'
	var frame = document.getElementById("cframe1");	
	if(frame.contentWindow.document.body)
		frame.contentWindow.document.body.innerHTML= '<div style="font-family:Arial, Helvetica, sans-serif; font-size:13px;color:#114eab;font-weight: bold;line-height:20px; padding-top:80px" style="float:center"><center><br>Please Wait...</center></div>';
	frame.src = url
	setDivPosition()
}
function setDivPosition(){
	var inviterFrndDiv = document.getElementById('dwindow1')
	
	var scrollTop = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop
	var myHeight = window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : (document.body.clientHeight ? document.body.clientHeight : 0))

	var clientWid = document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
	inviterFrndDiv.style.left = ((clientWid-inviterFrndDiv.offsetWidth)/2)+'px';	
	
	//if(ieB == 1)
		//inviterFrndDiv.style.top = scrollTop + ((parseInt(myHeight) - inviterFrndDiv.offsetHeight)/2)+'px';
	//else
		inviterFrndDiv.style.top = ((parseInt(myHeight) - inviterFrndDiv.offsetHeight)/2)+'px';
}
function closeInviteFrndDiv(){
	document.getElementById('dwindow1').style.display = 'none'
	document.getElementById('dullDiv').style.display = 'none'
}

/*
function loadwindow(url,width,height){
	var frame = document.getElementById("cframe");
	frame.contentWindow.document.body.innerHTML= '<div style="font-family:Arial, Helvetica, sans-serif; font-size:0.8em;color:#114eab;font-weight: bold;line-height:20px; padding-top:80px" style="float:center"><center>Please Wait....</center> </div>';	
	centerPopup();	
	loadPopup();
	if (!ie5&&!ns6)
		window.open(url,"","width=width,height=height,scrollbars=1")
	else{		
		document.getElementById("dwindow").style.display=''
		//document.getElementById("dwindow").style.left="15%"
		document.getElementById("dwindow").style.left=ns6? window.pageXOffset*1+80+"px" : iecompattest().scrollLeft*1+80+"px"
		document.getElementById("dwindow").align ='center'
		document.getElementById("dwindow").style.top=ns6? window.pageYOffset*1+80+"px" : iecompattest().scrollTop*1+80+"px"

		document.getElementById("dwindow").style.width=initialwidth=width+"px"		
		outerHeight = parseInt(height)+20;
		document.getElementById("dwindow").style.height=initialheight=outerHeight+"px"
		
		document.getElementById("cframe").style.display=''
		document.getElementById("cframe").style.width=initialwidth=width+"px"
		document.getElementById("cframe").style.height=initialheight=height+"px"
		document.getElementById("cframe").style.left="30px"
		document.getElementById("cframe").style.top=ns6? window.pageYOffset*1+30+"px" : iecompattest().scrollTop*1+30+"px"
		document.getElementById("cframe").src=url
	}
	centerAlignDiv("dwindow",width,height);
}
function centerPopup(){
	if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){
		var windowWidth=document.documentElement.clientWidth;var windowHeight=document.documentElement.clientHeight;
	}else if(document.body&&(document.body.clientWidth||document.body.clientHeight)){
		var windowWidth=document.body.clientWidth;var windowHeight=document.body.clientHeight;
	}
	var popupHeight=document.getElementById("dwindow").style.height;
	var popupWidth=document.getElementById("dwindow").style.width;
	document.getElementById("dwindow").style.position="absolute";
}
function centerAlignDiv(divId, wObj, HObj){
	if(ieB == 1){
		myHeight = document.documentElement.clientHeight; 
		myWidth = document.documentElement.clientWidth; 
		meOnLeft = parseInt(document.getElementById(divId).style.left);
		meOnTop = parseInt(document.getElementById(divId).style.top);
	}else{ 
		myHeight = window.innerHeight;
		myWidth = window.innerWidth;
		meOnTop = (myHeight-HObj)/2
		meOnLeft = (myWidth-wObj)/2	
	}
	FloatDiv(divId, meOnLeft,meOnTop).floatIt();
}
*/
function maximize(){
	if (minrestore==0){
		minrestore=1 //maximize window
		document.getElementById("maxname").setAttribute("src","/OpenInviter/images/restore.gif")
		document.getElementById("dwindow").style.width=ns6? window.innerWidth-20+"px" : iecompattest().clientWidth+"px"
		document.getElementById("dwindow").style.height=ns6? window.innerHeight-20+"px" : iecompattest().clientHeight+"px"
	}else{
		minrestore=0 //restore window
		document.getElementById("maxname").setAttribute("src","/OpenInviter/images/max.gif")
		document.getElementById("dwindow").style.width=initialwidth
		document.getElementById("dwindow").style.height=initialheight
	}	
	document.getElementById("dwindow").style.left=ns6? window.pageXOffset+"px" : iecompattest().scrollLeft+"px"
	document.getElementById("dwindow").style.top=ns6? window.pageYOffset+"px" : iecompattest().scrollTop+"px"
}
function closeit(){
			if(popupStatus==1){
				/*jQuery("#backgroundPopup").fadeOut("slow");jQuery("#dwindow").fadeOut("slow");popupStatus=0;*/
				document.getElementById("backgroundPopup").style.display='none';
				document.getElementById("dwindow").style.display='none';popupStatus=0;
			}
	}
function stopdrag(){
	dragapproved=false;
	document.getElementById("dwindow").onmousemove=null;
	document.getElementById("dwindowcontent").style.display="" //extra
}

var popupStatus = 0;
function loadPopup(){
		if(popupStatus==0){
			windowHeight= (typeof window.innerHeight != 'undefined' ? window.innerHeight : document.body.clientHeight);
			windowWidth= (typeof window.innerWidth != 'undefined' ? window.innerWidth : document.body.clientWidth);
			//document.getElementById("backgroundPopup").style.width = windowWidth-5+"px";
			//document.getElementById("backgroundPopup").style.height = windowHeight-5+"px";	/*jQuery("#backgroundPopup").css({"opacity":"0.7"});jQuery("#backgroundPopup").fadeIn("slow");jQuery("#dwindow").fadeIn("slow");popupStatus=1;*/
			document.getElementById("backgroundPopup").style.opacity="0.7";
			document.getElementById("backgroundPopup").style.display="block";
			document.getElementById("dwindow").style.display="block";popupStatus=1;
		}
}
	// End popup script




	// FLOAT DIV TO WINDOW MIDDLE 
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var d = document;
	function FloatDiv(id, sx, sy){
		var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		var px = document.layers ? "" : "px";
		window[id + "_obj"] = el;
		if(d.layers)el.style=el;
		el.cx = el.sx = sx;el.cy = el.sy = sy;
		el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
	
		el.floatIt=function(){
			var pX, pY;
			pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
			document.documentElement && document.documentElement.clientWidth ? 
			document.documentElement.clientWidth : document.body.clientWidth;
			pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
			document.documentElement.scrollTop : document.body.scrollTop;
			if(this.sy<0) 
			pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
			document.documentElement.clientHeight : document.body.clientHeight;
			this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
			this.sP(this.cx, this.cy);
			setTimeout(this.id + "_obj.floatIt()", 30);
		}
		return el;
	}	
	// FLOAT DIV TO WINDOW MIDDLE
	

