function showSection(parm, imgx,imgl){
var v = document.getElementById(parm); //Store reference to target division.
// var r=mid.firstChild; //Store reference to division to be moved.
sink.appendChild(curr);
try {
mid.appendChild(v);
}
catch (e) {
mid.appendChild(curr);
}
curr = v;
sink.appendChild(currimg);
currimg = document.getElementById(imgx);
right.appendChild(currimg);
sink.appendChild(currimgl);
currimgl = document.getElementById(imgl);
left.appendChild(currimgl);
return;
}
function changeClass(id)
{
document.getElementById('index').className="plain";
document.getElementById('about').className="plain";
document.getElementById('products').className="plain";
document.getElementById('lab').className="plain";
document.getElementById('rbs').className="plain";
document.getElementById('bi').className="plain";
document.getElementById('links').className="plain";
document.getElementById('contact').className="plain";
document.getElementById('order').className="plain";
document.getElementById(id).className="current";

}

var q=0;
var c=0;
var n=0;
items = new Array(50);

//Function to validate quantity field and to get values from catalog form.
function getDetails(itemid,cost,quan,ship,field) {

var i;
if(quan==""){
alert("Fill the number");
return false;
}
else
{
alert("Your value has been added successfuly");
var chk="quan"+field;
document.getElementsByName(chk)[0].value="";

}
for (i = 0; i < quan.length; i++){
var c = quan.charAt(i);
if (((c < "0") || (c > "9"))){
alert("enter the number");
return false;
}
}
checkCart(itemid,cost,quan,ship);
updateCartDisplay();
}

//Function to generate cartvalues (i.e) data to be stored in cookies.
function checkCart(itemid,cost,quan,ship) {

var cartValue = getCart('ordercart');
var array = getCartArray('ordercart');
var match_found=false;
var cart_size = array.length;
for (var i=0;i<cart_size;i++) {
if(itemid==array[i][0]) {
array[i][3] = parseInt(array[i][3])+parseInt(quan);
match_found = true;
break;
}
}

if (!match_found) { /* This is a new item_id */
/* Add new item_id at the bottom of the array */
array[cart_size] = new Array();
array[cart_size][0] = itemid;
array[cart_size][1] = cost;
array[cart_size][2] = ship;
array[cart_size][3] = quan;

}


/* Clear the entire Cart */
clearCart('ordercart');
cartValue = null;


/* Recraete the cart by going over the array */
for (i=0;i<array.length;i++) {
if (cartValue==null) {
cartValue = "itemid:" + array[i][0]
+ "/price:" + array[i][1]
+ "/shipcost:" + array[i][2]
+ "/qty:" + array[i][3];
}
else {
cartValue = cartValue
+ "#itemid:" + array[i][0]
+ "/price:" + array[i][1]
+ "/shipcost:" + array[i][2]
+ "/qty:" + array[i][3];
}
}

setCart('ordercart',cartValue);

}
//Function to generate cookies.
function getCart(ordercart){

nameEQ = ordercart + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));
}
return null;
}

//Function to set cartvalue.
function setCart(cartName,cartValue){
document.cookie = cartName+"="+escape(cartValue);

}

//Function to clear cart.
function clearCart(cartname){

document.cookie = cartname+"="+"'' ; expires=Thu, 2 Aug 2001 20:47:11 UTC;";
return;
}
function isCartEmpty(ordercart, pmt){
	var the_cookie = getCart('ordercart');
	if (the_cookie == null) {
		if(pmt == 'Y') {
			alert("Cart is empty");
			location.href="catalog.php?option=AUTO";
		}
		return true;
	}
	else return false;
}

function isCartempty(ordercart){
var the_cookie = getCart('ordercart');
if (the_cookie == null) {
alert("Cart is empty");
return false;
}
document.catalog.submit();
}

//Function to create cart array.
function getCartArray(ordercart) {

var the_cookie = getCart('ordercart');
cart = new Array();
if (the_cookie == null) {
return cart;
}
else {
subitem_split=new Array(4);
var i, j, k,g, temp;
var h=0;
split_value = new Array();
split_value = the_cookie.split("#");
for (i=0; i<split_value.length; i++) {
cart[i] = new Array(4);
subitem_split = split_value[i].split("/");
for (j=0; j<subitem_split.length; j++) {
temp = subitem_split[j];
k = temp.indexOf(":");
cart[i][j] = temp.substring(k+1,temp.length);

}
}
return cart;

}
}

//New Function for displaying total number of items and total cost
function updateCartDisplay() {

var p=0;
var x=0;

	if (isCartEmpty('ordercart','N')) {
		p = 0;
		x = 0 ;
	}
	else {
			var array = getCartArray('ordercart');
			var length = array.length;
		    	for (var i=0;i<length;i++) {
				x++
				p = p+(parseInt(array[i][1])*parseInt(array[i][3]))+(parseInt(array[i][2])*parseInt(array[i][3]));
				}
			}
			document.getElementById("totalitom").innerHTML=x;
			document.getElementById("totalprice").innerHTML="$"+moneyFormat(p);
			
}



//Function to update cart values.
function checkSelected(){
	
	var grp = document.getElementsByName("checkgroup");
		
	for(var i=grp.length-1; i>=0; i--) {
		if (!grp[i].checked) {
		cartArray.splice(i,1);
		}
		
	}
	if(cartArray.length==0) {
		alert("YOUR CART IS EMPTY");
		location.href="catalog.php?option=MaxLife";
		clearCart('ordercart');
	}
	else {
		setNewCart('ordercart');
	}
	
	return(0);

}

//Function to create new cartvalues after updation.
function setNewCart(cartname) {

clearCart(cartname);
var cartValue="";
for (var k=0; k<cartArray.length; k++) {
if (cartValue==""){
cartValue = "itemid:"+cartArray[k][0]+
"/price:"+cartArray[k][1]+
"/shipcost:"+cartArray[k][2]+
"/qty:"+cartArray[k][3];
}
else{
cartValue = cartValue+"#itemid:"+cartArray[k][0]+
"/price:"+cartArray[k][1]+
"/shipcost:"+cartArray[k][2]+
"/qty:"+cartArray[k][3];
}

}
setCart(cartname,cartValue);
document.cart1.submit();
}

//Function to disable cart table and to make user detail form visible.
function privacyselect(xForm){

for(var i=0;i<document.forms[0].length;i++){
document.forms[0].elements[i].disabled=true;
}

document.getElementById("shippingbillinghide").style.visibility = "visible";

}

//Function for e-mail validation
function mailVal(){
var str=document.buy.emailid.value;
var at="@";
var dot=".";
var lat=str.indexOf(at);
var lstr=str.length;
var ldot=str.indexOf(dot);
if ((str==null)||(str=="")){
document.buy.emailid.focus();
return false;
}
if (str.indexOf(at)==-1 || str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr||
str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr||
str.indexOf(at,(lat+1))!=-1||str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot||
str.indexOf(dot,(lat+2))==-1||str.indexOf(" ")!=-1){
document.buy.emailid.focus();
return false;
}
return true;
}

//Function to validate phone numbers.
function phoneVal(phone){
var checkVal="0123456789";
var objVal=phone;
var ok=true;
if(objVal.length == 10){}
else
{
return false;
}
if(objVal==null||objVal==""){
//alert("Please enter contact number!")
return false;
}
for(i=0;i<objVal.length;i++){
var myChar=objVal.charAt(i);
for(j=0;j<checkVal.length;j++)
if (myChar==checkVal.charAt(j)) break;
if(j==checkVal.length){
ok=false;
break;
}
}
if(!ok){
//alert("This is not a valid entry. Please enter a number!");
return false;
}
return true;
}

//Function for name validation
function isAlphabetic(aa) {

if(aa=="")
{
alert("Enter class name");
return false;
}
var ename=aa;
if(ename==null||ename=="")
{
alert("Please fill the");
return false;
}
var chr = new Array(15);
chr = ename.split('');
for (var i = 0; i < chr.length; i++)
{
if ((chr[i] < 'A' || chr[i] > 'Z')&& (chr[i] < 'a' || chr[i] > 'z'))
{
if (!(chr[i] == ' '))
{
alert("Invalid name , Enter only Characters");
return false;
}
}
}
return true;
}


//Function to validate numeric values.
function isNumeric(val) {

var i;
for (i = 0; i < val.length; i++)
{
var c = val.charAt(i);
if (((c < "0") || (c > "9")))
{
return false;
}
}
return true;
}

//Function to validate card expiry date.
function isCardexp(dt){
var thedate = new Date();
var theyear = thedate.getFullYear();
var themonth = thedate.getMonth() + 1;
var theday = thedate.getDate();
var curr = theyear + "-" + themonth + "-" + theday;
if (dt <= curr){
return false;
}
return true;
}

//Function for User detail form validation.
function validate(){

if(document.buy.custname1.value == ""){
alert("Please enter your name or Organization name");
document.buy.custname1.focus();
return false;
}
if(!isAlphabetic(document.buy.custname1.value)) {
document.buy.custname1.focus();
return false;
}

if(document.buy.shipaddr.value == ""){
alert("Please enter shipping address");
document.buy.shipaddr.focus();
return false;
}
if(document.buy.shiptown.value == ""){
alert("Please enter the town/suburban");
document.buy.shiptown.focus();
return false;
}

if(document.buy.shipstate.value =="SELECT" ){
alert("Please select a state or teritory");
document.buy.shipstate.focus();
return false;
}

if(document.buy.shippcode.value == ""){
alert("Please enter the postalcode");
document.buy.shippcode.focus();
return false;
}

if(!isNumeric(document.buy.shippcode.value)){
alert("Please enter a valid postalcode");
document.buy.shippcode.focus();
return false;
}

if(document.buy.lphone.value == ""){
alert("Please enter daytime phone number");
document.buy.lphone.focus();
return false;
}

if(!phoneVal(document.buy.lphone.value)){
alert("Please enter a 10 digit daytime phone number");
document.buy.lphone.focus();
return false;
}

if(!(document.buy.mphone.value) == ""){
if(!phoneVal(document.buy.mphone.value)){
alert("Please enter a valid mobile number or leave it blank");
document.buy.mphone.focus();
return false;
}
}

if(document.buy.emailid.value == ""){
alert("Please enter emailid field");
document.buy.emailid.focus();
return false;
}

if(!mailVal()){
alert("Please enter valid emailid");
document.buy.emailid.focus();
return false;
}

if(document.buy.custname2.value == ""){
alert("Please enter your name or Organization name for billing");
document.buy.custname2.focus();
return false;
}

if(!isAlphabetic(document.buy.custname2.value)) {
document.buy.custname2.focus();
return false;
}

if(document.buy.custaddr.value == ""){
alert("Please enter the address");
document.buy.custaddr.focus();
return false;
}
if(document.buy.town.value == ""){
alert("Please enter the town/suburban");
document.buy.town.focus();
return false;
}

if(document.buy.state.value =="SELECT" ){
alert("Please select a state or teritory");
document.buy.state.focus();
return false;
}
if(document.buy.pcode.value == ""){
alert("Please enter the postalcode");
document.buy.pcode.focus();
return false;
}

if(!isNumeric(document.buy.pcode.value)){
alert("Please enter valid postalcode");
document.buy.pcode.focus();
return false;
}
if(document.buy.lphone1.value == ""){
alert("Please enter a 10 digit daytime phone number");
document.buy.lphone1.focus();
return false;
}

if(!phoneVal(document.buy.lphone1.value)){
alert("Please enter a 10 digit daytime phone number");
document.buy.lphone1.focus();
return false;
}

if(!(document.buy.mphone1.value) == ""){
if(!phoneVal(document.buy.mphone1.value)){
alert("Please enter valid mobile number or leave it blank");
document.buy.mphone1.focus();
return false;
}
}
getFormValues();
document.buy.submit();
}


//Function to copy similar address in case of User detail and shipping address.
function copyAddress(){
var x = document.buy;
if(x.address.checked){
x.custname2.value = x.custname1.value;
x.custaddr.value = x.shipaddr.value;
x.town.value = x.shiptown.value;
x.state.value = x.shipstate.value;
x.pcode.value = x.shippcode.value;
x.lphone1.value = x.lphone.value;
x.mphone1.value = x.mphone.value;
}
else{
x.custname2.value = "";
x.custaddr.value = "";
x.town.value = "";
x.state.value = "";
x.pcode.value = "";
x.lphone1.value = "";
x.mphone1.value = "";
}
}

//Function to get vakues from cart table.
function getFormValues(){
document.buy.cartvalues.value= getCart('ordercart');
document.buy.gtotal.value=parseInt(document.getElementById("gtol").innerHTML);

}

//Function reset.

function reset1(){


var a = document.buy
a.custname1.value = "";
a.shipaddr.value = "";
a.shiptown.value = "";
a.shipstate.value = "";
a.shippcode.value = "";
a.lphone.value = "";
a.mphone.value = "";
a.emailid.value = "";
a.custname2.value = "";
a.custaddr.value = "";
a.town.value = "";
a.state.value = "";
a.pcode.value = "";
a.lphone1.value = "";
a.mphone1.value = "";
}

//validation for contactdeatails enquiry form

function enquiry_validate(){
                var name = document.enquiry.name.value;
                if (name == null || name == "") {
                    alert("Please enter your name");
                    document.enquiry.name.focus();
                    return false;
                }
                var chr = new Array(15);
                chr = name.split('');
                for (var i = 0; i < chr.length; i++) {
                    if ((chr[i] < 'A' || chr[i] > 'Z') && (chr[i] < 'a' || chr[i] > 'z')) {
                        if (!(chr[i] == ' ')) {
                            alert("Invalid name , Enter only Characters");
                            return false;
                        }
                    }
                }
                
                var org = document.enquiry.company.value;
                if (org == null || org == "") {
                    alert("Please enter Company name");
                    document.enquiry.company.focus();
                    return false;
                }
                var chr1 = new Array(15);
                chr1 = org.split('');
                for (var i = 0; i < chr.length; i++) {
                    if ((chr1[i] < 'A' || chr1[i] > 'Z') && (chr1[i] < 'a' || chr1[i] > 'z')) {
                        if (!(chr[i] == ' ')) {
                            alert("Invalid name , Enter only Characters");
                            
                            return false;
                        }
                    }
                }
                
                
                var checkVal = "0123456789";
                var objVal = document.enquiry.telephone.value;
                var ok = true;
                
                if (objVal == null || objVal == "") {
                    alert("Please enter Telephone number!")
                    document.enquiry.telephone.focus();
                    return false;
                }
                for (i = 0; i < objVal.length; i++) {
                    var myChar = objVal.charAt(i);
                    for (j = 0; j < checkVal.length; j++) 
                        if (myChar == checkVal.charAt(j)) 
                            break;
                    if (j == checkVal.length) {
                        ok = false;
                        break;
                    }
                }
                if (!ok) {
                    alert("This is not a valid value. Please enter a number!");
                    return false;
                }
                
                
                var str = document.enquiry.email.value
                var at = "@"
                var dot = "."
                var lat = str.indexOf(at)
                var lstr = str.length
                var ldot = str.indexOf(dot)
                
                if ((str == null) || (str == "")) {
                    alert("Please Enter your Email ID")
                    document.enquiry.email.focus();
                    return false;
                }
                if (str.indexOf(at) == -1 || str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr ||
                str.indexOf(dot) == -1 ||
                str.indexOf(dot) == 0 ||
                str.indexOf(dot) == lstr ||
                str.indexOf(at, (lat + 1)) != -1 ||
                str.substring(lat - 1, lat) == dot ||
                str.substring(lat + 1, lat + 2) == dot ||
                str.indexOf(dot, (lat + 2)) == -1 ||
                str.indexOf(" ") != -1) {
                    alert("Invalid E-mail ID")
                    
                    return false
                }
                
                var comments = document.enquiry.comment.value;
                if (comments == null || comments == "") {
                    alert("Enter comments");
                    document.enquiry.comment.focus();
                    return false;
                    
                }
      }
            
            
            function enquiry_reset(){
                
                document.enquiry.name.value = "";
                document.enquiry.company.value = "";
                document.enquiry.email.value = "";
                document.enquiry.telephone.value = "";
                document.enquiry.comment.value = "";
                
            }
              function popup()
{
	window.open("HTML/safe shopping guarantee.html?window=pop","regpopup","width=500,height=400,scrollbars=2");
}    
 
function moneyFormat(V){
var intPart,decPart
ret=V*100;ret=Math.round(ret);
ret=V<.1?"0"+ret:ret;
ret=V< 1?"0"+ret:""+ret;
intPart=ret.substring(0,ret.length-2);
decPart=ret.substring(ret.length-2);
ret=intPart+"."+decPart;
return(ret);
}


