function testfunc()
{
	
	alert('new window');
}

function FindProduct()
{
	var  criterior =  document.getElementById('txtsearch').value;
	
	if(criterior != '' && criterior != undefined){
		 
		 window.location.href= "./index.php?page=find&find=" + criterior;
		 
	 }
	 
	 
}

function showsubmenu(categorymenu,submenu){
	
	hideAllsubmenus();
	
	var MenuLayer = document.getElementById(categorymenu);
	var SubMenuLayer = document.getElementById(submenu);

/* Show or Hide the sub menu */	

if(SubMenuLayer.style.display=="none" || SubMenuLayer.style.display==""){
SubMenuLayer.style.display="block";
SubMenuLayer.display="block;"
sHeight =  20 + SubMenuLayer.offsetHeight ;
} 
else { 
SubMenuLayer.style.display="none";
sHeight = 21;	
}

/*Resize the Category menu item */
MenuLayer.style.height = sHeight + 'px';

/* Resize the outerwrapper */
/*setouterwrapperheight();*/
}

function hideAllsubmenus(){
  atags = document.getElementsByTagName('table');
  for(i=0;i<atags.length;i++) {  	
    if(atags[i].className=='Submenutable'){
      atags[i].style.display='none';
    }  
  }
  
  atags = document.getElementsByTagName('li');
  for(i=0;i<atags.length;i++) {  	
    if(atags[i].className=='catmenu_li'){
      atags[i].style.height=21 + 'px';
    }  
  }  
}


function initNavpostions(){
	 
	/*setnavboxposition('left_sidebar','leftnavbox2')*/
	 
	setouterwrapperheight()
	//setcopyrightposition()
	
	//hideAllsubmenus()
}

function setnavboxposition(sNavKey,sElement){
	
//	/* Get the position and height of the nave div */ 
	var lTop = document.getElementById(sNavKey).offsetTop;
	var lheight = document.getElementById(sNavKey).offsetHeight;
	
//	/* Calculate the new top and height values */
//	
//	var ldiff = lElemTop - lTop;
    var newTop = lTop + lheight;
  	document.getElementById(sElement).style.top = newTop;
//	*/

}

function setouterwrapperheight(){
	

	var nav2Height =  document.getElementById('left_sidebar').offsetHeight;
	var nav3Height =  document.getElementById('header').offsetHeight;
	var nav5Height =  document.getElementById('page_menu').offsetHeight;
	/*var nav6Height =  document.getElementById('page_bottom_menu').offsetHeight;*/
	/*var newHeight =  nav2Height + nav3Height + nav5Height + nav6Height  ;*/
	var newHeight =  nav2Height + nav3Height + nav5Height;
	
	document.getElementById("outerwrapper").style.height = newHeight;
	
}

function setcopyrightposition(){

	var nav7Height = document.getElementById('outerwrapper').offsetHeight;
	var newHeight =   0 ;//nav7Height;
		
	document.getElementById("pagecopyright").style.top = newHeight;

	
}
/*
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.style.background = '#ffffff' ;
	formElement.value = trim(formElement.value);
	
	_isEmpty = false;
	if (formElement.value == '') {
		 formElement.style.background = '#F4BAA8';
		_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 checkNumeric(objName,minval, maxval,comma,period,hyphen)
{
	var numberfield = objName;
	if (chkNumeric(objName,minval,maxval,comma,period,hyphen) == false)
	{
		numberfield.select();
		numberfield.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function chkNumeric(objName,minval,maxval,comma,period,hyphen)
{
// only allow 0-9 be entered, plus any values passed
// (can be in any order, and don't have to be comma, period, or hyphen)
// if all numbers allow commas, periods, hyphens or whatever,
// just hard code it here and take out the passed parameters
var checkOK = "0123456789" + comma + period + hyphen;
var checkStr = objName;
var allValid = true;
var decPoints = 0;
var allNum = "";

for (i = 0;  i < checkStr.value.length;  i++)
{
ch = checkStr.value.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
if (ch != ",")
allNum += ch;
}
if (!allValid)
{	
alertsay = "Please enter only these values \""
alertsay = alertsay + checkOK + "\" in this field."
alert(alertsay);
return (false);
}

// set the minimum and maximum
var chkVal = allNum;
var prsVal = parseInt(allNum);
if (chkVal != "" && !(prsVal >= minval && prsVal <= maxval))
{
alertsay = "Please enter a value greater than or "
alertsay = alertsay + "equal to \"" + minval + "\" and less than or "
alertsay = alertsay + "equal to \"" + maxval + "\" in this field."
alert(alertsay);
return (false);
}
}
//  End -->

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=" + info+"&pd=" + mylink;
else
   href="./index.php?info=" + info+ "?pd=" + mylink.href;
   
   // alert('new window');
   if(wndheight == undefined){
   wndheight = 500;
  }
  if(wndwidth==undefined){
  	wndwidth=650;
  }
  
   //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 closeWindow(){
	window.close;
}

function unscramble(scrambledtext){
	var output = unescape(scrambledtext);
	output = "martin";
	alert(output);
	return output;
	
}

function update_minicart(pid,iQty){
/*
Use JQuery to add items to the users basket and then refresh the minicart div
*/ 


$.get("../_lib/mini-cart_functions.php", {action: 'add', p: pid,qty: iQty },function(data){
     //alert("Data added: " + data);
     if(data != 'OK'){
     	 alert(data); // Error msg is return from the called function
    }else{
		  $.get("../_lib/mini-cart_functions.php", {action: 'reload'},function(data){
		     //alert("Data Loaded: " + data);
		     document.getElementById('cartclass').innerHTML = data;
		     alert('Product added to your shopping cart.');
		   });
    }
 });
 	
}


function refreshminicart(){
			  $.get("../_lib/mini-cart_functions.php", {action: 'reload'},function(data){
		     //alert("Data Loaded: " + data);
		     if (window.opener && !window.opener.closed){
		       window.opener.document.getElementById('cartclass').innerHTML = data;
		     }
		     alert('This product has been added to your shopping cart.');
		   });
}

function ReloadPage(){
	alert('reload');
		window.location.reload();
	
}

function ClearContactUsDetails(){

	
	var oForm = document.forms["ContactUsForm"]; 
	var frm_elements = oForm.elements; 
		
for(i=0; i<frm_elements.length; i++) {

field_type = frm_elements[i].type.toLowerCase();

switch(field_type) {

case "text":
case "password":
case "textarea":


frm_elements[i].value = "";

break;

case "radio":
case "checkbox":

if (frm_elements [i].checked) {

frm_elements[i].checked = false;

}
break;

case "select-one":
case "select-multi":

frm_elements[i].selectedIndex = -1;
break;

default:
break;

}

}	
}
