var userAgent = navigator.userAgent.toLowerCase();   // Figure out what browser is being used   
var browser = {   
version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],   
safari: /webkit/.test( userAgent ),  
google: /chrome/.test( userAgent ), 
opera: /opera/.test( userAgent ),   
msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),   
mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent ), 
macintoshOS:/macintosh/.test(userAgent) //macintoshOS for identifying the operating system of the end user -- this identify whether the user using AppleMAc or not
};   
var ver=userAgent.split('/');
    ver=ver[ver.length-1].split('.');
    var currentVersion=ver[0];    
if(browser.google==true)
{     
     document.write ("<style>.fade{opacity:1}.loginpage{margin-top:80px;float:left;margin-left:110px;}</style>");
}
else if(browser.safari==true)
{     
     document.write ("<style>.fade{opacity:1}.loginpage{margin-top:80px;float:left;margin-left:110px;}</style>");
}
else if (browser.msie==true)
{   

   if(browser.version!=7.0)
        document.write ("<style>.fade{filter:alpha(opacity=100)}.loginpage{margin-top:80px;float:left;margin-left:55px;}</style>");
   else
        document.write ("<style>.fade{filter:alpha(opacity=100)}.loginpage{margin-top:80px;float:left;margin-left:110px;}</style>");     
}	
else if (browser.mozilla==true)
{
    if(browser.macintoshOS==true)
        document.write ("<style>.fade{opacity:1}</style>");
    else    
        document.write ("<style>.fade{opacity:1}.loginpage{margin-top:80px;float:left;margin-left:110px;}</style>");
}


function callback() {
    
   timedelay=50;
  if(document.activeElement.id=='txtSearch')
  {
      document.getElementById("divSearchlist").style.display="block";
      document.getElementById("divSearchlist").style.height="auto";
      document.getElementById("divSearchlist").innerHTML = 'Type the first 4 letters of the product or the product code you are searching for and let our Search Assist do the rest';
  }   
  else if ((document.activeElement.id!='divList' &&  document.activeElement.id!='divSearchlist') || document.getElementById("divSearchlist").style.display!="block")
  {      
      document.getElementById("divSearchlist").style.display="none";	   	          
  }   
}
var timeout;
var timedelay=0;
function hideSearch()
{
    if(document.getElementById("divSearchlist").style.display=="block")
    {
        if (timedelay==0)
		    document.getElementById("divSearchlist").style.display="none";
	    else
	    {
		    timedelay=timedelay-1;
		    timeout=setTimeout("hideSearch()",1000);
		    document.getElementById("divSearchlist").style.display="block";		
	    }
    }   
}
function hideSearchlist()
{       
    document.getElementById("divSearchlist").style.display="none";
}
function showSearch() {
    
     if (typeof timeout!="undefined")
		clearTimeout(timeout);
    document.getElementById("divSearchlist").style.display="block";
}
function clearTxtBx(obj)
{    
    if(obj.value=='-- Email Address --')
        obj.value='';
}
function fillTxtBx(obj)
{
    if(trim(obj.value)=='')
    obj.value='-- Email Address --';
}
var imgHTTP=getreq(); 
var pagelink,key;
function productsearchcount(keyword,plink)
{         
    pagelink=plink;  
    key=keyword;
    time1=new Date();                     
    var url="/ajax/product-search.aspx";      
    url=url+"?count=1&search="+keyword+"&time="+time1.getTime();              
    if(imgHTTP.readyState>0)
        imgHTTP.abort();            
    imgHTTP.onreadystatechange=redirectlink;                                     
    imgHTTP.open('GET',url,true);                                       
    imgHTTP.send(null);           
}
function redirectlink()
{
    if (imgHTTP.readyState==4) 
    {
        document.location=pagelink+"?keyword="+key;
        return false;
    }
}
function productsearch(obj)
{       
    time1=new Date();
    var searchkey=trim(obj.value);
    var now = new Date();
    var exitTime = now.getTime() + 200;
    var stop=1;
    document.getElementById("divSearchlist").style.display="block";
    document.getElementById("divSearchlist").style.height="auto";
    document.getElementById("divSearchlist").innerHTML = 'Type the first 4 letters of the product or the product code you are searching for and let our Search Assist do the rest';
    while(stop>0)
    {   
        now = new Date();
        if(now.getTime() > exitTime) stop=0;
    }  
    if(searchkey!='' && searchkey.length>=4)
    {                   
        document.getElementById("divSearchlist").innerHTML = 'Please wait while we locate this product for you ';         
        var url="/ajax/product-search.aspx";    
      
        url=url+"?search="+searchkey+"&time="+time1.getTime();            
        if(imgHTTP.readyState>0)
            imgHTTP.abort();            
        imgHTTP.onreadystatechange=searchlist1;                                     
        imgHTTP.open('GET',url,true);                                       
        imgHTTP.send(null);           
    }    
    document.getElementById("divSearchlist").style.display="block";
}
function searchlist1 ()
{   
    document.getElementById("divSearchlist").style.height="auto";
    document.getElementById("divSearchlist").innerHTML = 'Please wait while we locate this product for you '; 
    if (imgHTTP.readyState==4) 
    {   document.getElementById("divSearchlist").style.display="block";                 
        document.getElementById("divSearchlist").style.height="200px";
        
        document.getElementById("divSearchlist").innerHTML = imgHTTP.responseText;                                                     
    } 
}
function getreq()
{ // returns false if exists
	if(window.ActiveXObject)
	 { // if IE
		try
		 {
		    return new ActiveXObject("Msxml2.XMLHTTP");
	    }
	    catch(e)
	    {
		    try
		    {
		        return new ActiveXObject("Microsoft.XMLHTTP");
		    }
		    catch(e)
		    {
		        return;
		    }
		}
	}
	else if(window.XMLHttpRequest)
	{ // if Mozilla, Safari, etc.
		return new XMLHttpRequest();
	}
}
function searchGo()
{
    if(trim(document.getElementById("txtSearch").value)!='') {

        time1 = new Date();
        var url = "/ajax/product-search.aspx";
        url = url + "?count=1&search=" + trim(document.getElementById("txtSearch").value) + "&time=" + time1.getTime();
        if (imgHTTP.readyState > 0)
            imgHTTP.abort();
        imgHTTP.onreadystatechange = searchsubmit;
        imgHTTP.open('GET', url, true);
        imgHTTP.send(null);
        
        
    }
    else
        alert("Please enter the keyword to search");
}
function searchsubmit() {
    if (imgHTTP.readyState == 4) {
        document.forms[0].method = "post";
        document.forms[0].action = "/app/product-search.aspx";
        document.forms[0].submit();
    }
}
function changebg(divid,imgid,imgsrc,color)
{       
    try
    {       
        document.getElementById(imgid).src="/images/"+imgsrc;
    }
    catch(e){ }
}
    
     //************************* Change Password***************************************//
function changePasswordValidation()
{    
    var oldpassword= trim(document.getElementById('ctl00_ContentPlaceHolder1_txtCurrentPassword').value);
    var newpassword= trim(document.getElementById('ctl00_ContentPlaceHolder1_txtNewPassword').value);
    var confirmpassword= trim(document.getElementById('ctl00_ContentPlaceHolder1_txtConfirmPassword').value);   
    if(oldpassword=='')
    {        
        document.getElementById('ctl00_ContentPlaceHolder1_txtCurrentPassword').focus();
        alert(geterrmsg('e47'));
        return false;
    }   
    else if(newpassword=='')
    {
        document.getElementById('ctl00_ContentPlaceHolder1_txtNewPassword').value='';
        document.getElementById('ctl00_ContentPlaceHolder1_txtNewPassword').focus();
        alert(geterrmsg('e45'));
        return false;
    }
    else if(newpassword.length<6)
    {
        document.getElementById('ctl00_ContentPlaceHolder1_txtNewPassword').value='';
        document.getElementById('ctl00_ContentPlaceHolder1_txtConfirmPassword').value='';
        document.getElementById('ctl00_ContentPlaceHolder1_txtNewPassword').focus();
        alert(geterrmsg('e18'));
        return false;
    }
    else if(confirmpassword=='')
    {
        document.getElementById('ctl00_ContentPlaceHolder1_txtConfirmPassword').value='';
        document.getElementById('ctl00_ContentPlaceHolder1_txtConfirmPassword').focus();
        alert(geterrmsg('e46'));
        return false;
    }
    else if(newpassword!=confirmpassword)
    {
        document.getElementById('ctl00_ContentPlaceHolder1_txtConfirmPassword').value='';
        document.getElementById('ctl00_ContentPlaceHolder1_txtConfirmPassword').focus();
        alert(geterrmsg('e44'));
        return false;
    }
    else
    {       
       
        var xmlHttp=getreq();
        var url='/ajax/change-forgot-pass.aspx?ps='+oldpassword;
        xmlHttp.open('get',url,false);
        xmlHttp.send(null);      
         
        if(xmlHttp.responseText=='0')
        {                      
            document.getElementById('ctl00_ContentPlaceHolder1_txtCurrentPassword').value='';
            document.getElementById('ctl00_ContentPlaceHolder1_txtCurrentPassword').focus();
            alert(geterrmsg('e43'));            
            return false;
        }
        else        
            return true;          
    }        
}
function checkLogin()
{
    var username=document.getElementById('ctl00_ContentPlaceHolder1_txtmail').value;
    var password=document.getElementById('ctl00_ContentPlaceHolder1_txtpass').value;
    //var imagecapcha=document.getElementById('ctl00_ContentPlaceHolder1_txtImageCapcha').value;
    if(trim(username)=='')
    {
        alert('Please enter your email address');
        document.getElementById('ctl00_ContentPlaceHolder1_txtmail').focus();
        return false;
    }
    else if(trim(password)=='')
    {
        alert('Please enter your password');
        document.getElementById('ctl00_ContentPlaceHolder1_txtpass').focus();
        return false;
    }
    /*else if(trim(imagecapcha)=='')
    {
        alert('Please enter the text that you see in the image');
        document.getElementById('ctl00_ContentPlaceHolder1_txtImageCapcha').focus();
        return false;
    }
    else if(trim(imagecapcha)!='')
    {
        var xmlHttp=getreq();
        var url="/ajax/email-and-capcha.aspx";
        url=url+"?capcha="+document.getElementById("ctl00_ContentPlaceHolder1_txtImageCapcha").value;                         
        imgHTTP.open('GET',url,false);                               
        imgHTTP.send(null);                			
         if(imgHTTP.responseText =='1')
        {				
            alert('Please enter the correct text');
            document.getElementById('ctl00_ContentPlaceHolder1_txtImageCapcha').focus(); 
             return false;         
        }          
    } */
    return true;       
}

function signup()
{    

    var email=trim(document.getElementById("signup").value);  
  //   document.getElementById("signup").className="signup_img";
  //   email.style.display="none";   
      
    if(email == "-- Email Address --")
    {
        alert("Please enter your email address");
        return;
    }
    else if(checkEmail(email))
    {    
    var time=new Date();
        document.getElementById("btsubmit").style.display ="none";
        var xmlHttp=getreq();
        var url="/ajax/signup.aspx";    
        url=url+"?email="+email+"&time=" +time.getTime();  
                                  
        imgHTTP.open('GET',url);   
        imgHTTP.onreadystatechange = getalert;
        imgHTTP.send(null);        
      //  alert("Thank you. You have been subscribed to the GP Supplies newsletter.");
        document.getElementById("btsubmit").style.display ="block";
        document.getElementById("signup").value ="-- Email Address --";  	
    }
    
}

function getalert()

{ 
    if (imgHTTP.readyState==4)
     {     
     
       response = imgHTTP.responseText;
   alert(response);
        if (response=="1")  
        {
          alert("You are already subscribed to the GP Supplies newsletter.");
        }
        else if(response=="2")  
        {
         alert("Thank you.You have been subscribed to the GP Supplies newsletter.");
        }

     }

}


function checkEmail(strReceived)
{
    var emailRegex=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(2([0-4]\d|5[0-5])|1?\d{1,2})(\.(2([0-4]\d|5[0-5])|1?\d{1,2})){3} \])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    if(!emailRegex.test(strReceived))
    {
        return false;
    }			
	return true;
}

/****for voucher***********/
 function validate()
    {
                temp = confirm('Do you want to move Orders');
				if (temp)
				{
					return true ;
				}
				else
				{
				   return false ;
				}
    }
    
    
    /*for registration page*/
    
    
     function cmb_change()
    {
        if (document.getElementById("ctl00_ContentPlaceHolder1_cmbTradingStyle").value == "Dentist")
        {
            document.getElementById("p_type").innerHTML = "Reg No";
        }
        else
        {
            document.getElementById("p_type").innerHTML = "GMC number";
        }
    }

/*for confirm shipping*******/
function  visiblebtn()
{

var obj3=document.getElementById("ctl00_ContentPlaceHolder1_lnkBtnConfirmShipping");
obj3.style.display="none";
return true ;
 
 }
 /* file import/export*/
 function validate1()
 {
 
 var suppliername=document.getElementById("ctl00_ContentPlaceHolder1_manu_ref_txt").value;
 if(suppliername =="")
 {
 alert ("Please Select altest one");return false;
 }
 
 }
 


function uploadfile()
{


var upload=document.getElementById("ctl00$ContentPlaceHolder1$FileUpload1").value;
if(upload=="")
{

alert("Please select file");
return false;

}

}