function getHTTPObject()
{
	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
  	{
  		xmlhttp=new XMLHttpRequest()
  	}
// code for IE
	else if (window.ActiveXObject)
  	{
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  	}
	return xmlhttp;
}

var http = getHTTPObject();
/* Brand javascript File */
function gotobrandsort(val)
{
  window.location = site_url + param + '/' + param1 + '/' + param2 + '/sort/' + val ;
}
/* End code */
/* Scroller javascript file */
function regenerate()
{
	window.location.reload();
}

function regenerate2()
{
	if(document.layers)
	{
		setTimeout("window.onresize=regenerate",450);
		intializemarquee();
	}
}

function intializemarquee()
{
	document.cmarquee01.document.cmarquee02.document.write(marqueecontents);
	document.cmarquee01.document.cmarquee02.document.close();
	thelength=document.cmarquee01.document.cmarquee02.document.height;
  scrollit();
}

function scrollit()
{
	if(document.cmarquee01.document.cmarquee02.top>=thelength*(-1))
	{
		document.cmarquee01.document.cmarquee02.top -= speed;
		setTimeout("scrollit()",100);
	}
	else
	{
		document.cmarquee01.document.cmarquee02.top = marqueeheight;
		scrollit();
	}
}
/* end code */
/* Send query Javascript file */
function checkvalidsendquery()
{
 
	if(Trim(document.frmquery.vFirstName.value)=="")
	{
	 document.getElementById('err_firstname').style.display = '';
		document.frmquery.vFirstName.focus();
		return false;
	}
	else
	{
   document.getElementById('err_firstname').style.display = 'none';
 }
	if(Trim(document.frmquery.vLastName.value)=="")
	{
		//alert("Please Enter Your Last Name");
		document.getElementById('err_lastname').style.display = '';
		document.frmquery.vLastName.focus();
		return false;
	}
	else
	{
   document.getElementById('err_lastname').style.display = 'none';
 }
 
	if(Trim(document.frmquery.vEmail.value)=="")
	{
		
		document.getElementById('err_email').style.display = '';
		document.getElementById('err_validemail').style.display = 'none';
		document.frmquery.vEmail.value = '';
		document.frmquery.vEmail.focus();
		return false;
		
	}	
	else if(document.frmquery.vEmail.value != '')
	{
	   if(!isValidEmail_withoutalert(document.frmquery.vEmail.value))
	   {
		    
		    document.getElementById('err_validemail').style.display = '';
		    document.getElementById('err_email').style.display = 'none';
		    document.frmquery.vEmail.focus();
		    return false;		      
	   }
	   else
	   {	     
	     document.getElementById('err_email').style.display = 'none';
		    document.getElementById('err_validemail').style.display = 'none';
		    		  
     }
	}
	/*if(Trim(document.frmquery.vHouseno.value)=="")
	{
		alert("Please Enter Your House No");
		document.frmquery.vHouseno.focus();
		return false;
	}
	if(Trim(document.frmquery.vStreet.value)=="")
	{
		alert("Please Enter Your Street");
		document.frmquery.vStreet.focus();
		return false;
	}
	if(Trim(document.frmquery.vCity.value)=="")
	{
		alert("Please Enter Your City");
		document.frmquery.vCity.focus();
		return false;
	}
	if(Trim(document.frmquery.vZipCode.value)=="")
	{
		alert("Please Enter Your Postal Code");
		document.frmquery.vZipCode.focus();
		return false;
	}
	else if(!alphanum(document.frmquery.vZipCode.value,document.frmquery.vZipCode.value.length))
	{
		alert("Please Enter Your Valid Postal Code");
		document.frmquery.vZipCode.select();
		return false;
	}
	if(Trim(document.frmquery.vCountry.value)=="")
	{
		alert("Please Enter Your Country");
		document.frmquery.vCountry.focus();
		return false;
	}*/
	if(Trim(document.frmquery.vPhone.value)=="")
	{
		//alert("Please Enter Your Phone number");
		document.getElementById('err_phone').style.display = '';
		document.frmquery.vPhone.focus();
		return false;
	}
	else if(!phoneformate(document.frmquery.vPhone.value,document.frmquery.vPhone.value.length))
	{
		//alert("Please Enter Your Valid Phone number");
		document.getElementById('err_validphone').style.display = '';
		document.frmquery.vPhone.select();
		return false;
	}
	else
	{
   document.getElementById('err_phone').style.display = 'none';
   document.getElementById('err_validphone').style.display = 'none';
 }
	/*if(Trim(document.frmquery.vDescription.value)=="")
	{
		alert("Please Enter Query");
		document.frmquery.vDescription.focus();
		return false;
	}*/
	
	//document.frmquery.submit();
}
/* End code */

/* Tell a friend javascript file */
function checkvalidtellafriend()
{
 
  email = document.frmfriend.friendemail.value;
  if(Trim(document.frmfriend.friendemail.value)=="")
	{
		
		document.getElementById('err_email').style.display = '';
		document.getElementById('err_validemail').style.display = 'none';
		document.frmfriend.friendemail.value = '';
		document.frmfriend.friendemail.focus();
		return false;
		
	}	
	else if(document.frmfriend.friendemail.value != '')
	{
	   email_arr = email.split(",");
	   for(i=0;i<email_arr.length;i++)
	   {
     if(!isValidEmail_withoutalert(email_arr[i]))
	   {
		    
		    document.getElementById('err_validemail').style.display = '';
		    document.getElementById('err_email').style.display = 'none';
		    document.frmfriend.friendemail.focus();
		    return false;		      
	   }
	   else
	   {	     
	     document.getElementById('err_email').style.display = 'none';
		    document.getElementById('err_validemail').style.display = 'none';
		    		  
     }
     }
	}
	if(Trim(document.frmfriend.vName.value)=="")
	{
	 document.getElementById('err_name').style.display = '';
		document.frmfriend.vName.focus();
		return false;
	}
	else
	{
   document.getElementById('err_name').style.display = 'none';
 }
 
 if(Trim(document.frmfriend.vEmail.value)=="")
	{
		
		document.getElementById('err_yemail').style.display = '';
		document.getElementById('err_yvalidemail').style.display = 'none';
		document.frmfriend.vEmail.value = '';
		document.frmfriend.vEmail.focus();
		return false;
		
	}	
	else if(document.frmfriend.vEmail.value != '')
	{
	   if(!isValidEmail_withoutalert(document.frmfriend.vEmail.value))
	   {
		    
		    document.getElementById('err_yvalidemail').style.display = '';
		    document.getElementById('err_yemail').style.display = 'none';
		    document.frmfriend.vEmail.focus();
		    return false;		      
	   }
	   else
	   {	     
	     document.getElementById('err_yemail').style.display = 'none';
		    document.getElementById('err_yvalidemail').style.display = 'none';
		    		  
     }
	}
 
}
/* end code */

/* Search javascript file */
function showBrandListing(val,txt)
{

     if (val != '')
     {
          brand_name = document.brand.left_brand.options[document.brand.left_brand.selectedIndex].text;
          newbrand_name = brand_name.replace(/\s/g,'-');
          document.brand.action = site_url+'ProductBrand/'+newbrand_name+'/'+val;
		document.brand.submit();
     }
     else
     {
          TB_show("Select Brand","#TB_inline?height=80&width=450&inlineId=select_brand","");
	     return false;
     }
}
function showSearch1()
{ 
        if(Trim(document.getElementById('getSearch').value) == "")
	{
	  document.getElementById('getSearch').value = '';
	  TB_show("Search Keyword","#TB_inline?height=80&width=450&inlineId=search_keyword","");
	  return false;
	}
	else
	{
		var keyword = document.getElementById('getSearch').value;
          document.f.action = site_url+'Product_Search/'+base64_encode(keyword);
		document.f.submit();
	}
}
function showSearch()
{ 
    if(Trim(document.getElementById('getSearch').value) == "")
	{
	  document.getElementById('getSearch').value = '';
	  TB_show("Search Keyword","#TB_inline?height=80&width=450&inlineId=search_keyword","");
	  return false;
	}
	else
	{
		var keyword = document.getElementById('getSearch').value;
                document.f.action = site_url+'Product_Search/'+base64_encode(keyword);
	}
}

/* End code */
/* Ajax newsletter file */
function sigup_newsletter(email)
{
 
	if(Trim(document.frmnewsletter.newsletter_email.value) == "Enter Your Email Address Here")
	{
		TB_show('Email',"#TB_inline?height=85&width=450&inlineId=blankemail","");
  	return false;
	}

	if(Trim(document.frmnewsletter.newsletter_email.value) == "")
	{
		TB_show('Email',"#TB_inline?height=85&width=450&inlineId=blankemail","");
  	return false;
	}
	if(!isValidEmail_withoutalert(document.frmnewsletter.newsletter_email.value))
	{
		TB_show('Email',"#TB_inline?height=85&width=450&inlineId=validemail","");
  	return false;
	}
	email = document.frmnewsletter.newsletter_email.value;
	//get url of ajax file

	var url = site_url+"ajax_newsletter_signup.php";
	url = url + "?email="+ escape(email);
	//window.location = url;
	http.open("GET", url, true);
	http.onreadystatechange = addnewsletteremail;
  http.send(null);

}

function addnewsletteremail()
{
	if (http.readyState == 4)
	{
   	var xmlDocument = http.responseXML;
		var newsletterid  = xmlDocument.getElementsByTagName('id').item(0).firstChild.data;
			//alert(newsletterid);
		if(newsletterid == 0)
		{
		  document.frmnewsletter.newsletter_email.value = '';
			TB_show("Newsletter Subscription","#TB_inline?height=85&width=450&inlineId=newsletterfail","");
		}
		else
		{
		  document.frmnewsletter.newsletter_email.value = '';
			TB_show("Newsletter Subscription","#TB_inline?height=85&width=450&inlineId=newsletterseccess","");
		}
	}
}
/* End code */
/* Top login javascript file */
function checkLogin(events)
{
  
  val = events.charCode? events.charCode :events.keyCode;
  
	if (val == 13) 
	{
		
      if(Trim(document.frmLogin.custid.value) != "" || Trim(document.frmLogin.tradid.value) != "")
      {
            document.frmLogin.vTopEmail.value = '';
            document.frmLogin.vTopPassword.value = '';
            TB_show("Login","#TB_inline?height=80&width=450&inlineId=logged_in","");
	         return false;
      }
      
      if(Trim(document.frmLogin.vTopEmail.value) == "")
      {
            TB_show("Login","#TB_inline?height=80&width=450&inlineId=login_name","");
	       return false;
      }
      if(document.frmLogin.vTopEmail.value != '')
      {
          if(!isValidEmail_withoutalert(document.frmLogin.vTopEmail.value))
          {
               TB_show("Login","#TB_inline?height=80&width=450&inlineId=login_validname","");
	          return false;
          }
      }
      if(Trim(document.frmLogin.vTopPassword.value) == "")
      {
            TB_show("Login","#TB_inline?height=80&width=450&inlineId=login_pass","");
	         return false;
      }
      /*
      if(Trim(document.frmLogin.vTopPassword.value) != "" && Trim(document.frmLogin.vTopEmail.value) == "" )
      {
            TB_show("Login","#TB_inline?height=80&width=450&inlineId=login_name","");
	         return false;
      }
      */
      
     document.frmLogin.submit();
	}
}
/* End code */
/* Product Detail Javascript File */
function ChangeProductPrice(val,productid)
{
        //1 For including and 0 for excluding VAT
        value = $.cookie('EBVATPrice')
        
        var url = site_url+"ajax_getVariantPrice.php";
	url = url + "?iProAttrId="+ val+"&productid="+productid+"&value="+value;
	//window.location = url;
	http.open("GET", url, true);
	http.onreadystatechange = dispprice;
        http.send(null);
}
function dispprice()
{
        if (http.readyState == 4)
        {
                var xmlDocument = http.responseXML;
                iProAttrId = xmlDocument.getElementsByTagName("iProAttrId")[0].childNodes[0].nodeValue;
                iProductId = xmlDocument.getElementsByTagName("iProductId")[0].childNodes[0].nodeValue;
                iStock = xmlDocument.getElementsByTagName("iStock")[0].childNodes[0].nodeValue;
                value = xmlDocument.getElementsByTagName("value")[0].childNodes[0].nodeValue;
                fPrice = xmlDocument.getElementsByTagName("fPrice")[0].childNodes[0].nodeValue;
                fRetailPrice = xmlDocument.getElementsByTagName("fRetailPrice")[0].childNodes[0].nodeValue;
                fDisplayPrice = xmlDocument.getElementsByTagName("fDisplayPrice")[0].childNodes[0].nodeValue;
                fDisplayRetailPrice = xmlDocument.getElementsByTagName("fDisplayRetailPrice")[0].childNodes[0].nodeValue;
                fVATPrice = xmlDocument.getElementsByTagName("fVATPrice")[0].childNodes[0].nodeValue;
                fVATRetailPrice = xmlDocument.getElementsByTagName("fVATRetailPrice")[0].childNodes[0].nodeValue;
                fVATDisplayPrice = xmlDocument.getElementsByTagName("fVATDisplayPrice")[0].childNodes[0].nodeValue;
                fVATDisplayRetailPrice = xmlDocument.getElementsByTagName("fVATDisplayRetailPrice")[0].childNodes[0].nodeValue;
                stockmsg = xmlDocument.getElementsByTagName("stockmsg")[0].childNodes[0].nodeValue;
                
                if (iProAttrId == '0')
                {
                        if (fVATRetailPrice != '0.00' && fVATRetailPrice != '') {
                                //if (value == '1')
                                document.getElementById('vatprice').value = fVATDisplayRetailPrice;
                                document.getElementById('price_'+iProductId).innerHTML = "&pound; "+fVATDisplayRetailPrice;
                                //document.getElementById('mrp_'+iProductId).innerHTML = "&pound; "+fVATDisplayPrice;
                        } else {
                                document.getElementById('price_'+iProductId).innerHTML = "&pound; "+fVATDisplayPrice;
                                //if (value == '1')
                                document.getElementById('vatprice').value = fVATDisplayPrice;
                                
                        }
                        if (fRetailPrice != '0.00' && fRetailPrice != '') {
                                //if (value == '0')
                                document.getElementById('price').value = fDisplayRetailPrice;
                                document.getElementById('priceex_'+iProductId).innerHTML = "&pound; "+fDisplayRetailPrice;
                                //document.getElementById('mrpex_'+iProductId).innerHTML = "&pound; "+fDisplayPrice;
                        } else {
                                document.getElementById('priceex_'+iProductId).innerHTML = "&pound; "+fDisplayPrice;
                                //if (value == '0')
                                document.getElementById('price').value = fDisplayPrice;
                        }
                        
                        if (value == '1') {
                              $(".inc").show();
		                        $(".ex").hide();
		                        $("#vatToggle").html("Show &nbsp;Ex vat prices");
                        }
                        if (value == '0') {
                              $(".inc").hide();
		                        $(".ex").show();
		                        $("#vatToggle").html("Show Inc vat prices");
                        }
                        document.getElementById('qty_'+iProductId).options.length = 0;
                        
                        if (stockmsg == 'Yes')
                        {
                           k = 1;
                           document.getElementById('msg_'+iProductId).innerHTML = "IN STOCK";
                           
                           document.getElementById('cart_'+iProductId).style.display = '';
                           document.getElementById('detail_'+iProductId).style.display = 'none';
                           if (iStock > 0)
                           {
                              for (j=0;j<iStock;j++) {
                                 document.getElementById('qty_'+iProductId).options[j] = new Option();
                                 document.getElementById('qty_'+iProductId).options[j].text = k;
                                 document.getElementById('qty_'+iProductId).options[j].value = k;
                                 k++;
                             }
                           }
                           else
                           {
                              document.getElementById('qty_'+iProductId).options[0] = new Option();
                              document.getElementById('qty_'+iProductId).options[0].text = 0;
                              document.getElementById('qty_'+iProductId).options[0].value = 0;
                           }
                        }
                        else
                        {
                           k = 0;
                           
                           document.getElementById('msg_'+iProductId).innerHTML = "OUT OF STOCK";
                           document.getElementById('cart_'+iProductId).style.display = 'none';
                           document.getElementById('detail_'+iProductId).style.display = '';
                           document.getElementById('qty_'+iProductId).options[0] = new Option();
                           document.getElementById('qty_'+iProductId).options[0].text = k;
                           document.getElementById('qty_'+iProductId).options[0].value = k;
                        }
                           
                        
                }
                else
                {
                        
                        if (fVATRetailPrice != '0.00' && fVATRetailPrice != '') {
                                //if (value == '1')
                                 document.getElementById('vatprice').value = fVATDisplayRetailPrice;
                                document.getElementById('price_'+iProductId).innerHTML = "&pound; "+fVATDisplayRetailPrice;
                                //document.getElementById('mrp_'+iProductId).innerHTML = "&pound; "+fVATDisplayPrice;
                        } else {
                                document.getElementById('price_'+iProductId).innerHTML = "&pound; "+fVATDisplayPrice;
                                //if (value == '1')
                                document.getElementById('vatprice').value = fVATDisplayPrice;
                        }
                        if (fRetailPrice != '0.00' && fRetailPrice != '') {
                                //if (value == '0')
                                document.getElementById('price').value = fDisplayRetailPrice;
                                document.getElementById('priceex_'+iProductId).innerHTML = "&pound; "+fDisplayRetailPrice;
                                //document.getElementById('mrpex_'+iProductId).innerHTML = "&pound; "+fDisplayPrice;
                        } else {
                                document.getElementById('priceex_'+iProductId).innerHTML = "&pound; "+fDisplayPrice;
                                //if (value == '0')
                                document.getElementById('price').value = fDisplayPrice;
                        }
                        
                        if (value == '1') {
                              $(".inc").show();
		                        $(".ex").hide();
		                        $("#vatToggle").html("Show &nbsp;Ex vat prices");
                        }
                        if (value == '0') {
                              $(".inc").hide();
		                        $(".ex").show();
		                        $("#vatToggle").html("Show Inc vat prices");
                        }
                        
                        document.getElementById('qty_'+iProductId).options.length = 0;
                        if (stockmsg == 'Yes')
                        {
                           k = 1;
                           
                           document.getElementById('msg_'+iProductId).innerHTML = "IN STOCK";
                           document.getElementById('cart_'+iProductId).style.display = '';
                           document.getElementById('detail_'+iProductId).style.display = 'none';
                           for (j=0;j<iStock;j++) {
                                document.getElementById('qty_'+iProductId).options[j] = new Option();
                                document.getElementById('qty_'+iProductId).options[j].text = k;
                                document.getElementById('qty_'+iProductId).options[j].value = k;
                                k++;
                           }
                        }
                        else
                        {
                           k = 0;
                           
                           document.getElementById('msg_'+iProductId).innerHTML = "OUT OF STOCK";
                           document.getElementById('cart_'+iProductId).style.display = 'none';
                           document.getElementById('detail_'+iProductId).style.display = '';
                           document.getElementById('qty_'+iProductId).options[0] = new Option();
                           document.getElementById('qty_'+iProductId).options[0].text = k;
                           document.getElementById('qty_'+iProductId).options[0].value = k;
                        }
                        
                }
        }
}
function checkvalidattributenew(val,productid,name,price,retprice,vatprice,vatretprice,catid)
{ 
     value = $.cookie('EBVATPrice');
     //alert(value)
     if(val != '0')
     {   
		if (value == '1')
               var iProdArrrId = document.getElementById('iProdAttrId_'+productid).value;
          else
               var iProdArrrId = document.getElementById('iProdAttrIdex_'+productid).value;
		if(iProdArrrId == '0')
		{
			alert("Please Select Product Variant");
			if (value == '1')
			  document.getElementById('iProdAttrId_'+productid).focus();
			else
			  document.getElementById('iProdAttrIdex_'+productid).focus();
			return false;
		}
	}
	
        
        document.getElementById('productid').value = productid;
        document.getElementById('name').value = name;
        
        if (value == '1') {
                proid = 'iProdAttrId_'+productid;
        } else {
                proid = 'iProdAttrIdex_'+productid;
        }
        if (document.getElementById(proid))
        {
                if (document.getElementById(proid).value == '0')
                {
                        //if (value == '0') {
                                if (retprice == '' || retprice == '0.00')
                                        document.getElementById('price').value = price;
                                else
                                        document.getElementById('price').value = retprice;
                        //}
                        //if (value == '1') {
                                if (vatretprice == '' || vatretprice == '0.00')
                                        document.getElementById('vatprice').value = vatprice;
                                else
                                        document.getElementById('vatprice').value = vatretprice;
                        //}
                }
        }
        else
        {
                //if (value == '0') {
                        if (retprice == '' || retprice == '0.00')
                                document.getElementById('price').value = price;
                        else
                                document.getElementById('price').value = retprice;
                //}
                
                //if (value == '1') {
                        if (vatretprice == '' || vatretprice == '0.00')
                                document.getElementById('vatprice').value = vatprice;
                        else
                                document.getElementById('vatprice').value = vatretprice;
                //}
        }
        
        //alert(document.getElementById('price').value)
        //alert(document.getElementById('vatprice').value)
	document.getElementById('cookieval').value = value;
	if (file == 'c-productdetail')
	{
          document.getElementById('catid').value = catid;
	     document.getElementById('categoryid').value = catid;
     }
     else
     {
     	if (iCategoryId == '')
     	{
     	    document.getElementById('catid').value = catid;
     	    document.getElementById('categoryid').value = catid;
          }
     }
     
     //alert('Coming Soon');
	document.frmcat.action = 'index.php?file=ca-cart&mode=Add';
	document.frmcat.submit();
}

function change_image(imgname, proid)
{	
    /*	converting small image to large */
    
        var changestr = imgname;
  	
  	changeres = changestr.split("/");
  	getsrc = changeres.slice(changeres.length-1);
  	
  	largesrc = getsrc[0].substring(0,2);
  	vImage = getsrc[0].substring(2);
  	large_val = getsrc[0].replace(largesrc, "");
        main_large_val = prod_url + large_val
   
   
        url_add = site_url+'popup.php?vImagepath='+main_large_val+'&vImage='+vImage+'&vTitle='+vImage;
        window.open(url_add,'enlarged_view',
        'width=700,height=550,toolbar=no,resizable=no,scrollbars=yes,left=10,top=20');
   
   
  	
  	
}

/* End code */
/* Category javascript file */
function filluprange(val,rangeid) {
        
  var url = site_url + "ajax_range.php";
  url = url + "?iBrandId="+val+'&iRangeId='+rangeid;
  if (val != '0')
  {
        http.open("GET", url, true);
        http.onreadystatechange = addrangeoption;
        http.send(null);
  }
  else
  {
        newbrand = '0';
        range = '0';
        sort = document.getElementById('vChange').value;
        window.location = site_url + param + '/' + param1 + '/' + param2 + '/sort/' + sort + '/' + newbrand + '/' + range ;
  }
    
}
function addrangeoption()
{
        if (http.readyState == 4)
        {
                
                var xmlDocument = http.responseXML;
                totalrange = xmlDocument.getElementsByTagName("total")[0].childNodes[0].nodeValue;
                //ranid = xmlDocument.getElementsByTagName("iRangeId")[0].childNodes[0].nodeValue;
                brand_id = xmlDocument.getElementsByTagName("brand_id")[0].childNodes[0].nodeValue;
                
                if (totalrange > 0) {
                        document.getElementById('vChange2').disabled = false;
                        document.getElementById('vChange2').options.length = 0;
	                document.getElementById('vChange2').options[0] = new Option("All Ranges");
	                document.getElementById('vChange2').options[0].value = "0";
                        j = 1;
                        for(i=0;i<parseInt(totalrange);i++)
			{
			     var rangeid1 = xmlDocument.getElementsByTagName('rangeid').item(i).firstChild.data;
			     var title1 = xmlDocument.getElementsByTagName('title').item(i).firstChild.data;
			     
                             document.getElementById('vChange2').options[j] = new Option();
                             document.getElementById('vChange2').options[j].text = title1;
                             document.getElementById('vChange2').options[j].value = rangeid1;
                             if (rangeid1 == iRangeId)
                                document.getElementById('vChange2').options[j].selected = true;
                             j++;
			}
                } 
                else
                {
                        document.getElementById('vChange2').options.length = 0;
	                document.getElementById('vChange2').options[0] = new Option("All Ranges");
	                document.getElementById('vChange2').options[0].value = "0";
	                
                        document.getElementById('vChange2').disabled = true;
                        range = '0';
                        sort = document.getElementById('vChange').value;
                        window.location = site_url + param + '/' + param1 + '/' + param2 + '/sort/' + sort + '/' + brand_id + '/' + range ;
                }
                
        }
}
function dispprod(val)
{ 
  sort1 = document.getElementById('vChange').value;
  newbrand = document.getElementById('vChange1').value;
  if(param != 'Product_Search')
  {  	
    	window.location = site_url + param + '/' + param1 + '/' + param2 + '/sort/' + sort1 + '/' + newbrand + '/' + val;
  }
  else 
  {
    param2 = '0';
    window.location = site_url + param + '/' + param1 + '/' + param2 + '/sort/' + sort1 + '/' + newbrand + '/' + val;
  } 
}
function gotosort(val)
{
  if(param != 'Product_Search')
  {
    if(param == 'brand_range_list')
    	window.location = site_url + param + '/' + param1 + '/' + param2 + '/' + param3 + '/sort/' + val;
    else	
    	window.location = site_url + param + '/' + param1 + '/' + param2 + '/sort/' + val ;
  }
  else 
  {
     param2 = '0'; 
     window.location = site_url + param + '/' + param1 + '/' + param2 + '/sort/' + val;
  }
}

/* End code */
function utf8_decode ( str_data ) {
    var tmp_arr = [], i = 0, ac = 0, c1 = 0, c2 = 0, c3 = 0;
    
    str_data += '';
    
    while ( i < str_data.length ) {
        c1 = str_data.charCodeAt(i);
        if (c1 < 128) {
            tmp_arr[ac++] = String.fromCharCode(c1);
            i++;
        } else if ((c1 > 191) && (c1 < 224)) {
            c2 = str_data.charCodeAt(i+1);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
            i += 2;
        } else {
            c2 = str_data.charCodeAt(i+1);
            c3 = str_data.charCodeAt(i+2);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    }
 
    return tmp_arr.join('');
}
function base64_decode( data ) {
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = "", tmp_arr = [];
 
    if (!data) {
        return data;
    }
 
    data += '';
 
    do {  // unpack four hexets into three octets using index points in b64
        h1 = b64.indexOf(data.charAt(i++));
        h2 = b64.indexOf(data.charAt(i++));
        h3 = b64.indexOf(data.charAt(i++));
        h4 = b64.indexOf(data.charAt(i++));
 
        bits = h1<<18 | h2<<12 | h3<<6 | h4;
 
        o1 = bits>>16 & 0xff;
        o2 = bits>>8 & 0xff;
        o3 = bits & 0xff;
 
        if (h3 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1);
        } else if (h4 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1, o2);
        } else {
            tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
        }
    } while (i < data.length);
 
    dec = tmp_arr.join('');
    dec = utf8_decode(dec);
 
    return dec;
}
function utf8_encode ( argString ) {
    var string = (argString+'').replace(/\r\n/g, "\n").replace(/\r/g, "\n");
 
    var utftext = "";
    var start, end;
    var stringl = 0;
 
    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;
 
        if (c1 < 128) {
            end++;
        } else if((c1 > 127) && (c1 < 2048)) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc !== null) {
            if (end > start) {
                utftext += string.substring(start, end);
            }
            utftext += enc;
            start = end = n+1;
        }
    }
 
    if (end > start) {
        utftext += string.substring(start, string.length);
    }
 
    return utftext;
}
function base64_encode(data) 
{      
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, enc="", tmp_arr = [];
 
    if (!data) {
        return data;
    }
 
    data = utf8_encode(data+'');
    
    do { // pack three octets into four hexets
        o1 = data.charCodeAt(i++);
        o2 = data.charCodeAt(i++);
        o3 = data.charCodeAt(i++);
 
        bits = o1<<16 | o2<<8 | o3;
 
        h1 = bits>>18 & 0x3f;
        h2 = bits>>12 & 0x3f;
        h3 = bits>>6 & 0x3f;
        h4 = bits & 0x3f;
 
        // use hexets to index into b64, and append result to encoded string
        tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
    } while (i < data.length);
    
    enc = tmp_arr.join('');
    
    switch( data.length % 3 ){
        case 1:
            enc = enc.slice(0, -2) + '==';
        break;
        case 2:
            enc = enc.slice(0, -1) + '=';
        break;
    }
 
    return enc;
}
function isValidEmail(emailStr) {
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
		alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	// Start by checking that only basic ASCII characters are in the strings (0-127).
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert("Ths username contains invalid characters.");
			return false;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert("Ths domain name contains invalid characters.");
			return false;
		}
	}
	if (user.match(userPat)==null) {
		alert("The username doesn't seem to be valid.");
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Destination IP address is invalid!");
				return false;
	   		}
		}
		return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			alert("The domain name does not seem to be valid.");
			return false;
	   }	
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}

// Make sure there's a host name preceding the domain.

	if (len<2) {
		alert("This address is missing a hostname!");
		return false;
	}	
	return true;
}
function checkAlphanumeric(events)
{ 	
	val = events.charCode? events.charCode :events.keyCode;
	if ((val > 0 && val < 48 && val != 8) || (val > 57 && val < 65) || (val > 90 && val < 97) || (val > 122 && val < 127)) 
	{
		return (false);
	}
	return true;
}
function goLink(my_page)
{
	window.open(my_page); 
}
function Trim(s) 
{
	return s.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function checkValid_Digit_Phone(events)
{ 	
	unicodes = events.charCode? events.charCode :events.keyCode;
 
	if(unicodes == 9 || unicodes == 13 || unicodes == 8 || unicodes == 37 || unicodes == 36 || unicodes == 35)
	 return true;
  if(unicodes > 47 && unicodes < 58 )
	   return true;
	else
		return false;
	
}
function checkValidPhone(events)
{  
  var unicodes=events.charCode? events.charCode :events.keyCode;
    	
	if(unicodes > 47 && unicodes < 58 )
	   return true;
	else if(unicodes == 8 || unicodes == 43 || unicodes == 45 || unicodes == 13 || unicodes == 9)		
		return true;
	else
		return false;
}
function checkValidAlphanumeric(events)
{ 	
	val = events.charCode? events.charCode :events.keyCode;
	
	if ((val > 0 && val < 48 && val != 8 && val != 9) || (val > 57 && val < 65) || (val > 90 && val < 97) || (val > 122 && val < 127)) 
	{
		return (false);
	}
	return true;
}



function isValidEmail_withoutalert(emailStr) {
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
		//	alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	// Start by checking that only basic ASCII characters are in the strings (0-127).
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			//	alert("Ths username contains invalid characters.");
			return false;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			//	alert("Ths domain name contains invalid characters.");
			return false;
		}
	}
	if (user.match(userPat)==null) {
		//	alert("The username doesn't seem to be valid.");
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				//	alert("Destination IP address is invalid!");
				return false;
	   		}
		}
		return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			//	alert("The domain name does not seem to be valid.");
			return false;
	   }	
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
		//	alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}

// Make sure there's a host name preceding the domain.

	if (len<2) {
		//	alert("This address is missing a hostname!");
		return false;
	}	
	return true;
}
function phoneformate(value,length)
{
	chk1="1234567890()+- ";
	for(i=0;i<length;i++)
	{
		ch1=value.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==-1)
			return false;
	}
	return true;
}
function removespace(e)
{
	if(!e)
        e = window.event;
    if(e.keyCode)
		val = e.keyCode;
    else
		val = e.charCode;
  
	
	if(val == "32")
	{
		/*
		if(e.keyCode)
		e.keyCode=0;
	    else
		e.charCode=0;
		*/
		return false;

		
	}
	else
	{
		return true;
	}
}
/* For home page featured products */
var BOOKS = function(){
	var _P = {
		init : function( params ) {
			_P.params = params;
			_P.loadXml();
		},
		params : null,
		data : null,
		loadXml : function() {
			$.ajax({
				type : "GET",
				url : _P.params.xmlPath,
				dataType : "xml",
				success : function( data ) {
					_P.data = data;
					_P.max = _P.params.perView;
					_P.count = $( "book", data ).length;
					_P.preloadBooks();
					_P.browseBooks();
				}
			});
		},
		first : 0,
		max : 0,
		count : 0,
		
		preloadBooks : function() {
		     
			$( "ul", "#books" ).empty();
			$( "book", _P.data ).each(function( i ) {
			    
                    value = $.cookie('EBVATPrice')
                    if (value == '1') {
                              $(".inc").show();
		                    $(".ex").hide();
		                  $("#vatToggle").html("Show &nbsp;Ex vat prices");
                    }
                    if (value == '0') {
                              $(".inc").hide();
		                  $(".ex").show();
		                   $("#vatToggle").html("Show Inc vat prices");
                    }
                    
				var title = $.trim( $( "title", this ).text() );
				var href = $.trim( $( "href", this ).text() );
				var producttitle = $.trim( $( "prodctname", this ).text() );
				var price = $.trim( $( "price", this ).text() );
				var retailprice = $.trim( $( "retailprice", this ).text() );
				var vatprice = $.trim( $( "vatprice", this ).text() );
				var vatretailprice = $.trim( $( "vatretailprice", this ).text() );
				html = '';
				if (retailprice != '' && retailprice != '0.00')
				{
                         //html = "<p class='MPnone prices inc' style='display:none;'><span>SRP: &pound; <b>"+ vatretailprice+ " </b></span></p>";
                         //html = html + "<p class='MPnone prices ex'><span>SRP: &pound; <b>"+ retailprice+ " </b></span></p>"
                    }
                    else
                    {
                        // html = "<p class='MPnone prices inc' style='display:none;'><span>SRP: &pound; <b>"+ vatprice+ " </b></span></p>";
                        // html = html + "<p class='MPnone prices ex'><span>SRP: &pound; <b>"+ price+ " </b></span></p>"
                    }
                    
				$( "ul", "#books" ).append([
					"<li><a href='",
					href,
					"' class='thumb'><img src='",
					$.trim( $( "image > src", this ).text() ),
					"' width='",
					$( "image", this ).attr( "width" ),
					"' height='",
					$( "image", this ).attr( "height" ),
					"' title='",
					title,
					"' /></a><a href='",
					href,
					"' class='infonew'>",
                         producttitle,
                         "</a><div class='price'>",
                         html,
                         "</div><a href='",
                         href,
                         "'> <img src='",
                         _P.params.imgPath,
                         "/btn-buy.gif' title='View' /></a></li>" ].join( "" ));
				value = $.cookie('EBVATPrice')
                    if (value == '1') {
                              $(".inc").show();
		                    $(".ex").hide();
		                  $("#vatToggle").html("Show &nbsp;Ex vat prices");
                    }
                    if (value == '0') {
                              $(".inc").hide();
		                  $(".ex").show();
		                   $("#vatToggle").html("Show Inc vat prices");
                    }
                    /*
                    $( "body" ).append([
					"<div class='books_tool_tip' id='books_tool_tip_",
					i,
					"'><div class='books_pointer_left'><!-- books pointer --></div><div class='inner'><p>",
					title,
					" (by <em>",
					$.trim( $( "author", this ).text() ),
					"</em>)",
					"</p><p><img src='",
					_P.params.imgPath,
					"/stars_",
					$.trim( $( "reviews > average_rating", this ).text() ),
					,".gif' width='55' height='12' /> (",
					$.trim( $( "reviews > total", this ).text() ),
					")",
					"</p></div></div>" ].join( "" ));
					*/
			});
			$( ".info", "#books" ).hover(function( e ) {
				_P.tooltip.show( e, $( "#books_tool_tip_" + $( "a.info", "#books" ).index( this ) ) );
			}, function( e ) {
				_P.tooltip.hide( e, $( "#books_tool_tip_" + $( "a.info", "#books" ).index( this ) ) );
			});
			$( "#books .prev" ).click(function() {
				_P.browseBooks( "prev" );
				return false;
			});
			$( "#books .next" ).click(function() {
				_P.browseBooks( "next" );
				return false;
			});
		},
		browseBooks : function( browse ) {
			if ( browse == "prev" ) {
				if ( _P.first == _P.count && ( _P.count % _P.max > 0 ) ) {
					_P.first = _P.first - ( ( _P.count % _P.max ) + _P.max );
				} else {
					_P.first = _P.first - ( _P.max * 2 );
				}
			}
			var range = _P.first + _P.max;
			var start = 1;
			if ( range > _P.max ) {
				start = ( ( range - _P.max ) + 1 );
			}
			if ( _P.first == 0 ) {
				$( "#books .prev" ).css( "visibility", "hidden" );
			} else {
				$( "#books .prev" ).css( "visibility", "visible" );
			}
			if ( range < _P.count ) {
				$( "#books .next" ).css( "visibility", "visible" );
			} else if ( range >= _P.count ) {
				range = _P.count;
				$( "#books .next" ).css( "visibility", "hidden" );
			}
			$( "book", _P.data ).each(function( i ) {
				if ( i >= _P.first && i < range ) {
					$( "#books li:eq(" + i + ")" ).fadeIn( "slow" );
				} else {
					$( "#books li:eq(" + i + ")" ).css( "display", "none" );
				}
			});
			_P.first = range;
			/*
               $( "#books .showing" ).html([
				"Viewing <strong>",
				start,
				" - ",
				range,
				"</strong> of <strong>",
				_P.count,
				"</strong>" ].join( "" ));
			*/
		},
		tooltip : {
			show : function( e, $o ) {
				var v = _P.tooltip.getViewport();
				var pageX = _P.tooltip.getMouseCoord( v, e )[0] + 15;
				var pageY = _P.tooltip.getMouseCoord( v, e )[1];
				$o.find( ".books_pointer_right" ).addClass( "books_pointer_left" ).removeClass( "books_pointer_right" );
				if ( pageX + $o.width() > v.innerWidth + v.pageXOffset ) {
					pageX = pageX - $o.width() - 30;
					$o.find( ".inner" ).addClass( "inner_right" );
					$o.find( ".books_pointer_left" ).addClass( "books_pointer_right" ).removeClass( "books_pointer_left" );
				}
				$o.css( "left", pageX ).css( "top", pageY ).css( "display", "block" );
			},
			hide : function( e, $o ) {
				$o.css( "display", "none" );
			},
			getMouseCoord : function( v, e ) {
				( !e ) ? e = window.event : e = e;
				( e.pageX ) ? v.pageX = e.pageX : v.pageX = e.clientX + v.scrollLeft;
				( e.pageY ) ? v.pageY = e.pageY : v.pageY = e.clientY + v.scrollTop;
				return [ e.pageX, e.pageY ];
			},
			getViewport : function() {
				var viewport = {}
				if ( self.innerHeight ) {
					viewport.pageYOffset = self.pageYOffset;
					viewport.pageXOffset = self.pageXOffset;
					viewport.innerHeight = self.innerHeight;
					viewport.innerWidth = self.innerWidth;
				} else if ( document.documentElement && document.documentElement.clientHeight ) {
					viewport.pageYOffset = document.documentElement.scrollTop;
					viewport.pageXOffset = document.documentElement.scrollLeft;
					viewport.innerHeight = document.documentElement.clientHeight;
					viewport.innerWidth = document.documentElement.clientWidth;
				}
				return viewport;
			}
		}
	};
	return {
		init : function( params ) {
			_P.init( params );
		}
	};
}();
/* End code */

