$(function() {
	$('a.lightbox').lightBox(); // Select all links with lightbox class
});

/* Display tooltip on sidebar */
function showtips(id) {
	document.getElementById('msg' + id).style.display='block';
}

function hidetips(id) {
	document.getElementById('msg' + id).style.display='none';
}

/* Display product image in browse page */
function showimg(id) {
	document.getElementById('img' + id).style.display='';
}

function hideimg(id) {
	document.getElementById('img' + id).style.display='none';
}



function DoDel(iserial)
{
	if (confirm("Are you sure?"))
	{
		window.location.href=iserial;
	}
}


function show_window(sid,h,w) {

  var popup = window.open("aa", "News",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=' + h + ',height=' + w);
  popup.location = sid;

}

function show_bar_window(sid,h,w) {

  var popup = window.open("", "News",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=' + h + ',height=' + w);
  popup.location = sid;

}


function checkUncheckAll(theElement) {
	 //documentation for this script at http://www.shawnolson.net/a/693/
    var theForm = theElement.form, z = 0;
    while (theForm[z].type == 'checkbox' && theForm[z].name != 'checkall') {
     theForm[z].checked = theElement.checked;
     z++;
    }
}


function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}


function isValidEmail(str) {
   return true; //(str.indexOf(".") > 0) && (str.indexOf("@") > 0);
}

function subscribe_newsletter() {
	
	var name=$("#subscribe_name").attr('value');
	var email=$("#subscribe_email").attr('value');
	
	var fail=0; error="";
	
	if ((name=="") || (name=="Enter your name")) { error='Please enter your name\n'; fail=1; }
	if ((email=="") || (email=="Enter your email address")) { error+='Please enter your Email Address'; fail=1; }
	if ((!isValidEmail(email)) && (email!="Enter your email address")) { error+='Please enter correct Email Address'; fail=1; }

	if (fail==0) {
		var dataString="pg=subscribe&name=" + name + "&email=" + email;
		
		$.ajax({  
		   type: "GET",  
		   url: "index.php",  
		   data: dataString,  
		   success: function(msg) {  
				document.getElementById('newsletter').innerHTML='<div class="message-text">' + msg + '</div>';
		   }  
		});  
	} else {
		alert(error);
	}
     
}

/* Switch on/off to textfield background texture */
function smarttip_focus(obj) {
	if (obj.value=="Enter your email address" || obj.value=="Enter your name") { obj.value=''; obj.style.color='#000000';}
	

}

function smarttip_blur(obj,msg) {
	if (obj.value=="") { 
		if (obj.name=="name") {
		 obj.value="Enter your name";
		 obj.style.color='#999999';	 
		} else {
		 obj.value="Enter your email address";
		 obj.style.color='#999999';	 
		}
	}
	
}




	
