

function viewmoreprodinfo(str)
{
	


  var sortorder = "";
  if ( $("#sortitems").length > 0 ) { 
 	sortorder = document.getElementById('sortitems').value;
  }
  
    
  var moreorless = "";
  if ( $("#moreorless").length > 0 ) { 
 	moreorless = document.getElementById('moreorless').value;
  }
  var page = "";
  if ( $("#page").length > 0 ) { 
 	page = document.getElementById('page').value;
  }
  
  
  document.getElementById('subheadingbar').style.display = 'none';
  
  window.location = 'section.php?menuid=' + $('#headerid').val() + '&filters=' + $('#filterstext').val() + "&orderfilter=" + sortorder + "&moreorless=" + moreorless + "&page=" + page + "&prodid=" + str;

	
}



function submitnewsletsub()
{
	
    
   	var email = $("input#email").val();
    
     
        
    if (ValidateEmail(email) == false)
	{
	   alert("You need to enter a valid email address"); return false;
	}
	
	
   
    $.post('regnews.php', "email=" + email, function(data) {

    window.location = "newsconfirm.php";    
  
 }
);
	
	
}

function encodeMyHtml(str) {
     encodedHtml = str;
     
     encodedHtml = encodedHtml.replace(/ /g,"%20");
     encodedHtml = encodedHtml.replace(/=/g,"%3D");
     encodedHtml = encodedHtml.replace(/&/g,"%26");
     encodedHtml = encodedHtml.replace(/@/g,"%40");
     return encodedHtml;
} 


function unsubscribe()
{
    
 $.blockUI(); 

 $.post('unsubscribedb.php', "email=" + $('#unsubemail').val() + "&reason=" + encodeMyHtml($('#txtunsubscribe').val()), function(data) {
      
   if (data.indexOf("Success") > 0) {
    
    alert("You have been removed from our email list");     
    window.location = 'index.php';
      
   } else {
   	
   	$.unblockUI(); 
   		
   }
 }
);
    
    
}

function resetpass()
{
    
    var msg = "";
    
    if ($('#txtp1').val() == "")
    {
        msg = "<p style='font-size:12px; color:#ffffff;'>Password Field cannot be blank</p>"; 
        $("#generalmessage").html(msg).dialog('option', 'title', 'Please correct the following').dialog('option', 'height', 'auto').dialog("open");return false;	
    }
    
    if ($('#txtp1').val() != $('#txtp2').val())
	{
	    msg = "<p style='font-size:12px; color:#ffffff;'>Your passwords do not match</p>"; 
        $("#generalmessage").html(msg).dialog('option', 'title', 'Please correct the following').dialog('option', 'height', 'auto').dialog("open");return false;		
	}
   
   
   $.blockUI(); 

 $.post('resetpass.php', $('#leftcolumn').find('input').serialize(), function(data) {
      
   if (data.indexOf("Success") > 0) {
    
    var msg = "<p style='font-size:14px; color:#ffffff;' align='left'>Your new password has been saved successfully, please login using your new credentials</p>";
    $.unblockUI(); 
    $("#generalmessage2").html(msg).dialog('option', 'title', 'Password Updated Successfully').dialog('option', 'height', 'auto').dialog("open");     
   
      
   } else {
   	
   	$.unblockUI(); 
   	
	$("#generalmessage").text("An error occurred updating your password, please try again").dialog('option', 'title', 'Please correct the following').dialog('option', 'height', 'auto').dialog("open");
	
	
   }
 }
);
    
    
}

function viewmoreprodinforrw(str,prodname)
{
    

  var sortorder = "";
  if ( $("#sortitems").length > 0 ) { 
 	sortorder = document.getElementById('sortitems').value;
  }
  
    
  var moreorless = "";
  if ( $("#moreorless").length > 0 ) { 
 	moreorless = document.getElementById('moreorless').value;
  }
  var page = "";
  if ( $("#page").length > 0 ) { 
 	page = document.getElementById('page').value;
  }
  
  
  document.getElementById('subheadingbar').style.display = 'none';
 
  
  var concat = "";
  
  if ($('#headerid').val() == "1")
  {
    concat = 'Wine/';
  }

  if ($('#headerid').val() == "2")
  {
    concat = 'Whiskey/';
  }

  if ($('#headerid').val() == "3")
  {
    concat = 'Spirits/';
  }

  if ($('#headerid').val() == "4")
  {
    concat = 'Bubbles/';
  }

  if ($('#headerid').val() == "5")
  {
    concat = 'Liqueurs/';
  }
  
  if ($('#headerid').val() == "6")
  {
    concat = 'Beers/';
  }

  if ($('#headerid').val() == "7")
  {
    concat = 'Softdrinks/';
  }

  if ($('#headerid').val() == "8")
  {
    concat = 'Accessorize/';
  }



  concat = "http://www.ngf.co.za/" + concat + prodname.replace(/^\s+/,"").replace(/ /g,"-") + "/" + $('#filterstext').val() + "_" + sortorder + "_" + moreorless + "_1_" + str;
  
  
  window.location = concat;  
  
  
}


function submitnewslet()
{
	
    if (ValidateEmail($('#newsletemail').val()) == false)
	{
	   alert("You need to enter a valid email address"); return false;
	}
	
	
   
   $.post('regnews.php', "email=" + $('#newsletemail').val(), function(data) {
      
   if (data.indexOf("Success") > 0) {
    
	

    $("#generalmessage").text("Thank you for registering the address " + $('#newsletemail').val() + " for the Norman Goodfellows newsletter. We look forward to sharing our exciting news with you in the future.").dialog('option', 'title', 'Congratulations').dialog('option', 'height', 'auto').dialog("open");
    
	$('#newsletemail').attr("value","");
	  
   } else {
   	
   	$.unblockUI(); 
   	
	$("#generalmessage").text(data).dialog('option', 'title', '').dialog('option', 'height', 'auto').dialog("open");
	
	
   }
 }
);
	
	
}


function dispdiv(str)
{
	
	if (str == "1")
	{
		
		document.getElementById("greatdealsinfo").innerHTML = "Enjoy the fantastic quality of Le Creuset, France's finest cookware.";
		document.getElementById("greatdealsimage").innerHTML = '<img src="images/lecreuset_03.jpg" border="0" class="featureimage" />';
		document.getElementById("greatdealslink").innerHTML = '<a href="http://www.ngf.co.za/section.php?menuid=8&filters=33*&orderfilter=&moreorless=" class="redlink">Get this deal <img src="images/redarrow.jpg" border="0" /></a>';
		
		
	}
	
		if (str == "2")
	{
		
		document.getElementById("greatdealsinfo").innerHTML = "Buy a Sprada coffee machine and receive R 500 in coffee free! Excludes Pod Machine.";
		document.getElementById("greatdealsimage").innerHTML = '<img src="images/sprada_03.jpg" border="0" class="featureimage" />';
		document.getElementById("greatdealslink").innerHTML = '<a href="http://www.ngf.co.za/section.php?menuid=8&filters=34*&orderfilter=sortselling&moreorless=" class="redlink">Get this deal <img src="images/redarrow.jpg" border="0" /></a>';
		
	}
	
		if (str == "3")
	{
		
		document.getElementById("greatdealsinfo").innerHTML = "Save 15% and get that set of Riedel wine glasses you have always wanted!";
		document.getElementById("greatdealsimage").innerHTML = '<img src="images/riedel_03.jpg" border="0" class="featureimage" />';
		document.getElementById("greatdealslink").innerHTML = '<a href="http://www.ngf.co.za/section.php?menuid=8&filters=30*&orderfilter=sortselling&moreorless=" class="redlink">Get this deal <img src="images/redarrow.jpg" border="0" /></a>';
		
	}
	
		if (str == "4")
	{
		
		document.getElementById("greatdealsinfo").innerHTML = "Fantastic Screwpull wine accessories at recession prices!";
		document.getElementById("greatdealsimage").innerHTML = '<img src="images/screwpull_03.jpg" border="0" class="featureimage" />';
		document.getElementById("greatdealslink").innerHTML = '<a href="http://www.ngf.co.za/section.php?menuid=8&filters=32*&orderfilter=sortselling&moreorless=" class="redlink">Get this deal <img src="images/redarrow.jpg" border="0" /></a>';
		
	}
	
	return false;
	
	
}

function entercomp(str)
{
	
var msg = "<p style='font-size:14px; color:#ffffff;' align='left'>You have entered information incorrectly, you need to attend to the following:</p>";
var nopass = 1;

    if ($('#compname' + str).val() == "")
	{
	   nopass = 2;	
	   msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter your name</p>"; 	
	}

    if ($('#compemail' + str).val() == "")
	{
	   nopass = 2;	
	   msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter your email addresss</p>"; 	
	}
	
		
    if (ValidateEmail($('#compemail' + str).val()) == false)
	{
	   nopass = 2;	
	   msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter a valid email address</p>"; 	
	}


    if ($('#comparea' + str).val() == "")
	{
	   nopass = 2;	
	   msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter your answer</p>"; 
	}

if (nopass == 2)
{
 $("#generalmessage").html(msg).dialog('option', 'title', 'Please correct the following').dialog('option', 'height', 'auto').dialog("open");return false;	
}
	
$.blockUI(); 

 $.post('entercomp.php', $('#compdiv' + str).find('input,textarea').serialize(), function(data) {
      
   if (data.indexOf("Success") > 0) {
    
	$.unblockUI();  
    $("#generalmessage").text("You have been registered for the competition!").dialog('option', 'title', 'Congratulations').dialog('option', 'height', 'auto').dialog("open");
    
	  
   } else {
   	
   	$.unblockUI(); 
   	
	$("#generalmessage").text(data).dialog('option', 'height', 'auto').dialog("open");
	
	
   }
 }
);
	
}

function enquire(str)
{
	
var msg = "<p style='font-size:14px; color:#ffffff;' align='left'>You have entered information incorrectly, you need to attend to the following:</p>";
var nopass = 1;

    if ($('#txtname').val() == "")
	{
	   nopass = 2;	
	   msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter your name</p>"; 	
	}

    if ($('#txtname').val() == "")
	{
	   nopass = 2;	
	   msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter your surname</p>"; 	
	}
	
		
    if (ValidateEmail($('#txtemail').val()) == false)
	{
	   nopass = 2;	
	   msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter a valid email address</p>"; 	
	}


    if ($('#comparea').val() == "")
	{
	   nopass = 2;	
	   msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter a description of your enquiry</p>"; 
	}

if (nopass == 2)
{
 $("#generalmessage").html(msg).dialog('option', 'title', 'Please correct the following').dialog('option', 'height', 'auto').dialog("open");return false;	
}
	
$.blockUI(); 

 $.post('enquire.php', $('#frmenquire').find('input,textarea').serialize(), function(data) {
      
   if (data.indexOf("Success") > 0) {
    
	$.unblockUI();  
    $("#generalmessage").text("Your enquiry has been logged, we will get back to you shortly").dialog('option', 'title', 'Enquiry Submitted').dialog('option', 'height', 'auto').dialog("open");
    
     history.go(-1);
    
	  
   } else {
   	
   	$.unblockUI(); 
   	
	$("#generalmessage").text(data).dialog('option', 'height', 'auto').dialog("open");
	
	
   }
 }
);
	
}


function SetHeader(str)
{
    document.getElementById("headerid").value = str;
}

function SetFilterText(str)
{
    document.getElementById("filterstext").value = str;
}

function blockcheck()
{
	alert("f");
	$.blockUI(); 
	alert("g");
}


function viewprodfromsitemap(str,headerid)

{
    
    
  var sortorder = "";
  if ( $("#sortitems").length > 0 ) { 
 	sortorder = document.getElementById('sortitems').value;
  }
 
     
  var moreorless = "";
    if ( $("#moreorless").length > 0 ) { 
 	moreorless = document.getElementById('moreorless').value;
  }
 

  
  var searchstr = "";
    if ( $("#searchBox").length > 0 ) { 
 
 	  searchstr = document.getElementById('searchBox').value;
 	  if (str == "0")
 	  {
 	   str = str + '*S' + searchstr ;
 	  }
 	  
    }
  
  concat = headerid + "/";
  

  concat = "http://www.ngf.co.za/" + concat + "products/" + str + "_" + sortorder + "_" + moreorless + "__";
  
  window.location = concat;
  
}
function viewprod(str)
{
 
 
 
 var origstr = str;
   
  var sortorder = "";
  if ( $("#sortitems").length > 0 ) { 
 	sortorder = document.getElementById('sortitems').value;
  }
 
     
  var moreorless = "";
    if ( $("#moreorless").length > 0 ) { 
 	moreorless = document.getElementById('moreorless').value;
  }
 
  var headerid = "";
    if ( $('#headerid').length > 0 ) { 
  	   headerid = document.getElementById('headerid').value;
    } else {
    	headerid = "1";
    }
 
  
  var searchstr = "";
    if ( $("#searchBox").length > 0 ) { 
 
 	  searchstr = document.getElementById('searchBox').value;
 	  if (str == "0")
 	  {
 	   str = str + '*S' + searchstr ;
 	  }
 	  
    }
  
 var concat = "";
   
 if (origstr != "0")
 {  
  
  if (headerid == "1")
  {
    concat = 'Wine/';
  }

  if (headerid == "2")
  {
    concat = 'Whiskey/';
  }

  if (headerid == "3")
  {
    concat = 'Spirits/';
  }

  if (headerid == "4")
  {
    concat = 'Bubbles/';
  }

  if (headerid == "5")
  {
    concat = 'Liqueurs/';
  }
  
  if (headerid == "6")
  {
    concat = 'Beers/';
  }

  if (headerid == "7")
  {
    concat = 'Softdrinks/';
  }

  if (headerid == "8")
  {
    concat = 'Accessorize/';
  }
  
  
  concat = "http://www.ngf.co.za/" + concat + "products/" + str + "_" + sortorder + "_" + moreorless + "__";
  
  window.location = concat;
  
  
 } else {
 
 	$.blockUI(); 
  
   $.post('http://www.ngf.co.za/searchgetcategory.php', "&filters=" + searchstr, function(data) {
    
    concat = data;   
    
    concat = "http://www.ngf.co.za/" + concat + "products/" + str + "_" + sortorder + "_" + moreorless + "__";
    
    $.unblockUI(); 
    
    window.location = concat;
     
   });
  
 
 }

  
  


}




function viewprodlandingpage(str)
{
    
    
     
 var origstr = str;
   
  var sortorder = "";
  if ( $("#sortitems").length > 0 ) { 
 	sortorder = document.getElementById('sortitems').value;
  }
 
     
  var moreorless = "";
    if ( $("#moreorless").length > 0 ) { 
 	moreorless = document.getElementById('moreorless').value;
  }
 
  var headerid = "";
    if ( $('#headerid').length > 0 ) { 
  	   headerid = document.getElementById('headerid').value;
    } else {
    	headerid = "1";
    }
 
  
  var searchstr = "";
    if ( $("#searchBox").length > 0 ) { 
 
 	  searchstr = document.getElementById('searchBox').value;
 	  if (str == "0")
 	  {
 	   str = str + '*S' + searchstr ;
 	  }
 	  
    }
    
    

 	$.blockUI(); 
  
   $.post('http://www.ngf.co.za/staging/testbase/searchgetcategory.php', "&filters=" + str, function(data) {
    
    concat = data;   
    
    concat = "http://www.ngf.co.za/staging/testbase/" + concat + "products/landingpage" + str + "_" + sortorder + "_" + moreorless + "__";
    
    $.unblockUI(); 
    
    window.location = concat;
     
   });    
    
    
}



function checklogin()
{
	
	var msg = "<p style='font-size:14px; color:#ffffff;' align='left'>You have entered information incorrectly, you need to attend to the following:</p>";
	var nopass = 1;

    if ($('#txtemail').val() == "")
	{
	   nopass = 2;	
	   msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter your email addresss</p>"; 	
	}
	
		
    if (ValidateEmail($('#txtemail').val()) == false)
	{
	   nopass = 2;	
	   msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter a valid email address</p>"; 	
	}
	
    if ($('#txtpass').val() == "")
	{
	   nopass = 2;	
	   msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter your password</p>"; 	
	}
	
	
if (nopass == 2)
{
 $("#generalmessage").html(msg).dialog('option', 'title', 'Please correct the following').dialog('option', 'height', 'auto').dialog("open");return false;	
}


    loginproceed();

}


function loginproceed()
{

$.blockUI(); 

 $.post('logincheck.php', $('#leftcolumn').find('input').serialize(), function(data) {
      
   if (data.indexOf("Success") > 0) {
         
    history.go(-1);
      
   } else {
   	
   	$.unblockUI(); 
   	
	$("#generalmessage").text(data).dialog('option', 'title', 'Please correct the following').dialog('option', 'height', 'auto').dialog("open");
	
	
   }
 }
);
	
		
}

function saveorder()
{

	$.blockUI(); 

 $.get('http://www.ngf.co.za/saveorder.php', {txtcomment: $("#txtcomment").val()}, function(data) {
    
	           
    $.unblockUI(); 
    $("#checkoutdivconfirm").text("Thank you, your order has been logged successfully").dialog('option', 'height', 'auto').dialog("open");
    
   
 }
);

}

function confirmorder()
{
	$("#orderdiv").dialog('option', 'height', 'auto').dialog("open");
}


function logout()
{
	
	$.get("http://www.ngf.co.za/logout.php", { prodid: ""} , function(data) {
	 
	 window.location= "index.php";

	});

}	

function CheckNumeric(e)
{
        
        if (window.event)
                key = event.keyCode
        else
                key = e.which
        // Was key that was pressed a numeric character (0-9) or backspace (8)?
        if ( key > 47 && key < 58 || key == 8 || key == 0)
                return; // if so, do nothing
        else // otherwise, discard character

                if (window.event) //IE
                        window.event.returnValue = null;                else 
//Firefox
                        e.preventDefault();
}

function checkreg(str)
{
	
	
	var msg = "<p style='font-size:14px; color:#ffffff;' align='left'>You have entered information incorrectly, you need to attend to the following:</p>";
	var nopass = 1;
	
	if ($('#txtname').val() == "")
	{
	   nopass = 2;	
	   msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter your name</p>"; 	
	}
	
	if ($('#txtsurname').val() == "")
	{
	   nopass = 2;	
	   msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter your surname</p>"; 	
	}
	

	if ($('#txttelh').val() == "")
	{
	   nopass = 2;	
	   msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter your telephone number</p>"; 	
	}
	

	
	
    if ($('#txtemailnew').val() == "")
	{
	        nopass = 2;	
	        msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter your email addresss</p>"; 	  			
	}
	
		
    if (ValidateEmail($('#txtemailnew').val()) == false)
	{
	        nopass = 2;	
	        msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter a valid email address</p>"; 	  			
	}
	
	
	if ($('#txtemailnew').val() != $('#txtemailnewconfirm').val())
	{
	        nopass = 2;	
	        msg = msg + "<p style='font-size:12px; color:#ffffff;'>Your email and confirmation address do not match</p>"; 	  			
	}
	
	
    if ($('#txtmobile').val() != "")
	{	  
	  var text = $('#txtmobile').val(); 
      var textlength = text.length;
 
	  if (textlength != 10) {
	        nopass = 2;	
	        msg = msg + "<p style='font-size:12px; color:#ffffff;'>Mobile needs to be 10 characters in length</p>"; 	  			

 	  }
	}
	
	

    if ($('#txtadd1').val() == "")
	{
	        nopass = 2;	
	        msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter address line 1</p>"; 	  			
	}
	

    if ($('#txtadd2').val() == "")
	{
	        nopass = 2;	
	        msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter address line 2</p>"; 	  			

	}
	
	
	if ($('#txtpostal').val() == "")
	{
	        nopass = 2;	
	        msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter your postal code</p>"; 	  			

	}

	
	
	if ($('#txtp').val() == "")
	{
	        nopass = 2;	
	        msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter a password</p>"; 	  			
	}
	

	if ($('#txtpconfirm').val() != $('#txtp').val())
	{
	        nopass = 2;	
	        msg = msg + "<p style='font-size:12px; color:#ffffff;'>Your passwords do not match</p>"; 	  			
	}
	
if (nopass == 2)
{
 $("#generalmessage").html(msg).dialog('option', 'title', 'Please correct the following').dialog('option', 'height', 'auto').dialog("open");return false;	
}

	initregandactivate();
	
}

function updateclientdetails()
{
	
	
		var msg = "<p style='font-size:14px; color:#ffffff;' align='left'>You have entered information incorrectly, you need to attend to the following:</p>";
	var nopass = 1;
	
	if ($('#txtname').val() == "")
	{
	   nopass = 2;	
	   msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter your name</p>"; 	
	}
	

	if ($('#txtsurname').val() == "")
	{
	   nopass = 2;	
	   msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter your surname</p>"; 	
	}
	
	if ($('#txttelh').val() == "")
	{
	   nopass = 2;	
	   msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter your telephone number</p>"; 	
	}
	
	
      var text2 = $('#txttelh').val(); 
      var textlength2 = text2.length;
 
	  if (textlength2 != 10) {
	        nopass = 2;	
	        msg = msg + "<p style='font-size:12px; color:#ffffff;'>Telephone number needs to be 10 characters in length</p>"; 	  	
 	  }

	
	
	
    if ($('#txtmobile').val() != "")
	{	  
	  var text = $('#txtmobile').val(); 
      var textlength = text.length;
 
	  if (textlength != 10) {
	        nopass = 2;	
	        msg = msg + "<p style='font-size:12px; color:#ffffff;'>Mobile needs to be 10 characters in length</p>"; 	  			

 	  }
	}


	if ($('#txtemailnew').val() != $('#txtemailnewconfirm').val())
	{
	        nopass = 2;	
	        msg = msg + "<p style='font-size:12px; color:#ffffff;'>Your email and confirmation address do not match</p>"; 	  			
	}
	
		
	
  if ($('#txtadd1').val() == "")
	{
	        nopass = 2;	
	        msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter address line 1</p>"; 	  			
	}
	

    if ($('#txtadd2').val() == "")
	{
	        nopass = 2;	
	        msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter address line 2</p>"; 	  			

	}
	
	
	if ($('#txtpostal').val() == "")
	{
	        nopass = 2;	
	        msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter your postal code</p>"; 	  			

	}


	
	
	if ($('#txtp').val() == "")
	{
	        nopass = 2;	
	        msg = msg + "<p style='font-size:12px; color:#ffffff;'>You need to enter a password</p>"; 	  			
	}
	

	if ($('#txtpconfirm').val() != $('#txtp').val())
	{
	        nopass = 2;	
	        msg = msg + "<p style='font-size:12px; color:#ffffff;'>Your passwords do not match</p>"; 	  			
	}
	
if (nopass == 2)
{
 $("#generalmessage").html(msg).dialog('option', 'title', 'Please correct the following').dialog('option', 'height', 'auto').dialog("open");return false;	
}

initregandactivatefromemail();
	
	
	
}



function initregandactivatefromemail()
{
	
 
 $.blockUI(); 


 $.post('userregandactivate.php', $('#leftcolumn').find('input').serialize(), function(data) {
      
   if (data.indexOf("Success") > 0) {
         
      
      $.unblockUI(); 
      window.location = 'thankyou.php';
	        
   } else {
   	
   	$.unblockUI(); 
   	
	$("#generalmessage").dialog('option', 'title', 'Registration').dialog('option', 'height', 'auto').text("This email address has already been registered").dialog("open");
	
	
   }
 }
);
	
	
}



function initregandactivate()
{
	
 
 $.blockUI(); 

  var url = 'http://www.ngf.co.za/dispwaittoactivate.php';
    var fromelse = 0;
    
    if ($('#frompopup').val() == "1")
    {
        url = 'http://www.ngf.co.za/regconfirm.php';
        fromelse = 1;
    }
    
    if ($('#frompopup').val() == "2")
    {
        url = 'http://www.ngf.co.za/newsconfirm.php';
        fromelse = 1;
    }



 $.post('userreg.php', $('#leftcolumn').find('input').serialize(), function(data) {
      
   if (data.indexOf("Success") > 0) {
         
     if (fromelse == 0)
     {    
       $('#leftcolumn').hide().load(url,function(){
       $(this).fadeIn('slow');
       $.unblockUI(); 
       });
      } else {
       window.location = url; 
      }
      
   } else {
   	
   	$.unblockUI(); 
   	
	$("#generalmessage").dialog('option', 'title', 'Registration').dialog('option', 'height', 'auto').text("This email address has already been registered").dialog("open");
	
	
   }
 }
);
	
	
}

function addtocart(str)
{
	
  $.blockUI(); 
 
 $.get("http://www.ngf.co.za/addtocart.php", { prodid: str, qty: $('#txtqty' + str).val() },function(){
 
 $('#shoppingcart').hide().load('http://www.ngf.co.za/dispcartrefresh.php?dispcartref=',function(){
 $(this).fadeIn('slow');
 
 $('#topmenudiv').hide().load('http://www.ngf.co.za/topmenu.php',function(){
 $(this).fadeIn('slow');
 });
 
 $.unblockUI(); 
 
});

} );
	
}

function increasebasket(str)
{
 
 $.blockUI(); 
 
 $.get("http://www.ngf.co.za/increasecart.php", { cartid: str } ,function(){
 
 $('#shoppingcart').hide().load('http://www.ngf.co.za/dispcartrefresh.php?dispcartref=',function(){
 $(this).fadeIn('slow');
 
 $('#topmenudiv').hide().load('http://www.ngf.co.za/topmenu.php',function(){
 $(this).fadeIn('slow');
 });
 
 } );
 
 $.unblockUI(); 
 
});

}

function decreasebasket(str)
{
 
 $.blockUI(); 
 
 $.get("http://www.ngf.co.za/decreasebasket.php", { cartid: str },function(){
 
 $('#shoppingcart').hide().load('http://www.ngf.co.za/dispcartrefresh.php?dispcartref=',function(){
 $(this).fadeIn('slow');
 
 $('#topmenudiv').hide().load('http://www.ngf.co.za/topmenu.php',function(){
 $(this).fadeIn('slow');
 });
 
 $.unblockUI(); 

});
 
});

}


function increasebasketF(str)
{
 
 $.blockUI(); 
 
 $.get("http://www.ngf.co.za/increasecart.php", { cartid: str },function(){
 
 $('#checkoutdiv').hide().load('http://www.ngf.co.za/orderitemsfull.php',function(){
 $(this).fadeIn('slow');
 
 $('#topmenudiv').hide().load('http://www.ngf.co.za/topmenu.php',function(){
 $(this).fadeIn('slow');
 
  $('#shoppingcart').hide().load('http://www.ngf.co.za/dispcartrefresh.php?dispcartref=',function(){
 $(this).fadeIn('slow');
 });
 
 }); 
 
 $.unblockUI(); 
 
});

});

}

function increasebasketFCO(str)
{
 
 $.blockUI(); 
 
 $.get("http://www.ngf.co.za/increasecart.php", { cartid: str },function(){
 
 $('#leftcolumn').load('http://www.ngf.co.za/checkoutdel.php', $('#leftcolumn').find('input,select').serialize(),function(data){
 $(this).fadeIn('slow');
 
 $('#topmenudiv').hide().load('http://www.ngf.co.za/topmenu.php',function(){
 $(this).fadeIn('slow');
 

 
 }); 
 
 $.unblockUI(); 
 
});

});

}

function emptybasketdb()
{
 
 $.blockUI(); 
 
 $.get("http://www.ngf.co.za/emptybasket.php", { cartid: "" },function(){
 
 $('#checkoutdiv').hide().load('http://www.ngf.co.za/orderitemsfull.php',function(){
 $(this).fadeIn('slow');
 
 $('#topmenudiv').hide().load('http://www.ngf.co.za/topmenu.php',function(){
 $(this).fadeIn('slow');
 
 $('#shoppingcart').hide().load('http://www.ngf.co.za/dispcartrefresh.php?dispcartref=',function(){
 $(this).fadeIn('slow');
 });
 
 }); 
 
 $.unblockUI(); 
});
 
});
}

function emptybasketdbs()
{
 
 $.blockUI(); 
 
 $.get("http://www.ngf.co.za/emptybasket.php", { cartid: "" } ,function(){
 
 $('#shoppingcart').hide().load('http://www.ngf.co.za/dispcartrefresh.php?dispcartref=',function(){
 $(this).fadeIn('slow');
 
 $('#topmenudiv').hide().load('http://www.ngf.co.za/topmenu.php',function(){
 $(this).fadeIn('slow');
 
 $('#shoppingcart').hide().load('http://www.ngf.co.za/dispcartrefresh.php?dispcartref=',function(){
 $(this).fadeIn('slow');
 });
 
 }); 
 
 $.unblockUI(); 

});
});

}

function emptybasket()
{
	$("#clearorder").dialog('option', 'height', 'auto').dialog("open");
}

function removeitem(str)
{

 $.blockUI(); 
 
 $.get("http://www.ngf.co.za/removeitem.php", { cartid: str } ,function(){
 
 $('#checkoutdiv').hide().load('http://www.ngf.co.za/orderitemsfull.php',function(){
 $(this).fadeIn('slow');
 
 $('#topmenudiv').hide().load('http://www.ngf.co.za/topmenu.php',function(){
 $(this).fadeIn('slow');
 
 $('#shoppingcart').hide().load('http://www.ngf.co.za/dispcartrefresh.php?dispcartref=',function(){
 $(this).fadeIn('slow');
 });
 
 }); 
 
 $.unblockUI(); 
 
});
});
	
}

function removeitemCO(str)
{

 $.blockUI(); 
 
 $.get("http://www.ngf.co.za/removeitem.php", { cartid: str } ,function(){
 
 $('#leftcolumn').load('http://www.ngf.co.za/checkoutdel.php', $('#leftcolumn').find('input,select').serialize(),function(data){
 $(this).fadeIn('slow');
 
 $('#topmenudiv').hide().load('http://www.ngf.co.za/topmenu.php',function(){
 $(this).fadeIn('slow');
 
 $('#shoppingcart').hide().load('http://www.ngf.co.za/dispcartrefresh.php?dispcartref=',function(){
 $(this).fadeIn('slow');
 });
 
 }); 
 
 $.unblockUI(); 
 
});
});
	
}

function decreasebasketF(str)
{
 
 $.blockUI(); 
 
 $.get("http://www.ngf.co.za/decreasebasket.php", { cartid: str }  ,function(){
 
 $('#checkoutdiv').hide().load('http://www.ngf.co.za/orderitemsfull.php',function(){
 $(this).fadeIn('slow');
 
 $('#topmenudiv').hide().load('http://www.ngf.co.za/topmenu.php',function(){
 $(this).fadeIn('slow');
 }); 
 
 $.unblockUI(); 

}); 
});

}

function decreasebasketFCO(str)
{
 
 $.blockUI(); 
 
 $.get("http://www.ngf.co.za/decreasebasket.php", { cartid: str }  ,function(){
 
$('#leftcolumn').load('http://www.ngf.co.za/checkoutdel.php', $('#leftcolumn').find('input,select').serialize(),function(data){
 $(this).fadeIn('slow');
 
 $('#topmenudiv').hide().load('http://www.ngf.co.za/topmenu.php',function(){
 $(this).fadeIn('slow');
 }); 
 
 $.unblockUI(); 

}); 
});

}


function increase(str) {
	
  var textbox = document.getElementById('txtqty' + str);
  textbox.value = parseInt(textbox.value) + 1;

}

function decrease(str) {
	
  var textbox = document.getElementById('txtqty' + str);
  
  if (textbox.value == 0) {
  	textbox.value = "0";
  } else {
   textbox.value = parseInt(textbox.value) - 1;
  }

}

function FillCrumbs(str)
{
	
	$('#crumbs').hide().load('crumbs.php?filters=' + str,function(){
      $(this).fadeIn('slow');
    });
}

function viewsectall(str)
{
	
	  var sortorder = "";
  if ( $("#sortitems").length > 0 ) { 
 	sortorder = document.getElementById('sortitems').value;
  }
 
     
  var moreorless = "";
    if ( $("#moreorless").length > 0 ) { 
 	moreorless = document.getElementById('moreorless').value;
  }
 
  var headerid = "";
    if ( $('#headerid').length > 0 ) { 
  	   headerid = document.getElementById('headerid').value;
    } else {
    	headerid = "1";
    }
 
  
  var searchstr = "";
    if ( $("#searchBox").length > 0 ) { 
 
 	  searchstr = document.getElementById('searchBox').value;
 	  if (str == "0")
 	  {
 	   str = str + '*S' + searchstr ;
 	  }
 	  
    }
  
  window.location = 'http://www.ngf.co.za/sectionviewall.php?menuid=' + headerid + '&dispall=' + str;
  
  


}

function viewallprodcat(str)
{
	
	if (document.getElementById("morecat" + str).style.display == 'none')
	{
		document.getElementById("morecat" + str).style.display = '';
		document.getElementById("searchlink" + str).innerHTML = '<a href="#"  class="whitelink" onclick="viewallprodcat(\'' + str + '\');return false;"><img src="images/whitearrowback.jpg" border="0" /> Less </a>';
		
	} else {
		document.getElementById("morecat" + str).style.display = 'none';
		document.getElementById("searchlink" + str).innerHTML = '<a href="#"  class="whitelink" onclick="viewallprodcat(\'' + str + '\');return false;"> More <img src="images/whitearrow.jpg" border="0" /> </a>';
	}
	
	
	
}

function searchagain()
{


  var sortorder = "";
  if ( $("#sortitems").length > 0 ) { 
 	sortorder = document.getElementById('sortitems').value;
  }
  
    
  var moreorless = "";
    if ( $("#moreorless").length > 0 ) { 
 	moreorless = document.getElementById('moreorless').value;
  }
  
  document.getElementById('subheadingbar').style.display = 'none';
 
 
 
   var concat = "";
  
  if ($('#headerid').val() == "1")
  {
    concat = 'Wine/';
  }

  if ($('#headerid').val() == "2")
  {
    concat = 'Whiskey/';
  }

  if ($('#headerid').val() == "3")
  {
    concat = 'Spirits/';
  }

  if ($('#headerid').val() == "4")
  {
    concat = 'Bubbles/';
  }

  if ($('#headerid').val() == "5")
  {
    concat = 'Liqueurs/';
  }
  
  if ($('#headerid').val() == "6")
  {
    concat = 'Beers/';
  }

  if ($('#headerid').val() == "7")
  {
    concat = 'Softdrinks/';
  }

  if ($('#headerid').val() == "8")
  {
    concat = 'Accessorize/';
  }




  concat = "http://www.ngf.co.za/" + concat + "products" + "/" + $('#filterstext').val() + "_" + sortorder + "_" + moreorless + "_" + $('#page').val() + "_";
  

  
  window.location = concat;
 

	
}

function searchagainmore(str)
{

  var sortorder = "";
  if ( $("#sortitems").length > 0 ) { 
 	sortorder = document.getElementById('sortitems').value;
  }
  
  document.getElementById('subheadingbar').style.display = 'none';
 
 
    var concat = "";
  
  if ($('#headerid').val() == "1")
  {
    concat = 'Wine/';
  }

  if ($('#headerid').val() == "2")
  {
    concat = 'Whiskey/';
  }

  if ($('#headerid').val() == "3")
  {
    concat = 'Spirits/';
  }

  if ($('#headerid').val() == "4")
  {
    concat = 'Bubbles/';
  }

  if ($('#headerid').val() == "5")
  {
    concat = 'Liqueurs/';
  }
  
  if ($('#headerid').val() == "6")
  {
    concat = 'Beers/';
  }

  if ($('#headerid').val() == "7")
  {
    concat = 'Softdrinks/';
  }

  if ($('#headerid').val() == "8")
  {
    concat = 'Accessorize/';
  }



  concat = "http://www.ngf.co.za/" + concat + "products" + "/" + $('#filterstext').val() + "_" + sortorder + "_" + str + "_" + $('#page').val() + "_";
  
  window.location = concat;
  
  
	
	
}


function searchprodPages(str)
{
	
	
  $.blockUI(); 
  
  var sortorder = "";
  if ( $("#sortitems").length > 0 ) { 
 	sortorder = document.getElementById('sortitems').value;
  }
  
  var moreorless = "";
    if ( $("#moreorless").length > 0 ) { 
 	moreorless = document.getElementById('moreorless').value;
  }
  
  
  document.getElementById('subheadingbar').style.display = 'none';
 
 
  
    var concat = "";
  
  if ($('#headerid').val() == "1")
  {
    concat = 'Wine/';
  }

  if ($('#headerid').val() == "2")
  {
    concat = 'Whiskey/';
  }

  if ($('#headerid').val() == "3")
  {
    concat = 'Spirits/';
  }

  if ($('#headerid').val() == "4")
  {
    concat = 'Bubbles/';
  }

  if ($('#headerid').val() == "5")
  {
    concat = 'Liqueurs/';
  }
  
  if ($('#headerid').val() == "6")
  {
    concat = 'Beers/';
  }


  if ($('#headerid').val() == "7")
  {
    concat = 'Softdrinks/';
  }


  if ($('#headerid').val() == "8")
  {
    concat = 'Accessorize/';
  }


  concat = "http://www.ngf.co.za/" + concat + "products" + "/" + $('#filterstext').val() + "_" + sortorder + "_" + moreorless + "_" + str + "_";
  
  
 window.location = concat;
  
  

		
	
}



function isValidCreditCard(type, ccnum) {
   if (type == "Visa") {
      // Visa: length 16, prefix 4, dashes optional.
      var re = /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/;
   } else if (type == "MC") {
      // Mastercard: length 16, prefix 51-55, dashes optional.
      var re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/;
   } else if (type == "Disc") {
      // Discover: length 16, prefix 6011, dashes optional.
      var re = /^6011-?\d{4}-?\d{4}-?\d{4}$/;
   } else if (type == "AmEx") {
      // American Express: length 15, prefix 34 or 37.
      var re = /^3[4,7]\d{13}$/;
   } else if (type == "Diners") {
      // Diners: length 14, prefix 30, 36, or 38.
      var re = /^3[0,6,8]\d{12}$/;
   }
   if (!re.test(ccnum)) return false;
   // Remove all dashes for the checksum checks to eliminate negative numbers
   ccnum = ccnum.split("-").join("");
   // Checksum ("Mod 10")
   // Add even digits in even length strings or odd digits in odd length strings.
   var checksum = 0;
   for (var i=(2-(ccnum.length % 2)); i<=ccnum.length; i+=2) {
      checksum += parseInt(ccnum.charAt(i-1));
   }
   // Analyze odd digits in even length strings or even digits in odd length strings.
   for (var i=(ccnum.length % 2) + 1; i<ccnum.length; i+=2) {
      var digit = parseInt(ccnum.charAt(i-1)) * 2;
      if (digit < 10) { checksum += digit; } else { checksum += (digit-9); }
   }
   if ((checksum % 10) == 0) return true; else return false;
}





function ValidateEmail(email)

{

  var fEmailOK = true;

  var num = 0;



  for (var i = 0; i < email.length; ++i) {

    var ch = email.charAt(i);

    if (ch == "@") {

      num = num + 1;

    }

  }

  if (num != "1")

    return false;



  var num2 = 0;

  for (var i = 0; i<email.length; ++i) {

    var ch = email.substring(i,i+2);

    if ((ch == "..")||(ch == ".@")||(ch == "@.")) {

      return false;

    }

  }

  if (email.length < 4)

    return false;

  else if (email.lastIndexOf(' ') != -1)

    return false;

  else if ((email.substring(0,1) == ".")||(email.substring(0,1) == "@")) {

    return false;

  }

  else if (email.lastIndexOf('\'') != -1)

    return false;

  else if ((i = email.lastIndexOf('@')) == -1)

    return false;

  else { // Get substring

    var tail = email.substring(i+1, email.length);

    if (tail.length < 3)

      return false;

    else if ((i = tail.lastIndexOf('.')) == -1)

      return false;

    else {

      var tailend = tail.substring(i+1, tail.length);

      if (tailend.length == 0)

        return false;

    }

  }

  return true;

}
