/*
Strip whitespace from the beginning and end of a string
Input : a string
	jpw 08/09/2010 removed a comma from the processreport function (after comments.value)
	jpw 08/18/2010 added the checkitemNumber function for validation on config/main.php
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

/*
Make sure that textBox only contain number
*/
function checkNumber(textBox)
{
	if(textBox.value == '.') textBox.value = '0.';
	while (textBox.length > 0 && isNaN(textBox.substring(textBox.length-1, textBox.length))) {
			textBox = textBox.substring(0, textBox.length - 1)
	}
	
	textBox = trim(textBox);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}

/* jpw added this as a special check function because it calls a specific field
	   on the main config form of txtitemsperpage.  Forces the default of 4 if not valid.
*/
function checkitemNumber(textBox)
{
	if(textBox == '.') textBox = '0.';
	if (textBox.length > 0 && isNaN(textBox.substring(textBox))) {
		alert('This value must be numeric.');
		document.frmConfig.txtitemsperpage.value = 4;
	}
	
}



/*
	Check if a form element is empty.
	If it is display an alert box and focus
	on the element
*/
function isEmpty(formElement, message) {
	formElement.value = trim(formElement.value);
	
	_isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	
	return _isEmpty;
}

/*
	Set one value in combo box as the selected value
*/
function setSelect(listElement, listValue)
{
	for (i=0; i < listElement.options.length; i++) {
		if (listElement.options[i].value == listValue)	{
			listElement.selectedIndex = i;
		}
	}	
}

function process_report(){
	        $.blockUI({ message: "<h1>Progressing your report</h1>" }); 
 
            $.ajax({ 
                url: 'process-report.php', 
                cache: false, 
				type: "POST",
				dataType: "html",
				data: ({
					   name :  document.getElementById("r_name").value,
					   email :  document.getElementById("r_email").value,
					   phone :  document.getElementById("r_phone").value,
					   type :  document.getElementById("abuse_type").value,
					   shop :  document.getElementById("r_URL").value,
					   comments :  document.getElementById("r_comments").value
					   }),
                complete: function() { 
                    // unblock when remote call returns 
                    $.unblockUI(); 
                } 
			}); 	
}

function ext_check(img){
		var fl= document.getElementById(img).value;
		var brfl = fl.split('.');
		
		fl = brfl[brfl.length - 1];
		
		//alert(fl.toUpperCase());
		
		//if(( fl.toUpperCase() != 'JPG') || (fl.toUpperCase() != 'JPEG') || (fl.toUpperCase() != 'PNG') || (fl.toUpperCase() != 'GIF') || (fl.toUpperCase() != 'BMP')){
		switch(fl.toUpperCase())
		{
			case 'JPG': case 'JPEG': case 'PNG': case 'GIF': case '':
				return true;	
			break;
			default:
				document.getElementById("err_msg").innerHTML = "Invalid Image Extension";
			  	return false
		}			
		
}


function modal_alert(msg){
document.getElementById("modal_msg").innerHTML = msg;
//$.blockUI({ message: $('#modal_alert'), css: { width: '275px' } });
$.blockUI({ message: '<span id="modal_msg">' + msg +'</span> <br/> <br/><input type="button" id="no" value="OK" onClick="ext_close()" class="box"/>', 
	            css: { width: '275px' } });	
}

function ext_close(){
	    document.getElementById("modal_msg").innerHTML = '';
	    $.unblockUI();
}

function modal_isEmpty(formElement, message) {
	formElement.value = trim(formElement.value);
	
	_isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		modal_alert(message);
		formElement.focus();
	}
	
	return _isEmpty;
}

function modal_alert2()
{
	$.blockUI({ message: $('#modal_alert2'), css: { width: '275px' } });			
	}

	function ext_close(){

	    $.unblockUI();
}
