function popupVideo(url) 
{
	window.open(url,'video','height=661,width=951,top=100,left=100,scrollbars=no,toolbars=no');
}

function popupGeneric(url, width, height) 
{
	window.open(url,'sbspopup','height=' + height + ',width=' + width + ',top=100,left=100,scrollbars=no,toolbars=no');
}

function popupSrollable(url, width, height) 
{
	window.open(url,'sbspopup','height=' + height + ',width=' + width + ',top=100,left=100,scrollbars=1,toolbars=0,location=0');
}


function getCategoryArticles(tab, page)
{
	// set up the post variables
	var data =
		'tab=' + tab +
		'&page=' + page
	;

	// send the url via ajax to a php script
	// and refresh content after success
	jQuery.ajax({
		type: 'POST',
		url: baseUrl + '/news/category-articles/',
		data: data,
		success: function(msg) {
			$('#' + tab).html(msg);
		}
	});

}


function getPrograms(controller, divName, page, filterValue, displayOrder, sortBy)
{
	// set up the post variables
	var data =
		'divName=' + divName +
		'&page=' + page +
		'&filterValue=' + filterValue +
		'&displayOrder=' + displayOrder + 
		'&sortBy=' + sortBy
	;

	// send the url via ajax to a php script
	// and refresh content after success
	jQuery.ajax({
		type: 'POST',
		url: baseUrl + '/' + controller + '/program-list/',
		data: data,
		success: function(msg) {
			$('#' + divName).html(msg);
		}
	});

}

function submitEnquiry(divName, baseUrl) 
{
	var errorText = '';
	var formError = false;

	var name 		= $('#nameEnquire').attr('value');
	var company	 	= $('#company').attr('value');
	var email 		= $('#emailEnquire').attr('value');
	var phone 		= $('#phone').attr('value');
	var fax    		= $('#fax').attr('value');
	var address1    = $('#address-1').attr('value');
	var address2 	= $('#address-2').attr('value');
	var city   		= $('#city').attr('value');
	var state     	= $('#state').attr('value');
	var country 	= $('#country').attr('value');
	var message		= $('#message').attr('value');
	var dvd_screener = $('#dvd_screener').attr('value');
	
	var program1 	= $('#program1').attr('value');
	var program2 	= $('#program2').attr('value');
	var program3 	= $('#program3').attr('value');
	var program4 	= $('#program4').attr('value');
	var program5 	= $('#program5').attr('value');
	var program6 	= $('#program6').attr('value');

	// do validation
	if (name == "") {
		 errorText = errorText + "Please enter your name\n";
		 formError = true;
	}
	if (company == "") {
		 errorText = errorText + "Please enter your company\n";
		 formError = true;
	}
	if (email == "") {
		 errorText = errorText + "Please enter your email address\n";
		 formError = true;
	}
	
	if (program1 == "Select a program") {
		 if (program2 == "Select a program") {
		 	if (program3 == "Select a program") {
		 		if (program4 == "Select a program") {
		 			if (program5 == "Select a program") {
		 				if (program6 == "Select a program") {
		 					errorText = errorText + "Please select at least one program\n";
		 					formError = true;
		 				}
		 			}
		 		}
		 	}
		 }
	}

	if(formError) {
		window.alert(errorText);
		return;
	};
	
	// set up the post variables
	var data =
		'name=' + name +
		'&company=' + company +
		'&email=' + email +
		'&phone=' + phone +
		'&fax=' + fax +
		'&address1=' + address1 +
		'&address2=' + address2 +
		'&city=' + city +
		'&state=' + state +
		'&country=' + country + 
		'&message=' + message + 
		'&dvd_screener=' + dvd_screener +
		'&program1=' + program1 +
		'&program2=' + program2 +
		'&program3=' + program3 +
		'&program4=' + program4 +
		'&program5=' + program5 + 
		'&program6=' + program6
	;

	// send the url via ajax to a php script
	// and refresh content after success
	jQuery.ajax({
		type: 'POST',
		url: baseUrl + '/ajax/enquiry',
		data: data,
		success: function(msg) {
			$('#' + divName).html(msg);
		}

	});
}


function makeComment() 
{
	var errorText = '';
	var formError = false;

	var contentId = $('#contentId').attr('value');
	var dbName    = $('#dbName').attr('value');
	var tableName = $('#tableName').attr('value');
	
	var formContainer = $('#formContainer').attr('value');
	var refererUrl    = $('#refererUrl').attr('value');
	
	var userName     = $('#txt_name').attr('value');
	var userLocation = $('#txt_location').attr('value');
	
	var title   = encodeURIComponent($('#txt_title').attr('value'));
	if (title == 'undefined') {
		title = '';
	}
	var url     = encodeURIComponent($('#txt_website').attr('value'));
	var content = encodeURIComponent($('#txt_content').attr('value'));
	var active  = $('#active').attr('value');
	
	var private_key = $('#com_private_key').attr('value');
	var public_key  = $('#public_key').attr('value');

	// do validation
	if (userName == "") {
		 errorText = errorText + "Please enter your name\n";
		 formError = true;
	}
	if (content == "") {
		 errorText = errorText + "Please enter your message\n";
		 formError = true;
	}
	if (private_key == "") {
		 errorText = errorText + "Please enter the validation number\n";
		 formError = true;
	}

	if(formError) {
		window.alert(errorText);
		return;
	};
	
	// set up the post variables
	var data =
		'contentId=' + contentId +
		'&name=' + userName +
		'&location=' + userLocation +
		'&title=' + title +
		'&website=' + url +
		'&content=' + content +
		'&active=' + active +
		'&public_key=' + public_key +
		'&private_key=' + private_key +
		'&dbName=' + dbName + 
		'&tableName=' + tableName + 
		'&refererUrl=' + refererUrl + 
		'&formContainer=' + formContainer
	;

	// send the url via ajax to a php script
	// and refresh content after success
	jQuery.ajax({
		type: 'POST',
		url: baseUrl + '/comment/make-comment/',
		data: data,
		success: function(msg) {
			$('#' + formContainer).html(msg);
		}

	});
}

function getComments(dbName, tableName, contentId, itemsPerPage, numPagesToDisplay, currentPage, baseUrl, container) 
{
	var params = encodeURI(
		'/dbName/' + dbName +
		'/tableName/' + tableName +
		'/contentId/' + contentId +
		'/currentPage/' + currentPage +
		'/itemsPerPage/' + itemsPerPage +
		'/numPagesToDisplay/' + numPagesToDisplay +
		'/container/' + container
	);
	
	$.ajax({
		type: 'GET',
		url: baseUrl + '/comment/get-comments' + params,
		data: '',
		success: function(msg) {
			$('#' + container).html(msg);
		}
	});	
}

/**
 * sets the agree/disagree vote for comments
 */
function makeCommentOpinion(commentId, opinion, dbName, tableName, baseUrl, container) 
{
	var data = 
		'commentId=' + commentId +
		'&opinion=' + opinion +
		'&dbName=' + dbName +
		'&tableName=' + tableName +
		'&container=' + container
	;
	
	// send the url via ajax to a php script
	// and refresh content after success
	jQuery.ajax({
		type: 'POST',
		url: baseUrl + '/comment/make-comment-opinion',
		data: data, 
		success: function(msg) {
			$('#' + container).html(msg);
		}
	});
}


function getFilledCommentForm() 
{
	var contentId = $('#contentId').attr('value');
	var dbName    = $('#dbName').attr('value');
	var tableName = $('#tableName').attr('value');
	
	var formContainer = $('#formContainer').attr('value');
	var refererUrl    = $('#refererUrl').attr('value');
	
	var userName     = $('#txt_name').attr('value');
	var userLocation = $('#txt_location').attr('value');
	
	var title   = $('#txt_title').attr('value');
	var url     = $('#txt_website').attr('value');
	var content = $('#txt_content').attr('value');
	var active  = $('#active').attr('value');

	var data = encodeURI(
		'contentId=' + contentId +
		'&dbName=' + dbName +
		'&tableName=' + tableName +
		'&formContainer=' + formContainer +
		'&active=' + active +
		'&name=' + userName +
		'&location=' + userLocation +
		'&title=' + title +
		'&website=' + url +
		'&content=' + content + 
		'&refererUrl=' + refererUrl
	);
	
	$.ajax({
		type: 'POST',
		url: baseUrl + '/comment/get-filled-comment-form/',
		data: data,
		success: function(msg) {
			$('#' + formContainer).html(msg);
		}
	});	
}

function submitContact(divName, baseUrl) {
    var errorText = '';
    var formError = false;
    
    if(document.getElementById('name').value == "") {
     	errorText = errorText + "Please enter your name\n";
     	formError = true;
    }
    
    if(document.getElementById('company').value == "") {
    	errorText = errorText + "Please enter your company\n";
     	formError = true;
    }
    
	if(document.getElementById('email').value == "") {
     	errorText = errorText + "Please enter your email\n";
     	formError = true;
    }
    
    
    if(formError) {
	    window.alert(errorText);
	    return;
    };
    




	var name = encodeURIComponent(document.getElementById('name').value);
	var company = encodeURIComponent(document.getElementById('company').value);
	var email = encodeURIComponent(document.getElementById('email').value);
	var phone = encodeURIComponent(document.getElementById('phone').value);
	var comment = encodeURIComponent(document.getElementById('comment').value);
	
	var data = 
		'name=' + name +
		'&company=' + company +
		'&email=' + email +
		'&phone=' + phone +
		'&comment=' + comment
	;
	
	// send the url via ajax to a php script
	// and refresh content after success
	jQuery.ajax({
		type: 'POST',
		url: baseUrl + '/submitcontact/list',
		data: data, 
		success: function(msg) {
			$('#' + divName).html(msg);
		}
	});		
}

function subscribeNewsletter(divName, baseUrl) {
    var errorText = '';
    var formError = false;
    
    if(document.getElementById('nameNewsletter').value == "") {
     	errorText = errorText + "Please enter your name\n";
     	formError = true;
    }
    
    if(document.getElementById('company').value == "") {
     	errorText = errorText + "Please enter your company\n";
     	formError = true;
    }
    
	if(document.getElementById('emailNewsletter').value == "") {
     	errorText = errorText + "Please enter your email\n";
     	formError = true;
    }
	
	if(document.getElementById('privacy').checked == false) {
     	errorText = errorText + "Please check to agree SBS Privacy Policy";
     	formError = true;
    }
    
    
    if(formError) {
	    window.alert(errorText);
	    return;
    };
    
	var name = encodeURIComponent(document.getElementById('nameNewsletter').value);
	var company = encodeURIComponent(document.getElementById('company').value);
	var position = encodeURIComponent(document.getElementById('position').value);
	var country = encodeURIComponent(document.getElementById('country').value);
	var email = encodeURIComponent(document.getElementById('emailNewsletter').value);
	
	var data = 
		'nameNewsletter=' + name +
		'&company=' + company +
		'&position=' + position +
		'&country=' + country +
		'&emailNewsletter=' + email
	;
	
	// send the url via ajax to a php script
	// and refresh content after success
	jQuery.ajax({
		type: 'POST',
		url: baseUrl + '/submitcontact/subscribe',
		data: data, 
		success: function(msg) {
			$('#' + divName).html(msg);
		}
	});		
}

