/*
Strip whitespace from the beginning and end of a string
Input : a string
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

/*
Make sure that textBox only contain number
*/
function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}

/*
	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;
}

/*
	Check if a form element is empty.
	No Msg and No Focus
*/
function isEmptyNoMsg(formElement) {
	formElement.value = trim(formElement.value);
	
	_isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
	}
	
	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;
		}
	}	
}


/*
    Set the background colour of the main page.
*/

function setbgcolor(){

  document.bgColor = "#FFFFFF";
}



function openNewWindow(mylink, windowname,wndheight,wndwidth,info)
{
	
	//alert('new window');

$thispage = window.location;

if (! window.focus)return true;

var href;
if (typeof(mylink) == 'string')
   href = "./index.php?info=popup" + "&type=" + windowname + "&pd=" + mylink;
else
   //href="./index.php?info=popup" + "?pd=" + mylink.href;
   href="./index.php?info=popup" + "&type=" + windowname + "&pd=" + mylink.href;
   
    
   if(wndheight == undefined){
   wndheight = 750;
  }
  
  if(wndwidth==undefined){
  	wndwidth=900;
  }
  
   //alert(href + "\n"+ windowname + "\n" +wndwidth + "\n" + wndheight);
   //var mywindow = window.open(href, windowname, 'width=' + wndwidth + ',height=' + wndheight + ',scrollbars=Yes');
   var mywindow = window.open(href, windowname, 'width=' + wndwidth +',height=' + wndheight + ',scrollbars=Yes');
if(mywindow) {
    //window.location = $thispage; 
    //return false;
  }else{
  alert('You are using popup blocker software. \nThis website needs to open a window to show you this product.\n\nplease disable your popup blocker or try holding down the \'Ctrl\' key when you click the \'view more\' button.');
   //window.location = $thispage;
   //return false;
  }
}


function openGoogleWindow(mylink, windowname,wndheight,wndwidth,info)
{
	
	//alert('new window');

$thispage = window.location;

if (! window.focus)return true;

var href;
if (typeof(mylink) == 'string')
   href =  mylink;
else   
   href= mylink.href;
   
    
 if(wndheight == undefined){
   wndheight = 750;
  }
  
  if(wndwidth==undefined){
  	wndwidth=900;
  }

   var mywindow = window.open(href, windowname, 'width=' + wndwidth +',height=' + wndheight + ',scrollbars=Yes,resizable=1,status=1');
if(mywindow) {

  }else{
  alert('You are using popup blocker software. \nThis website needs to open a window to show you this product.\n\nplease disable your popup blocker or try holding down the \'Ctrl\' key when you click the \'view more\' button.');

  }
}


function openNewsLetter(){
	
	//alert('new window');

$thispage = window.location;

if (! window.focus)return true;

/*
var href;

if (typeof(mylink) == 'string')
   href =  mylink;
else   
   href= mylink.href;
 */  
 /*   
 if(wndheight == undefined){
   wndheight = 750;
  }
  
  if(wndwidth==undefined){
  	wndwidth=900;
  }
*/
var mylink = 'http://eepurl.com/bOdb1';
var href;

if (typeof(mylink) == 'string')
   href =  mylink;
else   
   href= mylink.href;

var wndheight  = 750;
var wndwidth   = 900;
var windowname = 'Driftwood Seas Newsletter';

//var mywindow = window.open(href, windowname, 'width=' + wndwidth +',height=' + wndheight + ',menubar=1,titlebar=1,toolbar=1,scrollbars=Yes,resizable=1,status=1');

var mywindow = window.open(href);
if(mywindow) {

  }else{
  alert('You are using popup blocker software. \nThis website needs to open a window to show you this product.\n\nplease disable your popup blocker or try holding down the \'Ctrl\' key when you click the \'view more\' button.');

  }
}

function openNewWindowFull(mylink){
	
	//alert('new window');

$thispage = window.location;

if (! window.focus)return true;


var href;

if (typeof(mylink) == 'string')
   href =  mylink;
else   
   href= mylink.href;
 
 /*   
 if(wndheight == undefined){
   wndheight = 750;
  }
  
  if(wndwidth==undefined){
  	wndwidth=900;
  }
*/
//var mylink = 'http://eepurl.com/bOdb1';
//var href;

if (typeof(mylink) == 'string')
   href =  mylink;
else   
   href= mylink.href;

var wndheight  = 750;
var wndwidth   = 900;
var windowname = 'Driftwood Seas Newsletter';

//var mywindow = window.open(href, windowname, 'width=' + wndwidth +',height=' + wndheight + ',menubar=1,titlebar=1,toolbar=1,scrollbars=Yes,resizable=1,status=1');

var mywindow = window.open(href);
if(mywindow) {

  }else{
  alert('You are using popup blocker software. \nThis website needs to open a window to show you this product.\n\nplease disable your popup blocker or try holding down the \'Ctrl\' key when you click the \'view more\' button.');

  }
}

function closeWindow(){
	window.close;
}

function GetProductDescription(pid){
/*
Use JQuery to get the selected products description
*/ 
alert('GetProductDescription');

$.get("../_lib/callback-functions.php", {action: 'get_prod_descr', p: pid},function(data){
     //alert("Data added: " + data);
     if(data == ''){
     	// alert(data); // Error msg is return from the called function
     	
     	return '';
    }else{
    	
    	return data;
		 
    }
 });
 	
}
