﻿// JScript File
function LeadAccessEdit(leadid) {    
    document.getElementById("access_container").style.display = "block";
    LeadAccessRefresh(leadid);
}
function showMenu(obj) { 
    var rightedge = document.body.clientWidth-event.clientX; 
    var bottomedge = document.body.clientHeight-event.clientY; 
    if (rightedge < document.getElementById(obj).offsetWidth) { 
        document.getElementById(obj).style.left = document.body.scrollLeft + event.clientX - document.getElementById(obj).offsetWidth; 
    } else {
        document.getElementById(obj).style.left = document.body.scrollLeft + event.clientX;
    }
    if (bottomedge < document.getElementById(obj).offsetHeight) { 
        document.getElementById(obj).style.top = document.body.scrollTop + event.clientY - document.getElementById(obj).offsetHeight;
    } else {
        document.getElementById(obj).style.top = document.body.scrollTop + event.clientY;
    }    
    document.getElementById(obj).style.visibility = "visible";
    return false;
 }
 function showMenu2(obj,obj2) { 
    var rightedge = document.body.clientWidth-event.clientX; 
    var bottomedge = document.body.clientHeight-event.clientY; 
    var offset = findPos(obj2);
    if (rightedge < document.getElementById(obj).offsetWidth) { 
        document.getElementById(obj).style.left = document.body.scrollLeft + event.clientX - document.getElementById(obj).offsetWidth; 
    } else {
        document.getElementById(obj).style.left = document.body.scrollLeft + event.clientX;
    }
    document.getElementById(obj).style.top = offset + 20;
    document.getElementById(obj).style.visibility = "visible";
    return false;
 }
function hideMenu(obj) { document.getElementById(obj).style.visibility = "hidden"; }
function Ajax_ShowClaimStatus(membership,obj2) {    
    document.getElementById("claim_status").innerHTML = '';
    document.getElementById("claim_status").innerHTML = '<img src="../images/ajax3.gif"/>';    
    showMenu2('claim_status',obj2);
    var xmlHttp=GetXmlHttpObject();            
    if (xmlHttp==null) {
      alert ("Your browser does not support AJAX!");
      return;
    }
    
    xmlHttp.open("GET","../ajax/membership.aspx?m=show_claim&mid="+membership,true);    
    xmlHttp.onreadystatechange=function () {
        if(xmlHttp.readyState==4) {                            
            htmlDoc = xmlHttp.responseText;                        
            document.getElementById("claim_status").innerHTML = htmlDoc;
            setTimeout("hideMenu('claim_status')",10000);
        }
        if (xmlHttp.readyState != 4) return;
		if (xmlHttp.status != 200 && xmlHttp.status != 304) {
			return;
		}    
    }    
    xmlHttp.send(null);
    
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
        do {
			//curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }
    return curtop;
}

function showStatsDealers(stattype) {    
    document.getElementById("stats_dealers").innerHTML = '';
    document.getElementById("stats_dealers").innerHTML = '<img src="../images/ajax3.gif"/>';
    
    showMenu('stats_dealers');    
    var xmlHttp=GetXmlHttpObject();            
    if (xmlHttp==null) {
      alert ("Your browser does not support AJAX!");
      return;
    }
    xmlHttp.open("GET","../ajax/dealers.aspx?m=stats_dealers&stattype="+stattype,true);    
    xmlHttp.onreadystatechange=function () {
        if(xmlHttp.readyState==4) {        
            var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 
            xmlDoc.async = false;
            xmlDoc.loadXML(xmlHttp.responseText);            
            var x=xmlDoc.getElementsByTagName("list");
	        var htmlDoc="";
	        var name;
	        var stat;
	        if(x.length>0) {	        	            
	            htmlDoc += '<table>';
                for (i=0;i<x.length;i++) {                 
                    name = "";
                    if (x[i].getElementsByTagName("name")[0].childNodes[0]!= null) { name = x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue; }
                    if (x[i].getElementsByTagName("stat")[0].childNodes[0]!= null) { stat = x[i].getElementsByTagName("stat")[0].childNodes[0].nodeValue; }
                    
                    htmlDoc += '<tr>';
                    htmlDoc += '<td>'+name+'</td>';
                    htmlDoc += '<td style="text-align: right;">'+stat+'</td>';
                    htmlDoc += '</tr>';
                }
                htmlDoc += '</table>';
            }            
            document.getElementById("stats_dealers").innerHTML = htmlDoc;            
            document.getElementById("stats_dealers").style.display = "block";
        }
        if (xmlHttp.readyState != 4) return;
		if (xmlHttp.status != 200 && xmlHttp.status != 304) {
			return;
		}    
    }    
    xmlHttp.send(null);
}
function getSalesStat(userid) {    
    var xmlHttp=GetXmlHttpObject();            
    if (xmlHttp==null) {
      alert ("Your browser does not support AJAX!");
      return;
    }    
    if (method==1) {
    method=2;
    xmlHttp.open("GET","../ajax/salesstats.aspx?m=stat_newmoney&userid="+userid,true);
    document.getElementById("salesstats2").innerHTML = '<a href="javascript:void(0);" onclick="javascript:getSalesStat('+userid+');">show checks</a>';
    } else {
    method=1;
    xmlHttp.open("GET","../ajax/salesstats.aspx?m=stat_checks&userid="+userid,true);   
    document.getElementById("salesstats2").innerHTML = '<a href="javascript:void(0);" onclick="javascript:getSalesStat('+userid+');">show sales</a>';
    
    }
    xmlHttp.onreadystatechange=function () {        
        if(xmlHttp.readyState==4) {
            document.getElementById("salesstats").innerHTML = xmlHttp.responseText;            
        }
        if (xmlHttp.readyState != 4) return;
		if (xmlHttp.status != 200 && xmlHttp.status != 304) {
			return;
		}
    }
    xmlHttp.send(null);    
}
function LeadContactRefresh(leadid) {
    document.getElementById("contact_list").innerHTML = '<img src="../images/ajax3.gif"/>';
    var xmlHttp=GetXmlHttpObject();            
    if (xmlHttp==null) {
      alert ("Your browser does not support AJAX!");
      return;
    }
    xmlHttp.open("GET","../ajax/leads.aspx?m=contact_list&leadid="+leadid,true);    
    xmlHttp.onreadystatechange=function () {
        if(xmlHttp.readyState==4) {        
            var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 
            xmlDoc.async = false;
            xmlDoc.loadXML(xmlHttp.responseText);                    
            var x=xmlDoc.getElementsByTagName("list");
	        var htmlDoc="";
	        htmlDoc += '<table width="450" class="contact_list">';
            htmlDoc += '<tr class="rowheader">';
            htmlDoc += '<td width="40"></td>';
            htmlDoc += '<td width="160">Contact</td>';
            htmlDoc += '<td width="100">Phone</td>';                
            htmlDoc += '<td width="150">Email</td>';            
            htmlDoc += '</tr>';
            var contact;
            var phone;
            var email;
            var leadid;
            var contactid;
	        if(x.length>0) {	        	            
                for (i=0;i<x.length;i++) {                 
                    contact = "";
                    phone = "";
                    email = "";
                    leadid = "";
                    contactid = "";                    
                    if (x[i].getElementsByTagName("contact")[0].childNodes[0]!= null) { contact = x[i].getElementsByTagName("contact")[0].childNodes[0].nodeValue;       }          
                    if (x[i].getElementsByTagName("phone")[0].childNodes[0]!= null) { phone = x[i].getElementsByTagName("phone")[0].childNodes[0].nodeValue; }
                    if (x[i].getElementsByTagName("email")[0].childNodes[0]!= null) { email = x[i].getElementsByTagName("email")[0].childNodes[0].nodeValue; }
                    if (x[i].getElementsByTagName("leadid")[0].childNodes[0]!= null) { leadid = x[i].getElementsByTagName("leadid")[0].childNodes[0].nodeValue; }
                    if (x[i].getElementsByTagName("contactid")[0].childNodes[0]!= null) { contactid = x[i].getElementsByTagName("contactid")[0].childNodes[0].nodeValue; }
                    htmlDoc += '<tr>';
                    htmlDoc += '<td align="center">';
                    htmlDoc += '<a href="Javascript:LeadContactEdit('+leadid+','+contactid+');"><img src="../images/icon_edit.png" border="0" alt="Edit" /></a>&nbsp;';
                    htmlDoc += '<a href="Javascript:LeadContactDelete('+leadid+','+contactid+');"><img src="../images/icon_remove.png" border="0" alt="Delete" /></a>';
                    htmlDoc += '</td>';
                    htmlDoc += '<td style="text-transform: capitalize;">'+contact+'</td>';
                    htmlDoc += '<td>'+phone+'</td>';
                    htmlDoc += '<td><img oncontextmenu="javascript:updateContactID('+contactid+');javascript:showmenuie5();" src="../images/pn_inbox.gif" /> '+email+'</td>';                    
                    htmlDoc += '</tr>';
                }            
            }
            htmlDoc += "</table>";        
            document.getElementById("contact_list").innerHTML = htmlDoc;
        }
        if (xmlHttp.readyState != 4) return;
		if (xmlHttp.status != 200 && xmlHttp.status != 304) {
			return;
		}    
    }    
    xmlHttp.send(null);
}
function LeadAccessRefresh(leadid) {    
    var xmlHttp=GetXmlHttpObject();            
    if (xmlHttp==null) {
      alert ("Your browser does not support AJAX!");
      return;
    }    
    xmlHttp.open("GET","../ajax/leads.aspx?m=access_list&leadid="+leadid,true);    
    xmlHttp.onreadystatechange=function () {
        if(xmlHttp.readyState==4) {        
            var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 
            xmlDoc.async = false;
            xmlDoc.loadXML(xmlHttp.responseText);
            //alert(xmlHttp.responseText);
            document.getElementById("debug").value = xmlHttp.responseText;
            var x=xmlDoc.getElementsByTagName("list");
	        var htmlDoc="";
	        htmlDoc += '<table style="width: 300px;">';
            htmlDoc += '<tr class="rowheader">';
            htmlDoc += '<td style="width: 50px;"></td>';
            htmlDoc += '<td style="width: 350px;">Name</td>';
            htmlDoc += '</tr>';
	        if(x.length>0) {	        	            
                for (i=0;i<x.length;i++) {                 
                    userid = x[i].getElementsByTagName("userid")[0].childNodes[0].nodeValue;                
                    hasaccess = x[i].getElementsByTagName("hasaccess")[0].childNodes[0].nodeValue;
                    userfullname = x[i].getElementsByTagName("userfullname")[0].childNodes[0].nodeValue;                    
                    htmlDoc += '<tr>';
                    htmlDoc += '<td align="center">';
                    if(hasaccess!=0) {
                        htmlDoc += '<input type="checkbox" name="access_userid" value="'+userid+'" checked="checked" />';
                    } else {
                        htmlDoc += '<input type="checkbox" name="access_userid" value="'+userid+'" />';
                    }                    
                    htmlDoc += '</td>';
                    htmlDoc += '<td style="text-transform: capitalize;">'+userfullname+'</td>';
                    htmlDoc += '</tr>';
                }            
            }
            htmlDoc += "</table>";        
            document.getElementById("access_list").innerHTML = htmlDoc;
        }
        if (xmlHttp.readyState != 4) return;
		if (xmlHttp.status != 200 && xmlHttp.status != 304) {
//			alert('HTTP error ' + req.status);
			return;
		}    
    }    
    xmlHttp.send(null);    
}
 
function LeadContactEdit(leadid,contactid) {    
    var xmlHttp=GetXmlHttpObject();            
    if (xmlHttp==null) {
      alert ("Your browser does not support AJAX!");
      return;
    }
    xmlHttp.open("GET","../ajax/leads.aspx?m=contact_get&leadid="+leadid+"&contactid="+contactid,true);
    xmlHttp.onreadystatechange=function () {
        if(xmlHttp.readyState==4) {        
            var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 
            xmlDoc.async = false;
            xmlDoc.loadXML(xmlHttp.responseText);        
            var x=xmlDoc.getElementsByTagName("list");
            var fname=""; var lname=""; var sname=""; var phonea=""; var phonef=""; var phonel=""; var phonex=""; var email=""; var title=""; var leadid=""; var contactid="";
	        if(x.length>0) {              
                fname = x[0].getElementsByTagName("fname")[0].childNodes[0].nodeValue;                
                lname = x[0].getElementsByTagName("lname")[0].childNodes[0].nodeValue;                
                sname = x[0].getElementsByTagName("sname")[0].childNodes[0].nodeValue;                
                phonea = x[0].getElementsByTagName("phonea")[0].childNodes[0].nodeValue;
                phonef = x[0].getElementsByTagName("phonef")[0].childNodes[0].nodeValue;
                phonel = x[0].getElementsByTagName("phonel")[0].childNodes[0].nodeValue;
                if(x[0].getElementsByTagName("phonex")[0].childNodes[0] != null) {
                    phonex = x[0].getElementsByTagName("phonex")[0].childNodes[0].nodeValue;
                }                
                email = x[0].getElementsByTagName("email")[0].childNodes[0].nodeValue;
                title = x[0].getElementsByTagName("title")[0].childNodes[0].nodeValue;
                leadid = x[0].getElementsByTagName("leadid")[0].childNodes[0].nodeValue;
                contactid = x[0].getElementsByTagName("contactid")[0].childNodes[0].nodeValue;
                
                
                document.getElementById("contact_edit_contactid").value = contactid;
                document.getElementById("contact_edit_phonea").value = phonea;
                document.getElementById("contact_edit_phonef").value = phonef;
                document.getElementById("contact_edit_phonel").value = phonel;
                document.getElementById("contact_edit_phonex").value = phonex;
                document.getElementById("contact_edit_title").value = title;
                document.getElementById("contact_edit_fname").value = fname;
                document.getElementById("contact_edit_lname").value = lname;
                document.getElementById("contact_edit_sname").value = sname;
                document.getElementById("contact_edit_email").value = email; 
                
                showDiv("#contact_edit_container");                
            }            
        }
        if (xmlHttp.readyState != 4) return;
		if (xmlHttp.status != 200 && xmlHttp.status != 304) {
//			alert('HTTP error ' + req.status);
			return;
		}    
    }    
    xmlHttp.send(null);    
}   
function ProductsTypeID(categoryid) {    
    var xmlHttp=GetXmlHttpObject();    
    document.getElementById("product_types").innerHTML = "";
    document.getElementById("shipfee").value = "0";
    if (xmlHttp==null) {
      alert ("Your browser does not support AJAX!");
      return;
    }
    xmlHttp.open("GET","../ajax/products.aspx?m=product_types&categoryid="+categoryid,true);
    xmlHttp.onreadystatechange=function () {
        if(xmlHttp.readyState==4) {        
            var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 
            xmlDoc.async = false;
            xmlDoc.loadXML(xmlHttp.responseText);            
            var x=xmlDoc.getElementsByTagName("list");
            var htmlDoc="";
            if (x.length > 0) {
                var subcategory;
                var subcategoryid;
                htmlDoc = '<select name="product_type" onchange="javascript:ReturnSHByTypeID(this.value);">';
                htmlDoc += '<option value="0">Select one</option>';
                for (i=0;i<x.length;i++) {                 
                    subcategoryid = x[i].getElementsByTagName("categoryid")[0].childNodes[0].nodeValue;                
                    subcategory = x[i].getElementsByTagName("category")[0].childNodes[0].nodeValue;
                    htmlDoc += '<option value="'+subcategoryid+'">'+subcategory+'</option>';
                }
                htmlDoc += '</select>';
            }
            document.getElementById("product_types").innerHTML = htmlDoc;
        }
        
                
        if (xmlHttp.readyState != 4) return;
		if (xmlHttp.status != 200 && xmlHttp.status != 304) {
			return;
		}    
    }    
    xmlHttp.send(null);    
}   
function ReturnSHByTypeID(subcategoryid) {
    $("shipfee").load("../ajax/products.aspx?m=fee_sh_by_typeid&SUBcategoryid="+subcategoryid);
}   
function LeadNoteEdit(leadid,noteid) {    
    var xmlHttp=GetXmlHttpObject();            
    if (xmlHttp==null) {
      alert ("Your browser does not support AJAX!");
      return;
    }
    xmlHttp.open("GET","../ajax/leads.aspx?m=note_get&leadid="+leadid+"&noteid="+noteid,true);
    xmlHttp.onreadystatechange=function () {
        if(xmlHttp.readyState==4) {        
            var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 
            xmlDoc.async = false;
            xmlDoc.loadXML(xmlHttp.responseText);        
            var x=xmlDoc.getElementsByTagName("list");
            var fname=""; var lname=""; var sname=""; var phonea=""; var phonef=""; var phonel=""; var phonex=""; var email=""; var title=""; var leadid=""; var contactid="";
	        if(x.length>0) {              
                note = x[0].getElementsByTagName("note")[0].childNodes[0].nodeValue;                
                document.getElementById("note_edit_noteid").value = noteid;
                document.getElementById("note_edit_note").value = note;                
                showDiv("#note_edit_container");                
            }            
        }
        if (xmlHttp.readyState != 4) return;
		if (xmlHttp.status != 200 && xmlHttp.status != 304) {
//			alert('HTTP error ' + req.status);
			return;
		}    
    }    
    xmlHttp.send(null);    
}   
function LeadNoteRefresh(leadid) {    
    document.getElementById("note_list").innerHTML = '<img src="../images/ajax3.gif"/>';
    var xmlHttp=GetXmlHttpObject();            
    if (xmlHttp==null) {
      alert ("Your browser does not support AJAX!");
      return;
    }
    
    xmlHttp.open("GET","../ajax/leads.aspx?m=note_list&leadid="+leadid,true);
    xmlHttp.onreadystatechange=function () {        
        if(xmlHttp.readyState==4) {  
            //document.getElementById("htmld").innerText = xmlHttp.responseText;	        
            var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 
            xmlDoc.async = false;             
            xmlDoc.loadXML(xmlHttp.responseText);        
            //document.getElementById("debug").value = xmlHttp.responseText;
            var x=xmlDoc.getElementsByTagName("list");        
            var htmlDoc="";
            htmlDoc += '<table class="note_list" width="100%">';		 
            htmlDoc += '<tr class="rowheader">';
            htmlDoc += '<td width="40"></td>';
            htmlDoc += '<td width="15%">Date</td>';
            htmlDoc += '<td width="10%">Rep</td>';
            htmlDoc += '<td width="75%">Note</td>';            
            htmlDoc += '</tr>';             
            if(x.length>0) {	        
                var postdate=""; var username=""; var note=""; var noteid="";
                for (i=0;i<x.length;i++) {                    
                    postdate = x[i].getElementsByTagName("postdate")[0].childNodes[0].nodeValue;                
                    username = x[i].getElementsByTagName("username")[0].childNodes[0].nodeValue;
                    note = x[i].getElementsByTagName("note")[0].childNodes[0].nodeValue;
                    note = note.replace("\n","<br/>");
                    noteid = x[i].getElementsByTagName("noteid")[0].childNodes[0].nodeValue;                    
                    htmlDoc += '<tr>';                    
                    htmlDoc += '<td valign="top" align="center">';                    
                    htmlDoc += '<a href="Javascript:LeadNoteEdit('+leadid+','+noteid+');"><img src="../images/icon_edit.png" border="0" alt="Edit" /></a>&nbsp;';
                    htmlDoc += '<a href="Javascript:LeadNoteDelete('+leadid+','+noteid+');"><img src="../images/icon_remove.png" border="0" alt="Delete" /></a>';
                    htmlDoc += '</td>';
                    htmlDoc += '<td valign="top">'+postdate+'</td>';
                    htmlDoc += '<td valign="top">'+username+'</td>';
                    htmlDoc += '<td valign="top">'+note+'</td>';                    
                    htmlDoc += '</tr>';
                }            
            }
            htmlDoc += "</table>";        
            document.getElementById("note_list").innerHTML = htmlDoc;
        }	
    }        
    xmlHttp.send(null);
} 
function LeadDBARefresh(leadid) {    
    document.getElementById("dba_list").innerHTML = '<img src="../images/ajax3.gif"/>';
    var xmlHttp=GetXmlHttpObject();            
    if (xmlHttp==null) {
      alert ("Your browser does not support AJAX!");
      return;
    }
    xmlHttp.open("GET","../ajax/leads.aspx?m=dba_list&leadid="+leadid,true);
    xmlHttp.onreadystatechange=function () {        
        if(xmlHttp.readyState==4) {  
            //document.getElementById("htmld").innerText = xmlHttp.responseText;	        
            var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 
            xmlDoc.async = false;             
            xmlDoc.loadXML(xmlHttp.responseText);        
            var x=xmlDoc.getElementsByTagName("list");        
            var htmlDoc="";
            htmlDoc += '<table class="dba_list" width="300">';		 
            htmlDoc += '<tr class="rowheader">';
            htmlDoc += '<td width="40"></td>';
            htmlDoc += '<td width="110">DBA Name</td>';
            htmlDoc += '<td width="150">DBA Url</td>';
            htmlDoc += '</tr>';   
            if(x.length>0) {	        
                var dba;
                var url;
                var dbaid;
                var leadid;
                for (i=0;i<x.length;i++) {                 
                    dba = x[i].getElementsByTagName("dba")[0].childNodes[0].nodeValue;                
                    url = x[i].getElementsByTagName("url")[0].childNodes[0].nodeValue;
                    dbaid = x[i].getElementsByTagName("dbaid")[0].childNodes[0].nodeValue;
                    leadid = x[i].getElementsByTagName("leadid")[0].childNodes[0].nodeValue;
                    htmlDoc += '<tr>';
                    htmlDoc += '<td align="center">';
                    htmlDoc += '<a href="Javascript:LeadDBAEdit('+leadid+','+dbaid+',\''+dba+'\',\''+url+'\');"><img src="../images/icon_edit.png" border="0" alt="Edit" /></a>&nbsp;';
                    htmlDoc += '<a href="Javascript:LeadDBADelete('+leadid+','+dbaid+');"><img src="../images/icon_remove.png" border="0" alt="Delete" /></a>';
                    htmlDoc += '</td>';
                    htmlDoc += '<td>'+dba+'</td>';
                    htmlDoc += '<td>'+url+'</td>';                    
                    htmlDoc += '</tr>';
                }            
            }
            htmlDoc += "</table>";        
            document.getElementById("dba_list").innerHTML = htmlDoc;
        }	
    }        
    xmlHttp.send(null);
} 