var isMozilla;
var objDiv = null;
var originalDivHTML = "";
var DivID = "";
var over = false;

function getWindowWidth() {
		var windowWidth = 0;
		if (typeof(window.innerWidth) == 'number') {
			windowWidth = window.innerWidth;
		}
		else {
			if (document.documentElement && document.documentElement.clientWidth) {
				windowWidth = document.documentElement.clientWidth;
			}
			else {
				if (document.body && document.body.clientWidth) {
					windowWidth = document.body.clientWidth;
				}
			}
		}
		return windowWidth;
	}
	
function buildDimmerDiv() {
    document.write('<div id="Dimmer" style="width:'+ (getWindowWidth() - 16) + 'px; height:' + (screen.height + 1000) +'px"></div>');
  	document.write('<div id="VideoWindow" class="hidden"></div>');
}

function displayWindow(url) {
	var w, h, l, t;
	w = 500;
	h = 500;
	l = ((getWindowWidth() - 15)/2)-(w/2);
	if (document.documentElement.scrollTop) {
		t = document.documentElement.scrollTop + 120;
	} else {
		t = document.body.scrollTop + 120;
	}
	displayFloatingDiv('VideoWindow', '', w, h, l, t, url);
	sendRequest(url)
}
			
function displayFloatingDiv(divId, title, width, height, left, top, url) {
	DivID = divId;

	// document.getElementById('Dimmer').style.visibility = "visible";
	sFa();

    document.getElementById(divId).style.width = width + 'px';
    // document.getElementById(divId).style.height = height + 'px';
    document.getElementById(divId).style.left = left + 'px';
    document.getElementById(divId).style.top = top + 'px';

	if (originalDivHTML == "") originalDivHTML = document.getElementById(divId).innerHTML;
	document.getElementById(divId).innerHTML = originalDivHTML;
	
	document.getElementById(divId).className = 'Dimming';
	document.getElementById(divId).style.visibility = "visible";
}

function hiddenFloatingDiv(divId) {
	document.getElementById(divId).innerHTML = originalDivHTML;
	document.getElementById(divId).style.visibility='hidden';

	//document.getElementById('Dimmer').style.visibility = 'hidden';
	hFa();

	DivID = "";
}

function MouseDown(e) {
    if (over) {
        if (isMozilla) {
            objDiv = document.getElementById(DivID);
            X = e.layerX;
            Y = e.layerY;
            return false;
        } else {
            objDiv = document.getElementById(DivID);
            objDiv = objDiv.style;
            X = event.offsetX;
            Y = event.offsetY;
        }
    }
}

function MouseMove(e) {
    if (objDiv) {
        if (isMozilla) {
            objDiv.style.top = (e.pageY-Y) + 'px';
            objDiv.style.left = (e.pageX-X) + 'px';
            return false;
        } else {
            objDiv.pixelLeft = event.clientX-X + document.body.scrollLeft;
            objDiv.pixelTop = event.clientY-Y + document.body.scrollTop;
            return false;
        }
    }
}

function MouseUp() {
    objDiv = null;
}

function init() {
    isMozilla = (document.all) ? 0 : 1;
    if (isMozilla) {
	   function modifyText() {
	   
	   }        
	   document.addEventListener(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP, modifyText, false);
    }
    document.onmousedown = MouseDown;
    document.onmousemove = MouseMove;
    document.onmouseup = MouseUp;
	buildDimmerDiv();
}

init();

function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function sendRequest(request) {
    http.open('GET', request);
    http.onreadystatechange = handleResponse;
    http.send(null);
}

var http_request = false;
function postRequest(url, parameters) {
	http_request = false;

	var parameters = "";

	if (self.formMessages) {
		var parameters = "Content=" + encodeURI( document.formMessages.Content.value ) +
						"&ToProfileID=" + encodeURI( document.formMessages.ToProfileID.value ) +
						"&Video=" + encodeURI( document.formMessages.Video.value );
	} 
	if (self.formFriends) {	
		var parameters = "Code=" + encodeURI( document.formFriends.Code.value );
	}
	if (self.formInvite) {
		var parameters = "InviteEmails=" + encodeURI( document.formInvite.InviteEmails.value );
		if (document.formGetContacts.ImportTypeID.Email > ' ') {
			var parameters = "ImportTypeID=" + encodeURI( document.formGetContacts.ImportTypeID.value );
		}
	} 
	if (self.formCaption) {
		var parameters = "ProfileCaption=" + encodeURI( document.formCaption.ProfileCaption.value );
	}
	if (self.formDetails) {
		var parameters = "ProfileName=" + encodeURI( document.formDetails.ProfileName.value ) +
						"&Town=" + encodeURI( document.formDetails.Town.value ) +
						"&Visit=" + encodeURI( document.formDetails.Visit.value ) +
						"&Style=" + encodeURI( document.formDetails.Style.value ) +
						"&Music=" + encodeURI( document.formDetails.Music.value ) +
						"&Clubs=" + encodeURI( document.formDetails.Clubs.value ) +
						"&Interests=" + encodeURI( document.formDetails.Interests.value ) +
						"&Phone=" + encodeURI( document.formDetails.Phone.value ) +
						"&LookingFor=" + encodeURI( document.formDetails.LookingFor.value ) +
						"&Details=" + encodeURI( document.formDetails.Details.value );
	}
	if (self.formSettings) {
		for (var x=0; x<document.formSettings.Privacy_ViewProfileID.length; x++) {
			if (document.formSettings.Privacy_ViewProfileID[x].checked) { var val_Privacy_ViewProfileID = document.formSettings.Privacy_ViewProfileID[x].value; }
		}
		for (var x=0; x<document.formSettings.Privacy_SendMessageID.length; x++) {
			if (document.formSettings.Privacy_SendMessageID[x].checked) { var val_Privacy_SendMessageID = document.formSettings.Privacy_SendMessageID[x].value; }
		}
		var parameters = "Privacy_ViewProfileID=" + encodeURI( val_Privacy_ViewProfileID ) +
						"&Privacy_ViewProfileKeywords=" + encodeURI( document.formSettings.Privacy_ViewProfileKeywords.value ) +
						"&Privacy_SendMessageID=" + encodeURI( val_Privacy_SendMessageID ) +
						"&Privacy_SendMessageKeywords=" + encodeURI( document.formSettings.Privacy_SendMessageKeywords.value );
	}
	
	
	http.onreadystatechange = handleResponse;
	http.open('POST', url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", parameters.length);
	http.setRequestHeader("Connection", "close");
	http.send(parameters);
}

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        
		var addHeader;
		// addHeader = '<table style="width: 100%;"><tr><td ondblclick="void(0);" onmouseover="over=true;" onmouseout="over=false;" style="cursor:move;height:5px"><br /></td></tr></table>';
		// addHeader = '<div style="height: 20px; cursor:move; padding-right: 20px; background-color: #fff;" ondblclick="void(0);" onmouseover="over=true;" onmouseout="over=false;"><a href="##" onclick="hiddenFloatingDiv(\'VideoWindow\');void(0);return false;" style="float: right; margin: 4px 0px 4px 0px; color: ##333;"><strong><u>Close Window</u></strong></a></div>';

		addHeader = '';
		
 		window.parent.document.getElementById('VideoWindow').innerHTML = addHeader + response;

	}
}

function sendRequestOnly(request) {
    http.open('GET', request);
    http.send(null);
}




















var tmr;
var t;
var obj;

function sFa() {
	obj = gObj();
	sLft();
	shw(true);
	t = 0;
	sTmr();
}

function hFa() {
	t = -100;
	sTmr();
	return false;
}

function sTmr() {
	tmr = setInterval("fd()",20);
}

function fd() {
	var amt = Math.abs(t+=20);
	if(amt == 0 || amt >= 100) clearInterval(tmr);
	amt = (amt == 100)?99.999:amt;
  	
	obj.style.filter = "alpha(opacity:"+amt+")";
	obj.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+ amt + ");";
	obj.style.KHTMLOpacity = amt/100;
	obj.style.MozOpacity = amt/100;
	obj.style.opacity = amt/100;
	
	if(amt == 0) shw(false);
}

function sLft() {
	var w = 170;	// set this to 1/2 the width of the faw div defined in the style sheet 
			// there's not a reliable way to retrieve an element's width via javascript!!
					
	var l = (document.body.innerWidth)? document.body.innerWidth / 2:document.body.offsetWidth / 2;

	// obj.style.left = (l - w)+"px";
	obj.style.left = "0px";

}

function gObj() {
	return document.getElementById("Dimmer");	
}

function shw(b) {
	(b)? obj.style.visibility = "visible":obj.style.visibility = "hidden";	
}

