$(document).ready(function() {
	changeHeight();
    $('#dialog').jqm({modal: true, trigger: 'a.showDialog'});
	$('#dialog').jqmAddClose('.closeClass'); 
});

function changeHeight() {
    
    var pagesize = getPageSize();

    var header_height = $('#header').height();
    var mainmenu_height = $('#main-menu').height();
    var pagewrapper_height = $('#page-wrapper').height();
    var footer_height = $('#footer').height();
    var copyright_height = $('#copyright').height();
	var bottom_height = $('#bottom').height();

    var total_height = header_height + mainmenu_height + pagewrapper_height + footer_height + copyright_height + bottom_height;
   // alert(total_height);
	var add = 120;
    if(total_height<pagesize[3]) {
        var diff = pagesize[3] - mainmenu_height - header_height - footer_height - copyright_height -bottom_height - add;
        $('#page-wrapper').css('min-height',diff+'px');
    }
}


function getPageSize()
{
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function sendFeedback()
{
	//jQuery('#login-progress').show();
	var baseUrl = jQuery('#baseUrl').val();
	
	var title = $('#title option:selected').val();
	var name = $('#name').val();
	var company = $('#company').val();
	var job_title = $('#job_title').val();
	var country = $('#country').val();
	var email = $('#email').val();
	var phone = $('#phone').val();
	var subject = $('#subject').val();
	var message = $('#message').val();
	var vcf = $('#vcf').val();
	var lang = $('#lang').val();

	jQuery.post(baseUrl+'/index/send-feedback', {
			title:		title,
			name:		name,
			company:	company,
			job_title:	job_title,
			country:	country,
			email:		email,
			phone:		phone,
			subject:	subject,
			message:	message,
			vcf:		vcf,
			langvar: 	lang
		},
		function(data){
		resultFeedback(data);
	}, "json");
}

function resultFeedback(data)
{
	//alert(data['result']);
	//alert(data['errors']);
	
	if(data['result']==0) {
		$('#errors').html(data['errors']);
		$('#errors').css('display','block');
	} else {
		$('#errors').css('display','none');
		$('#fback-form').css('display','none');
		$('#msg').css('display','block');
		
		
	}
}

