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=='pp')
  {
  
      document.getElementById("topquick").style.display="block";
      document.getElementById("topquick").style.height="auto";
      document.getElementById("topquick").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!='topquick') || document.getElementById("topquick").style.display!="block")
  {      
      document.getElementById("topquick").style.display="none";	   	          
  }   
}
var timeout;
var timedelay=0;
function hideSearch()
{

    if(document.getElementById("topquick").style.display=="block")
    {
        if (timedelay==0)
		    document.getElementById("topquick").style.display="none";
	    else
	    {
		    timedelay=timedelay-1;
		    timeout=setTimeout("hideSearch()",1000);
		    document.getElementById("topquick").style.display="block";		
	    }
    }   
}
function hideSearchlist()
{       
    document.getElementById("topquick").style.display="none";
}
function showSearch()
{    
     if (typeof timeout!="undefined")
		clearTimeout(timeout);
    document.getElementById("topquick").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(); 



//To count the search word..
function validateSearch1()
{

    strval = trim(document.getElementById("pp").value);
    if(strval =="")
    {
        alert("Kindly enter the product you want to search");
        document.getElementById("pp").focus();
        return; 
    }
  //  document.getElementById("txtsearch").value = strval;
    document.forms[0].method ="post";
    document.forms[0].action ="/app/product-search.aspx";
    document.forms[0].submit();
}


var xmlHttp;
function searchcount(obj)
	{
	
	            time1=new Date();
                var searchkey=trim(obj.value);
                var now = new Date();
                var exitTime = now.getTime() + 200;
                var stop=1;
	            str = document.getElementById("pp").value
	 			xmlHttp=getreq()
				if (xmlHttp==null)
				{
				alert ("Browser does not support HTTP Request")
				return
				} 
			
				if(str.length > 3)
	            {
	              //  document.getElementById("topquick").style.display ="block"
	             //  document.getElementById("txtHint2").innerHTML= "<div  style='padding:5px 5px 5px 5px;width:215px;font-family:Trebuchet MS;font-size:11px;color:#000000;text-align:center;'>Please wait while we locate <br/>this product for you <br /></div>"
				    var url="/ajax/product-search.aspx";    
				     url=url+"?count=1&search="+searchkey+"&time="+time1.getTime();  
				    xmlHttp.onreadystatechange=clublayer 
				    xmlHttp.open("GET",url,true)
				    xmlHttp.send(null)
				    
				}    
			
	}
function clublayer2(obj)
	{
                time1=new Date();
                var searchkey=trim(obj.value);
                var now = new Date();
                var exitTime = now.getTime() + 200;
                var stop=1;
	            str = document.getElementById("pp").value
	 			xmlHttp=getreq()
				if (xmlHttp==null)
				{
				alert ("Browser does not support HTTP Request")
				return
				} 
				if(str.length > 3)
	            {
	                document.getElementById("topquick").style.display ="block"
	                document.getElementById("txtHint2").innerHTML= "<div  style='padding:5px 5px 5px 5px;width:215px;font:normal 0.75em Lucida Sans Unicode;color:#555555;text-align:center;'>Please wait while we locate <br/>this product for you <br /></div>"
				    var url="/ajax/product-search.aspx";    
				    url=url+"?search="+searchkey+"&time="+time1.getTime();  
    				xmlHttp.onreadystatechange=clublayer 
				    xmlHttp.open("GET",url,true)
				    xmlHttp.send(null)
				}    
	}
	
	function clublayer() 
	{ 
	    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 			
		document.getElementById("txtHint2").innerHTML=xmlHttp.responseText; 
		} 
	} 


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)!='')
    {
        document.forms[0].method="post";
        document.forms[0].action="/app/product-search.aspx";
        document.forms[0].submit();
    }
    else
        alert("Please enter the keyword to search");
}
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_txtoldpass').value);
    var newpassword= trim(document.getElementById('ctl00_ContentPlaceHolder1_txtnewpass').value);
    var confirmpassword= trim(document.getElementById('ctl00_ContentPlaceHolder1_txtconfirmpass').value);  
   
    if(oldpassword=='')
    {        
        document.getElementById('ctl00_ContentPlaceHolder1_txtoldpass').focus();
        alert(geterrmsg('e47'));
        return false;
    }   
    else if(newpassword=='')
    {
        document.getElementById('ctl00_ContentPlaceHolder1_txtnewpass').value='';
        document.getElementById('ctl00_ContentPlaceHolder1_txtnewpass').focus();
        alert(geterrmsg('e45'));
        return false;
    }
    else if(newpassword.length<6)
    {
        document.getElementById('ctl00_ContentPlaceHolder1_txtnewpass').value='';
        document.getElementById('ctl00_ContentPlaceHolder1_txtconfirmpass').value='';
        document.getElementById('ctl00_ContentPlaceHolder1_txtnewpass').focus();
        alert(geterrmsg('e21'));
        return false;
    }
    else if(confirmpassword=='')
    {
        document.getElementById('ctl00_ContentPlaceHolder1_txtconfirmpass').value='';
        document.getElementById('ctl00_ContentPlaceHolder1_txtconfirmpass').focus();
        alert(geterrmsg('e44'));
        return false;
    }
   
    else if(document.getElementById('ctl00_ContentPlaceHolder1_txtnewpass').value != document.getElementById('ctl00_ContentPlaceHolder1_txtconfirmpass').value)  
   
    {
   
        document.getElementById('ctl00_ContentPlaceHolder1_txtconfirmpass').value='';
        document.getElementById('ctl00_ContentPlaceHolder1_txtconfirmpass').focus();
        alert(geterrmsg('e48'));
        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_txtoldpass').value='';
            document.getElementById('ctl00_ContentPlaceHolder1_txtoldpass').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;
    }
 
    return true;       
}

function signup()
{    

    var email=trim(document.getElementById("signup").value);  
   
      
    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;

}

}