﻿var chkval="";
var newdd1
var fc = 0
 var finalcnt = 0
function GetXmlHttpObject()
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
	objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
	objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
} 
function add_to_cart(hid,type)
{    
    var qty;
    var colorval;
    var sizeval;
    var query = unescape(window.location);
    var keyword = query.toString();
    keyword = keyword.split('?');
    if (keyword.length > 1) 
    {
        keyword = keyword[1].split('&');
        for (var kw = 0; kw < keyword.length; kw++)
         {
            if (keyword[kw].search('keyword') == 0)
             {
                keyword = keyword[kw].split('=');
                keyword = keyword[1].replace(/#/gi, '');

                break;
            }
        }
    }
  
    
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
    alert ("Browser does not support HTTP Request")
    return
    } 
        cFlag = 0;
        sFlag = 0;
        if (document.getElementById("colorval_" + hid) || document.getElementById("sizeval_" + hid))
        {
            if(document.getElementById("colorval_" + hid))
            {
                colorval = document.getElementById("colorval_" + hid).value;
                if (colorval != "")
                    cFlag = 1;
                else
                    cFlag = 2;
            }
            if(document.getElementById("sizeval_" + hid))
            {
                sizeval = document.getElementById("sizeval_" + hid).value;
                 sFlag = 2;
                if (sizeval != "")
                    sFlag = 1;
            }
           
            if(cFlag == 2 && sFlag == 0)
            {
                alert("Please select a color");
                document.getElementById("colorval_" + hid).focus();
                return;
            }
            if(cFlag == 0 && sFlag == 2)
            {
                alert("Please select a size");
                document.getElementById("sizeval_" + hid).focus();
                return;
            }
            if(sFlag == 2 && cFlag == 2)
            {
                alert("Please select a color or size");
                document.getElementById("sizeval_" + hid).value;
                return;
            }        
        }
        
    if (type=="1")
        qty=document.getElementById("qty_" + hid).value;
     else 
        qty="1"

    if ((trim(qty)=="") || (qty=="0"))
    {
        alert("Kindly enter the order quantity")
        return;
    }
    else
     {
        var anum=/(^\d+$)|(^\d+\.\d+$)/
        if (!anum.test(qty))
        {
            alert("Kindly enter the order quantity")
            return;
        }
    }
    urlval = window.location.search
    partner = urlval.split("=")
    if (colorval == "undefined")
        colorval = '';
    if (sizeval == "undefined")
        sizeval = '';
    if (keyword == "undefined")
        keyword = '';
    //   alert(colorval);
     
    pageName = "/app/addtocart.aspx?Prodid=" + hid + "&quantity=" + qty + "&colorval=" + colorval + "&sizeval=" + sizeval + "&keyword=" + keyword;
   
    if(document.getElementById("neworderbut1"))
    {
        document.getElementById("neworderbut1").innerHTML ='';
        document.getElementById("neworderbut1").innerHTML ='<font class=\"green fnt-12\">Please wait....</font>';
    }
    if(document.getElementById("prodbuy_img2"))
    {
        document.getElementById("prodbuy_img2").innerHTML ='';
        document.getElementById("prodbuy_img2").innerHTML ='<font  class=\"green fnt-12\">Please wait...</font>';
    }
    var url= pageName
    xmlHttp.onreadystatechange= function() { qty_status(hid) };
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}	
function qty_status(hid) 
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {    
      var dds=xmlHttp.responseText;
      var constraint = xmlHttp.responseText;
        if (constraint==1)
        {
          //document.location = "https://www.gpsupplies.com/app/login.aspx"
          document.location = "https://www.normedica.co.uk/app/login.aspx"
            return;
        }
        if(constraint==2)
        {	           
         //document.location = "https://www.gpsupplies.com/app/PharmaAuthorization.aspx?pharmach=3"
         document.location = "https://www.normedica.co.uk/app/PharmaAuthorization.aspx?pharmach=3"
            return;
        }
        if(constraint==3)
        {
           //document.location = "https://www.gpsupplies.com/app/PharmaAuthorization.aspx?pharmach=4"
           document.location = "https://www.normedica.co.uk/app/PharmaAuthorization.aspx?pharmach=4"
            return;
        }        
          alert("This product has been added to your Order");
            document.getElementById("qty_" + hid).value = "";   
            window.location.reload();	                
            if(document.getElementById("neworderbut1"))
            {
                document.getElementById("neworderbut1").innerHTML ='';
                document.getElementById("neworderbut1").innerHTML ='<font class=\"fnt-12 green\">Please wait....</font>';
            }
            if(document.getElementById("prodbuy_img2"))
            {
                document.getElementById("prodbuy_img2").innerHTML ='';
                document.getElementById("prodbuy_img2").innerHTML ='<font class=\"fnt-12 green\">Please wait....</font>';
            }
      
    } 
}          

function add_to_cart_new(tcnt,newhid)
{           
    var size='';
    if(document.getElementById("colorcode1"))
    {
        var myString2=document.getElementById("colorcode1").value;
        var colorcode = myString2.split(","); 
    }
    var myString1=newhid.substring(0,newhid.length)
    var SplitName1 = myString1.split(","); 
    var colorcodearray=[];                          
    if(document.getElementById("colorcode1"))
    {
        var colorcodecount=(SplitName1.length)- colorcode.length;
        for(k=0;k<SplitName1.length;k++)
        {
            if(k<colorcodecount)
            colorcodearray[k]="";  
            else
            colorcodearray[k]=colorcode[k-colorcodecount];  
        }     
    }			  			
    var colorval_new;
    var qty;
    var ccode='';
    alflag = 0
    withval = 0  
    
    for (i = 0; i < SplitName1.length ; i++) 
    {             
        if(eval('document.forms[0].qty_' + SplitName1[i]))
        {
            if(document.getElementById('qty_'+SplitName1[i]).value != "")
            {                
                if(document.getElementById('sizeval_'+SplitName1[i])!=null)
                {                    
                    if(document.getElementById('sizeval_'+SplitName1[i]).value!=null)
                    {
                        var code=document.getElementById('sizeval_'+SplitName1[i]).value;                       
                        code=code.split(",");
                        ccode=code[0];
                         size=code[1];
                    }   
                }
                if(document.getElementById('colorval_'+SplitName1[i])!=null)
                {
                    if(document.getElementById('colorval_'+SplitName1[i]).value!='')
                    ccode=document.getElementById('colorval_'+SplitName1[i]).value
                }
                type =document.getElementById('qty_'+SplitName1[i]).value; 
                alflag = alflag + 1   
                var colorval = '';
                var sizeval = '';
                xmlHttp=GetXmlHttpObject()
                if (xmlHttp==null)
                {
                    alert("Browser does not support HTTP Request")
                    return
                } 
                cFlag = 0;
                sFlag = 0;
                if ((document.getElementById("colorval_" + SplitName1[i])) || (document.getElementById("sizeval_" + SplitName1[i])))
                {
                    if(document.getElementById("colorval_" + SplitName1[i]))
                    {
                        colorval = document.getElementById("colorval_" + SplitName1[i]).value;
                        if (colorval != "")
                        cFlag = 1;
                        else
                        cFlag = 2;
                    }
                    if(document.getElementById("sizeval_" + SplitName1[i]))
                    {
                        sizeval = document.getElementById("sizeval_" + SplitName1[i]).value;
                        if (sizeval != "")
                        sFlag = 1;
                        else
                        sFlag = 2;
                    }
                    if(cFlag == 2 && sFlag == 0)
                    {
                        alert("Please select a color");
                        document.getElementById("colorval_" + SplitName1[i]).focus();
                        return;
                    }
                    if(cFlag == 0 && sFlag == 2)
                    {
                        alert("Please select a size");
                        document.getElementById("sizeval_" + SplitName1[i]).focus();
                        return;
                    }
                    if(sFlag == 2 && cFlag == 2)
                    {
                        alert("Please select a color or size");
                        document.getElementById("sizeval_" + SplitName1[i]).value;
                        return;
                    }
                }

                if (type!= "")
                    qty=type;
                else
                    qty="1"

//                if ((trim(qty)=="") || (qty=="0"))
//                {
//                    alert("Kindly enter the order quantity")
//                    return;
//                }
//                else
//                {
                    var anum=/(^\d+$)|(^\d+\.\d+$)/
                    if (!anum.test(qty))
                    {
                        alert("Kindly enter the order quantity")
                        return;
                    }
//                }
                urlval = window.location.search
                partner = urlval.split("=")
                if (colorval == "undefined")
                colorval = ''
                if (sizeval == "undefined")
                sizeval = ''
                pageName = "/app/addtocart.aspx?Prodid=" + SplitName1[i] + "&quantity=" + qty + "&colorval=" + colorval + "&sizeval=" + sizeval + "&size=" + size + "&tcnt=" + alflag +"&colorcode=" + ccode +"&colorval_new=" + colorval_new;                
                var url= pageName	               	             
                xmlHttp.onreadystatechange= function(){qty_status_new(SplitName1[i])};
                xmlHttp.open("GET",url,true);
                xmlHttp.send(null);
            }
        }	
    }
   if(alflag==0)
   {
     alert("Kindly enter the order quantity");
                    return;
   }
    if(alflag != 0)
    {
        document.getElementById("neworderbut").innerHTML =''
        document.getElementById("neworderbut").innerHTML ='<font class=\"fnt-12 green\">Please wait....</font>'
       document.getElementById("neworderbut").focus();
    }
    if (alflag == 0)
        alert("Kindly enter the order quantity")
}


function qty_status_new(hid) 
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {      
        var dds=xmlHttp.responseText;         
        var constraint=xmlHttp.responseText;
        if (constraint==1)
        {
          //document.location = "https://www.gpsupplies.com/app/login.aspx"
          document.location = "https://www.normedica.co.uk/app/login.aspx"
            return;
        }
        if(constraint==2)
        {	           
          //document.location = "https://www.gpsupplies.com/app/PharmaAuthorization.aspx?pharmach=3"
          document.location = "https://www.normedica.co.uk/app/PharmaAuthorization.aspx?pharmach=3"
            return;
        }
        if(constraint==3)
        {
          //document.location = "https://www.gpsupplies.com/app/PharmaAuthorization.aspx?pharmach=4"
          document.location = "https://www.normedica.co.uk/app/PharmaAuthorization.aspx?pharmach=4"
            return;
        }
        if(withval == 0)
        {
            withval = withval + 1
            alert("Product/s have been added to your Order");
            window.location.reload();	 
        }
    } 
} 


function buttonTest(hid,type)
{
    var myString1=document.getElementById("colorcode").value;
    var SplitName1 = myString1.split(","); 
    var color=document.getElementById("colorval").value;
    color=color.split(",");
    var size=document.getElementById("sizeval").value;
    size=size.split(",");
    var qty;
    var hid=document.getElementById("hierarchy_id").value;
    var price=document.getElementById("prPrice1").value;
    alflag = 0;
    withval = 0; 
    var cnt=0;
    for (i = 0; i < SplitName1.length-1 ; i++) 
    { 
        try
        {
            if(eval('document.forms[0].qty_' + SplitName1[i] + '.value')!="") 
            {
                cnt=1;
                type =eval('document.forms[0].qty_' + SplitName1[i] + '.value');
                qty=type;
                alflag = alflag + 1   
                var colorval = '';
                var sizeval = '';
                xmlHttp=GetXmlHttpObject();
                if (xmlHttp==null)
                {
                    alert("Browser does not support HTTP Request");
                    return;
                }            
                colorval =color[i];                   
                sizeval = size[i];                      
                urlval = window.location.search;

                partner = urlval.split("=");
                if(qty != "0")
                {
                    pageName = "/app/addtocart.aspx?Prodid=" + hid + "&quantity=" + qty + "&colorcode=" + SplitName1[i] + "&colorval=" + colorval + "&price=" + price + "&sizeval=" + sizeval + "&tcnt=color"; 
                }
                var url= pageName;
                xmlHttp.open("GET",url,true);
                xmlHttp.send(null);
                if(alflag != 0)
                {
                    document.getElementById("neworderbut").innerHTML =''
                    document.getElementById("neworderbut").innerHTML ='<font class="green fnt-12">Please wait....</font>'
                }
            }
        }
        catch(e){}
    }	
    xmlHttp.onreadystatechange= addcart;
    if(cnt==0)
    {
        alert("Kindly enter the order quantity")
        return;
    }
}
function addcart()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {     
        var dds=xmlHttp.responseText;         
        var constraint=xmlHttp.responseText;       
        if (constraint==1)
        {
         //document.location = "https://www.gpsupplies.com/app/login.aspx"
          document.location = "https://www.normedica.co.uk/app/login.aspx"
            return;
        }
        if(constraint==2)
        {	           
          //document.location = "https://www.gpsupplies.com/app/PharmaAuthorization.aspx?pharmach=3"
          document.location = "https://www.normedica.co.uk/app/PharmaAuthorization.aspx?pharmach=3"
            return;
        }
        if(constraint==3)
        {
          //document.location = "https://www.gpsupplies.com/app/PharmaAuthorization.aspx?pharmach=4"
         document.location = "https://www.normedica.co.uk/app/PharmaAuthorization.aspx?pharmach=4"
            return;
        }
        //alert(dds);
        alert("This product's has been added to your Order");  
        window.location.reload();	
    }
}
    
var hid1;    
function getsize(prevID,obj,hid)
{     
    hid1 =hid;
    if(prevID!=null && obj.value!='')
        pageName = "/app/getsize-value.aspx?Prodid=" + prevID +"&color=" + obj.options[obj.selectedIndex].text +"&hid=" +hid;               
    xmlHttp=GetXmlHttpObject();     
    xmlHttp.onreadystatechange= getvalue1;  
    xmlHttp.open("GET",pageName,true);
    xmlHttp.send(null);
   
}        
function getvalue1()
{    
    if (xmlHttp.readyState==4)
        document.getElementById("span_"+hid1).innerHTML=xmlHttp.responseText;
}   

function qtychange(orderid,obj)
{	   

//alert(orderid);
//alert(obj.value);
document.getElementById("ctl00_ContentPlaceHolder1_hfOrderID").value=orderid +",";
if(obj.value==0)obj.value=1;

document.getElementById("ctl00_ContentPlaceHolder1_hfQuanity").value=obj.value + ",";
 //   qty = obj.value	
//document.getElementById("ctl00_ContentPlaceHolder1_change_btn").click();
//document.getElementById("txtquan_" + orderid).className="signup_img";
 

//	qty = obj.value	
//	obj.className="gry_img grey1";
//	if (qty == "" || qty == "0" )
//	{
//       qty = 1;
//       obj.value=qty;
//    }   
//    xmlHttp=GetXmlHttpObject(); 
//    var url="/ajax/delete-add-quantity.aspx?type=add&rowid="+orderid+"&quantity="+qty;   
//    xmlHttp.open("GET",url,false);
//    xmlHttp.send(null); 
//  //  location.reload(true);    
          
}
function numeric(e)
{
    var key;
    if(document.all)
        key=e.keyCode;
    else if(document.getElementById)    
        key=e.which;
    else
        key=e.keyCode;    
    if(key>=48 && key<=57 || key>=96 && key<=105 || key==8)
    {
        return true; 
    }
     return false;                       
}
function deleteproduct()
{
    var element=document.getElementsByTagName("input");
    var i=0;
    var bool=false;
    var rowids="";   
    for(i=0;i<element.length;i++)
    {
        if(element[i].type=='checkbox' && element[i].checked==true)
        {
            bool=true;
            if(rowids=='')
                rowids=element[i].value;
            else
                rowids=rowids+","+element[i].value;    
        }    
    }
    if(bool==true)
        bool=confirm("Are you sure want to delete?");
    else
        alert("Please select atleast one product");
    if(bool==true)
    {        
        xmlHttp=GetXmlHttpObject(); 
        var url="/ajax/delete-add-quantity.aspx?type=delete&rowid="+rowids;   
        xmlHttp.open("GET",url,false);
        xmlHttp.send(null);       
        location.reload(true); 
    }    
        
}
function confirmshipping()
{
    document.forms[0].method="post";
    document.forms[0].action="/app/confirmshipping.aspx";
    document.forms[0].submit();
}
function voucher()
{
    document.getElementById('ctl00_ContentPlaceHolder1_hfVoucherCode').value=document.getElementById('vouchercode').value;
if (trim(document.getElementById('vouchercode').value)!='')
    document.getElementById('ctl00_ContentPlaceHolder1_btnVoucherEvent').click();
else
    alert("Please enter a valid voucher number");
return;
}

function pdtcode(hid)
{
    var id=document.getElementById("dp1").value;
    document.getElementById("getid").style.display = "none";
    if(id!="")
    {
        xmlHttp=GetXmlHttpObject()
        if (xmlHttp==null)
        {
            alert ("Browser does not support HTTP Request")
            return
        } 
	    str = document.getElementById("dp1").value
	    var url="/app/Productcode.aspx"
	    url=url+"?str="+str
	    url=url+"&hid="+hid
	    xmlHttp.onreadystatechange=stateChanged1 
	    xmlHttp.open("GET",url,true)
	    xmlHttp.send(null)
	    document.getElementById("img1").style.display = "block";
	    document.getElementById("getid").style.display = "block";
    } 
    if(id=="")
    {   
        document.getElementById("getid").style.display = "none";
        alert("Please Select Product Code");
        return false; 
    }
}

function stateChanged1() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
	    var responsetext=xmlHttp.responseText.split("$");	
	   // alert(xmlHttp.responseText);	       
        document.getElementById("getid").innerHTML=responsetext[0]; 
        document.getElementById("getid").style.display = "block";
        document.getElementById("img1").style.display = "none";
	   
	} 
} 

function add_to_cart_single(hid,type)
{
   
    var qty;
    var colorval;
    var sizeval;
    alflag=0;
    xmlHttp1=GetXmlHttpObject()
    if (xmlHttp1==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    } 
    cFlag = 0;
    sFlag = 0;
    if ((document.getElementById("colorval_" + hid)) || (document.getElementById("sizeval_" + hid)))
    {
        alflag = alflag + 1 
        if(document.getElementById("colorval_" + hid))
        {
            colorval = document.getElementById("colorval_" + hid).value;
             cFlag = 2;
            if (colorval != "")
                cFlag = 1;
        }
        if(document.getElementById("sizeval_" + hid))
        {
            sizeval = document.getElementById("sizeval_" + hid).value;
            sFlag = 2;
            if (sizeval != "")
                sFlag = 1;
        }
        if(cFlag == 2 && sFlag == 0)
        {
            alert("Please select a color");
            document.getElementById("colorval_" + hid).focus();
            return;
        }
        if(cFlag == 0 && sFlag == 2)
        {
            alert("Please select a size");
            document.getElementById("sizeval_" + hid).focus();
            return;
        }
        if(sFlag == 2 && cFlag == 2)
        {
            alert("Please select a color or size");
            document.getElementById("sizeval_" + hid).value;
            return;
        }
    }
    if (type=="1")
        qty=document.getElementById("qty_" + hid).value;
    else 
        qty="1"
	if ((trim(qty)=="") || (qty=="0"))
    {
	    alert("Kindly enter the order quantity")
	    return;
    } 
    else 
    {
	    var anum=/(^\d+$)|(^\d+\.\d+$)/
	    if (!anum.test(qty))
	    {
	        alert("Kindly enter the order quantity")
	        return;
	    }
    }
    urlval = window.location.search
    partner = urlval.split("=")
    if (colorval == "undefined")
        colorval = ''
    if (sizeval == "undefined")
        sizeval = ''
    if(qty!="")
    {
        hierachy=document.getElementById("hid").value;	       
        pageName = "/app/addtocart.aspx?Prodid=" + hierachy + "&colorcode=" + hid + "&colorval=" + colorval + "&sizeval=" + sizeval+ "&quantity=" + qty ;               
    }
    var url= pageName
    xmlHttp1.onreadystatechange= function() { add_single(hid) };
    xmlHttp1.open("GET",url,true);
    xmlHttp1.send(null);
    if(alflag != 0)
    {
         document.getElementById("prodbuy_img1").innerHTML =''
         document.getElementById("prodbuy_img1").innerHTML ='<font class=\"green\">Please wait....</font>'
    }
}	
    
function add_single(hid)
{
    if (xmlHttp1.readyState==4 || xmlHttp1.readyState=="complete")
    {        
        alert("This product has been added to your Order");	
        var dds=xmlHttp1.responseText;            
        document.getElementById("qty_" + hid).value = ""                 
        window.location.reload();	    
    }
}


