function getWindowParams() 
{
	this.width = 100;
	if(window.innerWidth) this.width = window.innerWidth; // Mozilla, Opera, NN4
	else if(document.documentElement && document.documentElement.clientWidth)
	{ // eLe¦ IE
		this.width = document.documentElement.clientWidth;
	}
	else if(document.body && document.body.clientWidth)
	{
		this.width = document.body.clientWidth;
	}
	
	this.height = 100;
	if(window.innerHeight) this.height =  window.innerHeight; // Mozilla, Opera, NN4
	else if(document.documentElement && document.documentElement.clientHeight)
	{ // eLe¦ IE
		this.height =  document.documentElement.clientHeight;
	}
	else if(document.body && document.body.clientHeight)
	{
		this.height = document.body.clientHeight;
	}
	
	this.scrollX = 0;
	if(window.scrollX) this.scrollX = window.scrollX; // Moziila
	if(window.pageXOffset) this.scrollX = window.pageXOffset; // Opera, NN4
	if(document.documentElement && document.documentElement.scrollLeft)
	{ // eLe¦ IE
		this.scrollX = document.documentElement.scrollLeft;
	}
	else if(document.body && document.body.scrollLeft)
	{
		this.scrollX = document.body.scrollLeft;
	}
	
	this.scrollY = 0;
	if(window.scrollY) this.scrollY = window.scrollY; // Mozilla
	if(window.pageYOffset) this.scrollY = window.pageYOffset; // Opera, NN4
	if(document.documentElement && document.documentElement.scrollTop)
	{ // eLe¦ IE
		this.scrollY = document.documentElement.scrollTop;
	}
	else if(document.body && document.body.scrollTop)
	{
		this.scrollY = document.body.scrollTop;
	}


	this.centerLeft = Math.floor(this.width / 2) + this.scrollX;
	this.centerTop = Math.floor(this.height / 2) + this.scrollY;

	return this;
}

function getEl(objID)
{
//	this.obj = document.getElementById? document.getElementById(objID): document.all? document.all[objID]: document.layers? eval("document.layers." +objID): null;
	var jqObj = jQuery("#"+objID);
	if (jqObj != undefined)
		this.obj = jqObj[0];
	this.getSize();
	this.visible = false;
	return this;
}

getEl.prototype.getSize = function()
{
	this.width = document.layers? this.obj.clip.width : (this.obj.offsetWidth||this.obj.style.pixelWidth||parseInt(this.obj.style.width)||0);
	this.height = document.layers? this.obj.clip.height:(this.obj.offsetHeight||this.obj.style.pixelHeight||parseInt(this.obj.style.height)||0);
}

getEl.prototype.setPos = function(left, top)
{
	if (this.obj != null)
	{
		if(document.layers) // NN4
		{
			this.obj.moveTo(left, top);
		}
		else if (typeof this.obj.style.left != "undefined" && typeof this.obj.style.left == "string") // IE5+, Mozilla, Opera 7
		{
			this.obj.style.left = left;
			this.obj.style.top = top;
		}
		else if(typeof this.obj.style.pixelLeft!="undefined") // IE4, Opera 6
		{
			this.obj.style.pixelLeft = left;
		    this.obj.style.pixelTop = top;
		}
		else
		{
			this.obj.left = left;
			this.obj.top = top;
		}
	}
}

getEl.prototype.show = function()
{
	if (!this.visible && this.obj != null)
	{
//		(this.obj.style||this.obj).visibility=(window.opera && !document.documentElement)?'visible':'inherit';
		this.obj.style.display = 'block';
		this.visible = true;
	}
}

getEl.prototype.hide = function()
{
	if (this.visible && this.obj != null)
	{
//		(this.obj.style||this.obj).visibility = 'hidden';
		this.obj.style.display = 'none';
		this.visible = false;
	}
}

var contactObj = null;
var contactSendObj = null;
var maskObj = null;
var allcontentObj = null;
var currentRequestBusinessID = 0;
var windowSizeObj = null;

function getmaskObj()
{
	if (maskObj == null)
		maskObj = new getEl('mask');
	return maskObj;
}
function getcontactObj()
{
	if (contactObj == null)
		contactObj = new getEl('divContact');
	return contactObj;
}
function getcontactSendObj()
{
	if (contactSendObj == null)
		contactSendObj = new getEl('divContactSend');
	return contactSendObj;
}
function getallObj()
{
	if (allcontentObj == null)
		allcontentObj = new getEl('allcontent');
	return allcontentObj;
}
function getwindowSizeObj()
{
//	if (windowSizeObj == null)
		windowSizeObj = new getWindowParams();
	return windowSizeObj;
}

function hideselects()
{

}

function showMask()
{
	getmaskObj().obj.style.height = getallObj().height;
	getmaskObj().obj.style.width = getallObj().width;
	getmaskObj().show();
	hideselects();
}

function showContact()
{
	if (getcontactObj().obj != null)
	{
		showMask();
		getcontactObj().show();

		getcontactObj().setPos(getwindowSizeObj().centerLeft - getcontactObj().width / 2, getwindowSizeObj().centerTop - getcontactObj().height / 2);
		window.onresize = function() {showContact();}
		window.onscroll = function() {showContact();}
	}
}
function hideContact()
{
	if (getcontactObj().obj != null)
	{
		getmaskObj().hide();
		getcontactObj().hide();
		window.onresize = null;
		window.onscroll = null;
	}
}
function showContactSend()
{
	if (getcontactSendObj().obj != null)
	{
		getcontactObj().hide();
		getcontactSendObj().show();

		getcontactSendObj().setPos(getwindowSizeObj().centerLeft - getcontactObj().width / 2, getwindowSizeObj().centerTop - getcontactObj().height / 2);
		window.onresize = function() {showContactSend();}
		window.onscroll = function() {showContactSend();}
	}
}
function hideContactSend()
{
	if (getcontactObj().obj != null)
	{
		getmaskObj().hide();
		getcontactSendObj().hide();
		window.onresize = null;
		window.onscroll = null;
	}
}

function callMethod(methodName, parameters, successFunc)
{
  jQuery.ajax({
  type: "POST",
  url: "/service/contact.asmx/" + methodName,
  data: "t=&" + parameters,
  dataType: "xml",
  success: successFunc,
  error: function (xml){
//  alert(xml);
  }
  });
}

function contactPost()
{
	var sp = new contactParams();
//	jQuery('#divContact').html('<h1>Request is Preparing...</h1>');
	if(sp.businessID == 0 || sp.fName == '' || sp.lName == '' || sp.Email == '')
	{
		alert('Please fill in required fields');
		return;
	}
	if (jQuery("input[@name='readpolicy']").attr('checked') != true)
	{
		alert('Please confirm, that you have read privacy policy.')
		return;
	}
	callMethod('GetContact', "parameters=" + sp, contactPost_Success);
}

function contactSend(userguid)
{
	if (currentRequestBusinessID > 0)
		callMethod('SendContact', "parameters=businessID=" + currentRequestBusinessID + ';userguid=' + userguid, hideContactSend);
}

function contactPost_Success(text)
{
	var x = jQuery('string', text).text();
	jQuery('#divContactSend').html(x);
	
	showContactSend();
}

function contactParams()
{
	this.fName = jQuery("input[@name='fName']").val();
	this.lName = jQuery("input[@name='lName']").val();
	this.email = jQuery("input[@name='email']").val();
	this.phone = jQuery("input[@name='phone']").val();
	this.comments = $("#comments").val();
	this.businessID = currentRequestBusinessID;
	
	this.toString = function()
	{
		var result = 'fName=' + this.fName +
			';lName=' + this.lName +
			';email=' + this.email +
			';phone=' + this.phone +
			';comments=' + this.comments +
			';businessID=' + this.businessID;
		return result;
	}
}