function CloseEmail() {
	$('EmailDoor').style.display = 'none';
	if ($('GB_overlay')) Element.remove('GB_overlay');
}

function EmailPage() {
	
	wleft = (findPos(document.getElementsByClassName('mainAreaInterior')[0])[0] + 220) + 'px'; 
		
		// create grey box if needed
	if (!$('GB_overlay')) {
		new Insertion.Bottom(document.body,'<div id="GB_overlay" style="z-index:150;"></div>');
		resizeGBOverlay2();
	}

	if(!$('EmailDoor')) {
	    new Insertion.Bottom(document.body,'<div id="EmailDoor"></div>');
	}
	var q=''; 
	//alert(q);
	var myAjax = new Ajax.Updater(
	'EmailDoor',
	'/ajax/EmailDoor.php',
	{
		parameters: q,
		onComplete: function(response) {
        $('EmailDoor').style.display = 'block';  
        $('EmailDoor').style.left = wleft;
        Field.activate($('fromName'));
		}
	});
}

function SendEmail()
{
        var q=createContent(document);
        q+='_action=SEND&url='+escape(document.URL);
        //alert(q); 
		var myAjax = new Ajax.Updater(
		'EmailDoor',
		'/ajax/EmailDoor.php',
		{
	        	    
			parameters: q,
			onComplete: function(response){
			  $('EmailDoor').style.display = 'none';
			  if ($('GB_overlay')) Element.remove('GB_overlay');
		     }
		});
		return false;

}	

function createContent(dstDoc) {
    var content = "";
    var logElem = false;

    // build content out of all fields on the form.
    for (var i = 0; i < dstDoc.forms['ajaxEmail'].elements.length; i++) {
        var element = dstDoc.forms['ajaxEmail'].elements[i];
        if (element.type == "file" && element.value != "") {
            // if a file-upload control is on the page that has a file assigned,
            // a real submit is required to transfer the file to the server.
            // make sure that the encoding type is multipart, before the data is submitted.
            dstDoc.forms['ajaxEmail'].encoding = 'multipart/form-data';
            dstDoc.forms['ajaxEmail'].submit();
            //blockClicks(dstDoc, false);
            return;	// exit!

        } else if (element.type == "select-multiple") {
            for (var x = 0; x < element.length; x++) {
                if (element.options[x].selected) {
                    content += element.name + "=" + escape(element.options[x].value) + "&";
                    if (logElem) {
                        logElem.value = logElem.value + element.name + "=" + element.options[x].value + "\n";
                    }
                }
            }
        } else if (element.name != "" && (element.type != "radio" || element.checked)) {
            content += element.name + "=" + escape(element.value) + "&";
            if (logElem) {
                if (element.name != "_debugLog" &&
                    element.name != "_sendContent" &&
                    element.name != "_ajaxMessage") {
                    logElem.value = logElem.value + element.name + "=" + element.value + "\n";
                }
            }
           }
    }
    return content;
}

function WindowSize() {
    var myWidth = 0, myHeight = 0, scrollTop, scrollLeft;
    var type;
    if (typeof(window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
        scrollLeft = window.pageXOffset;
        scrollTop = window.pageYOffset;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
        scrollLeft = document.documentElement.scrollLeft;
        scrollTop = document.documentElement.scrollTop;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
        scrollLeft = document.body.scrollLeft;
        scrollTop = document.body.scrollTop;
    }
    return [myWidth, myHeight, scrollLeft, scrollTop];
}

