﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//disabling popup with jQuery magic!
function disablePopup(PopUpElement, BackgroundPopUp){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$(BackgroundPopUp).hide();
		$(PopUpElement).hide();
		popupStatus = 0;		
	}
}

//centering popup
function EnablePopup(PopUpElement, BackgroundPopUp){
    //request data for centering

	var popupHeight = $(PopUpElement).height();
	
	var popupWidth = $(PopUpElement).width();

	var backgroundPopUpHeight = $(document).height();
	var backgroundPopUpWidth = $(window).width() - 2; //alert(popupHeight); 
	//centering
	$(PopUpElement).css({
		"top": backgroundPopUpHeight/2-popupHeight/2,
		"left": backgroundPopUpWidth/2-popupWidth/2
        
	});
	//only need force for IE6
	
	var windowheight = $(window).height();
	
	if(windowheight > (backgroundPopUpHeight - popupHeight))
	{
	    backgroundPopUpHeight = windowheight;
	}
	else
	{
	     backgroundPopUpHeight = backgroundPopUpHeight - popupHeight;
	}
	
	$(BackgroundPopUp).css({
		"height": backgroundPopUpHeight,
		"width": backgroundPopUpWidth 	
	});
	
	//loads popup only if it is disabled
	if(popupStatus==0){
		$(BackgroundPopUp).css({
			"opacity": "0.5"
		});
		 $(BackgroundPopUp).show();
    $(PopUpElement).show();
		popupStatus = 1;
	}
	
	//extra scriipt for animation	
    var Height =$(window).height();
    var NewHeight = Height/2-200;
    var IE6Height = backgroundPopUpHeight/64;
    //alert(NewHeight);
   // alert(popupHeight + " Window Height : " + Height + " MiddleHeight  ; " + NewHeight + " Background height : " + backgroundPopUpHeight + " Background Width : " + backgroundPopUpWidth ); 
    $(PopUpElement).animate({top: NewHeight}, {queue:false, duration:1200}); 

}
function EnableImagePopup(PopUpElement, BackgroundPopUp) {

	//request data for centering
	var popupHeight = $(PopUpElement).height();
	
	var popupWidth = $(PopUpElement).width();
	var backgroundPopUpHeight = $(document).height();
	var backgroundPopUpWidth = $(window).width() - 2;
	//centering
	$(PopUpElement).css({
		"top": backgroundPopUpHeight/2-popupHeight/2,
		"left": backgroundPopUpWidth/2-popupWidth/2-30
	});
	//only need force for IE6
	
	var windowheight = $(window).height();
	
	if(windowheight > (backgroundPopUpHeight - popupHeight))
	{
	    backgroundPopUpHeight = windowheight;
	}
	else
	{
	     backgroundPopUpHeight = backgroundPopUpHeight - popupHeight;
	}
	
	$(BackgroundPopUp).css({
		"height": backgroundPopUpHeight,
		"width": backgroundPopUpWidth 	
	});
	
	//loads popup only if it is disabled
	if(popupStatus==0){
		$(BackgroundPopUp).css({
			"opacity": "0.5"
		});
		 $(BackgroundPopUp).show();
    $(PopUpElement).show();
    popupStatus = 1;

}
	// document.getElementById("divPopUpImage").style.visibility="visible"; 
	//extra scriipt for animation	
//    var Height =$(window).height();
//    var NewHeight = Height/2-350;
//    var IE6Height = backgroundPopUpHeight/64;
//    //alert(NewHeight);
//   // alert(popupHeight + " Window Height : " + Height + " MiddleHeight  ; " + NewHeight + " Background height : " + backgroundPopUpHeight + " Background Width : " + backgroundPopUpWidth ); 
//    $(PopUpElement).animate({top: NewHeight}, {queue:false, duration:1200}); 

}

//function ImagePopUp()
//{
//    document.getElementById("divChat").style.display="block";
//    //Create a 'script' element	
//    var scrptE = document.createElement("script");

//    // Set it's 'type' attribute	
//    scrptE.setAttribute("type", "text/javascript");

//    // Set it's 'language' attribute
//    scrptE.setAttribute("language", "JavaScript");

//    // Set it's 'src' attribute
//    scrptE.setAttribute("src", "http://chatserver.comm100.com/js/LiveChat.js?siteId=61913&amp;planId=1683&amp;partnerId=-1");

//    // Now add this new element to the head tag
//    document.getElementsByTagName("head")[0].appendChild(scrptE);
//}
//    
//function ImagePopUpClose()
//{
//    document.getElementById("divChat").style.display="none";
//}


//function OpenChatWindow(chatURL) {
//    var myObject = new Object();
//    myObject = "";
//    strReturnValue = unescape(window.showModalDialog(chatURL, myObject, "resizable=1;location:yes;menubar:yes;toolbar:no;scrollbars:no;status:0;dialogTop: 200px; dialogLeft: 300px;dialogWidth:542px;dialogHeight:563px;help:no;scroll:yes;center:1;maximize:yes;minimize:yes;maximize:1;minimize:1;center:1;"));
//    return false;
//}
function ImagePopUp() {
    document.getElementById("divChat").style.display = "block";
    //Create a 'script' element	
    var scrptE = document.createElement("script");

    // Set it's 'type' attribute	
    scrptE.setAttribute("type", "text/javascript");

    // Set it's 'language' attribute
    scrptE.setAttribute("language", "JavaScript");

    // Set it's 'src' attribute
    scrptE.setAttribute("src", "https://chatserver.comm100.com/js/LiveChat.js?siteId=61913&amp;planId=2570&amp;partnerId=-1");

    // Now add this new element to the head tag
    document.getElementsByTagName("head")[0].appendChild(scrptE);


    var p = $('a[name^=Live_ChatPosition]');
    var offset = p.offset();
   
    $('#divChat').css('top', offset.top+28);
    $('#divChat').css('left', offset.left);
//    if ($.browser.msie && $.browser.version == "7.0") {
//        $('#divChat').css('top', offset.top+28);
//     }
    
}

function ImagePopUpClose() {
    document.getElementById("divChat").style.display = "none";
}


function OpenChatWindow(chatURL) {
    var myObject = new Object();
    myObject = "";
    strReturnValue = unescape(window.showModalDialog(chatURL, myObject, "resizable=1;location:yes;menubar:yes;toolbar:no;scrollbars:no;status:0;dialogTop: 200px; dialogLeft: 300px;dialogWidth:542px;dialogHeight:563px;help:no;scroll:yes;center:1;maximize:yes;minimize:yes;maximize:1;minimize:1;center:1;"));
    return false;
}


