function popupForm(ctrl,width,height)
{
	width=width==null?500:width;
	height=height==null?500:height;
	window.open("PopupForm.aspx?em=ad&ctrl="+ctrl,"","toolbar=no,scrollbars=yes,resizable=yes,width="+width+",height="+height+"'");
}
function popupWindow(url,width,height)
{
	width=width==null?500:width;
	height=height==null?500:height;
	window.open(url,"","toolbar=no,scrollbars=yes,resizable=yes,width="+width+",height="+height+"'");
}
function ConfirmDelete()
{
	if (confirm("Are you sure to delete this item?"))
	{
		__doPostBack('btnDelete','');
	}
}
function findPos(obj)
{
    var curleft=curtop= 0;
    if(obj.offsetParent)
    {
        curleft=obj.offsetLeft;
        curtop=obj.offsetTop;
        while(obj=obj.offsetParent)
        {
            curleft +=obj.offsetLeft;
            curtop +=obj.offsetTop;
        }
    }
    return [curleft,curtop];
}
function addObjEvent(obj,event_name,func_name){
	if (obj.attachEvent){
		obj.attachEvent("on"+event_name, func_name);
	}else if(obj.addEventListener){
		obj.addEventListener(event_name,func_name,true);
	}else{
		obj["on"+event_name] = func_name;
	}
}
function dummy()
{
    //return false;
}
function showLayer(layerName,layerPos,layerLeft,layerTop)
{
    document.getElementById(layerName).style.visibility="visible";
    document.getElementById(layerName).style.display="block";
    if (layerPos=="absolute")
    {
		    document.getElementById(layerName).style.position="absolute";
		    document.getElementById(layerName).style.left=layerLeft;
		    document.getElementById(layerName).style.top=layerTop;
    }

}
function showLayer2(layerName,sender)
{
    document.getElementById(layerName).style.visibility="visible";
    document.getElementById(layerName).style.display="inline";
    pos=findPos(sender);
    document.getElementById(layerName).style.position="absolute";
    document.getElementById(layerName).style.left=pos[0];
    document.getElementById(layerName).style.top=pos[1]+sender.offsetHeight+1;
}

function hideLayer(layerName)
{
    document.getElementById(layerName).style.display="none";
    document.getElementById(layerName).style.visibility="hidden";
    
}

function getClientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function getClientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}


function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}


function SelectSubMenu(MenuName)    
{
    if (document.getElementById("tdB"+MenuName)!=null)
    {
        document.getElementById("tdB"+MenuName).className="SubMenuSelected";
        document.getElementById("hlkB"+MenuName).className="ASubMenuSel";
    }
}

function SelectPlaceTab(TabName)
{
    if (document.getElementById("tdP"+TabName)!=null)
    {
        document.getElementById("tdP"+TabName).className="sel";
        //document.getElementById("hlkP"+TabName).className="AGrayB";
    }

}

function SelectTab(TabName,className)
{
    if (document.getElementById("td"+TabName)!=null)
    {
        if (className!=null)
            document.getElementById("td"+TabName).className=className;
        else
            document.getElementById("td"+TabName).className="sel";
        //document.getElementById("hlk"+TabName).className="AGrayB";
       
    }

}

function confirmPostBack(message,button)
{
	if (confirm(message))
	{
		__doPostBack(button,'');
	}

}

function showBaloon(left,top,text)
{
    if (document.getElementById('divBaloon'))
    {
        //document.body.removeChild(document.getElementById('divBaloon'));
        return;
    } 
    objDiv= document.createElement('div');
    objDiv.id="divBaloon";
    objDiv.className="Baloon";
    objDiv.innerHTML=text;
    objDiv.style.position='absolute';
    objDiv.style.top=top+20;
    objDiv.style.left=left;
    document.body.appendChild(objDiv);
}

function hideBaloon()
{
    if (document.getElementById('divBaloon'))
    {
        document.body.removeChild(document.getElementById('divBaloon'));
    } 
}

function createPopupBG()
{
    if (document.getElementById('divOverlayBG'))
    {
        document.body.removeChild(document.getElementById('divOverlayBG'));
    }
    objDiv= document.createElement('div');
    objDiv.id="divOverlayBG";
    objDiv.className="popupbg";
    
    objDiv.style.position="absolute";
    objDiv.style.height=document.body.scrollHeight>document.body.clientHeight?document.body.scrollHeight:document.body.clientHeight;
    objDiv.style.top=0;
    objDiv.style.left=0;
    objDiv.style.width="100%";
    objDiv.style.visibility="visible";
    objDiv.style.display="block";
    objDiv.style.zIndex="50";
    document.body.appendChild(objDiv);
    

    if (document.getElementById('divOverlay'))
    {
        document.forms[0].removeChild(document.getElementById('divOverlay'));
    }
    var scrW;
    scrW=parseInt(screen.width);
    objDivO=document.createElement('div');
    objDivO.id="divOverlay";
    objDivO.className="popup";
    objDivO.style.zIndex="80";
    objDivO.style.width=800;
    //objDivO.style.height=400;
    objDivO.align="left";
    objDivO.style.visibility="visible";
    objDivO.style.display="block";
    objDivO.style.position="absolute";
    
    objDivO.style.top=f_scrollTop()+100+"px";
    objDivO.style.left=f_scrollLeft()+scrW/2-500/2+"px";
    
    document.forms[0].appendChild(objDivO);
    return objDivO
}

function createPopupFrame(pWidth,pHeight,pLeft,pTop)
{
    //objDivO=document.createElement('div');
    //objDivO.id="divOverlay";
    obj=document.getElementById("divOverlay");
    var scrW;
    if (pWidth==null)
        pWidth=500;
    //objDivO.className="popup";
    obj.style.zIndex="80";
    //scrW=parseInt(screen.width);
    scrW=getClientWidth();
    obj.style.width=pWidth;
    if (pHeight!=null)
        obj.style.height=pHeight;
    //objDivO.align="left";
    //objDivO.style.visibility="visible";
    //objDivO.style.display="block";
    //objDivO.style.position="absolute";
    
    if (pTop==null)
        obj.style.top=f_scrollTop()+100+"px";
    else
        obj.style.top=pTop+"px";
        
    if (pLeft==null)
        obj.style.left=f_scrollLeft()+scrW/2-pWidth/2+"px";
    else
        obj.style.left=pLeft+"px";
    
    //document.forms[0].appendChild(objDivO);
    return obj

}

function viewVideo(code,layerW,title)
{
    createPopupBG();
    objDivO=createPopupFrame(layerW);
   
    //objDivO.innerHTML="<div><TABLE class='HeaderRow9' cellSpacing='0' cellPadding='3' width='"+layerW+"' border='0'><TR><TD>"+title+"</TD><TD align=right><A href='javascript:closeVideo();'><IMG src='images/icons/close.gif' /></A></TD></TR></TABLE></div><div class='divBorder'>"+code+"</div>";
    
    objDivO.innerHTML="<div id=\"popuptitle\"><div class=\"title\">"+title+"</div><div class=\"close\"><A href=\"javascript:closeVideo();\"></A></div></div><div align='center'>"+code+"</div>";
    
}

function viewVideo2(videoId)
{
    createPopupBG();
    objDivO=createPopupFrame(500);
   
    
    xmlHttp = getXMLHTTP_();
    if (xmlHttp)
    {
	    requestUrl="/Lookup.aspx?id=fav&val="+videoId+"&rnd="+Math.random();
	    xmlHttp.onreadystatechange = viewVideoCallback;
	    xmlHttp.open("GET", requestUrl, true);
	    xmlHttp.send(null);
    }
    
    function viewVideoCallback()
    {
        
        if (xmlHttp.readyState == 4)
	    {
		    if (xmlHttp.status == 200)
		    {
			    eval("var d=" + xmlHttp.responseText);
			    if (d==null)
			    {
		            objDivO.innerHTML="<div id=\"popuptitle\"><div class=\"title\">Error</div><div class=\"close\"><A href=\"javascript:closeVideo();\"></A></div></div><div align='center'>Error loading video</div>";	        
			    }
			    else
			    {
			        objDivO.innerHTML="<div id=\"popuptitle\"><div class=\"title\">"+d.Name+"</div><div class=\"close\"><A href=\"javascript:closeVideo();\"></A></div></div><div align='center'>"+d.Embed+"</div>";	        
			    }
		    }
		    else
		    {
			    alert("There was a problem in retrieving the data:\n" + xmlHttp.statusText);
		    }
	    }
    }
			
}



function closeVideo()
{
    if (document.getElementById('divOverlay')){ document.forms[0].removeChild(document.getElementById('divOverlay')); }		
    if (document.getElementById('divOverlayBG')){ document.body.removeChild(document.getElementById('divOverlayBG')); }		
}


function showPopup2(layerName,title,layerW,layerH, left, top,callBackF)
{
    createPopupBG();
    objDivO=createPopupFrame(layerW+20,layerH,left,top);
    //document.getElementById(layerName).className="visible";
    document.getElementById(layerName).style.visibility="visible";
    document.getElementById(layerName).style.display="block";
    document.getElementById(layerName).style.margin="10px";
    //objDivO.innerHTML="<div><TABLE class='popuptitle' cellSpacing='0' cellPadding='3' width='"+layerW+"' border='0'><TR><TD>"+title+"</TD><TD align=right><A href=\"javascript:hidePopup2('"+layerName+"');\"><IMG src='images/icons/close.gif' /></A></TD></TR></TABLE></div>";
    objDivO.innerHTML="<div id=\"popuptitle\"><div class=\"title\">"+title+"</div><div class=\"close\"><A id='hlkClPop2' href=\"javascript:hidePopup2('"+layerName+"');\"></A></div></div>";
    objDivO.appendChild(document.getElementById(layerName));
    if (callBackF!=null)
        addObjEvent(document.getElementById("hlkClPop2"),"click",callBackF);
    
}

function hidePopup2(layer)
{
    if (layer!=null)
    {
        document.forms[0].appendChild(document.getElementById(layer));
        document.getElementById(layer).className="Hidden";
        document.getElementById(layer).style.visibility="hidden";
     }
        
    if (document.getElementById('divOverlayBG')){ document.body.removeChild(document.getElementById('divOverlayBG'));}
    if (document.getElementById('divOverlay')){ document.forms[0].removeChild(document.getElementById('divOverlay')); }
}
function showObject(objName)
{
    document.getElementById(objName).className="Visible";
}

function hideObject(objName)
{
    document.getElementById(objName).className="Hidden";
}


function getXMLHTTP_()
{
	var A = null;
	try{
		A = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e){
		try{
			A = new ActiveXObject("Microsoft.XMLHTTP");
		} catch(oc){
			A = null;
		}
	}
	if(!A && typeof XMLHttpRequest != "undefined") {
		A = new XMLHttpRequest();
	}
	return A;
}

var varMem;

function viewMember(memId)
{
    
    if (memId==varMemberId)
    {
        var loc="";
        loc=window.location.toString().toLowerCase();
        //if (loc.indexOf("myprofile.aspx")==-1)
        if (loc.substring(loc.lastIndexOf("/")+1)=="myself")
        {
            return ;
        }
        else
        {
            window.location=("/myself");
            return;
        }
    }
    
    xmlHttp = getXMLHTTP_();
    if (xmlHttp)
    {
	    varMem=memId;
	    requestUrl="/Lookup.aspx?id=mem&val="+memId+"&rnd="+Math.random();
	    xmlHttp.onreadystatechange = viewMemberCallback;
	    xmlHttp.open("GET", requestUrl, true);
	    xmlHttp.send(null);
    }			
    
}

function viewMemberCallback()
{
	if (xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200)
		{
			eval("var d=" + xmlHttp.responseText);
			if (d==null)
			{
			    window.location=("/myself/friends/"+varMem);
			}
			else
			{
			    createPopupBG();
			    obj=createPopupFrame(400);
			    var html;
			    var html2="";
			    html="<div id=\"popuptitle\"><div class=\"title\">Member Information</div><div class=\"close\"><A href=\"javascript:hidePopup2();\"></A></div></div><br class='lock' />";
			    if (memGroups!=undefined)
			    {
			        html2="<select  id='cmbMemberGroup_'>"
			        
				    for(var i=0; i<memGroups.length; i++)
				    {
				       html2+="<option value='"+memGroups[i].value+"' >"+memGroups[i].name+"</opption>"
				    }
				    html2+="</select>&nbsp;&nbsp;<a href='javascript:friendRequest("+d.id+",document.getElementById(\"cmbMemberGroup_\").value);' Class='ABlue3B'>Add</a>&nbsp;or&nbsp;<a class='ABlue3B' href='javascript:hideObject(\"divAddFriend_\");'>Cancel</a>"
			    }
			    //html+="<div><table width='100%'><tr><td width='100px' valign='top'><img src='"+(d.imageName=="Male" || d.imageName=="Female"?"/images/default/"+d.imageName+".jpg":"/UF/Members/"+d.id+"/th_"+d.imageName)+"' width='100px' /></td><td valign='top' align='left' class='GrayText'><div style='margin:2px'>Name:&nbsp;<b>"+d.name+"</b></div><div style='margin:2px'>Location:&nbsp;"+d.location+"</div><div style='margin:4px'><a class='AAdd' href='javascript:showObject(\"divAddFriend_\");' >Add as Friend</a>&nbsp;</div><div id='divAddFriend_' class='Hidden'>"+html2+"</div></td></tr></table><br class='lock' /></div>";
                html+="<div><table width='100%'><tr><td width='100px' valign='top'><img src='"+(d.imageName=="Male" || d.imageName=="Female"?"/images/default/"+d.imageName+".jpg":"/UF/Members/"+d.id+"/th_"+d.imageName)+"' width='100px' /></td><td valign='top' align='left' class='GrayText'><div style='margin:2px'>Name:&nbsp;<b>"+d.name+"</b></div><div style='margin:2px'>Location:&nbsp;"+d.location+"</div></td></tr></table><br class='lock' /></div>";			    
			    obj.innerHTML=html;

			    
			}
		}
		else
		{
			alert("There was a problem in retrieving the data:\n" + xmlHttp.statusText);
		}
	}
	
}

function friendRequest(memberId,groupId)
{
    if (groupId=="-1" || groupId=="")
    {
        alert("Select Group");
        return;
    }
    
    xmlHttp = getXMLHTTP_();
    if (xmlHttp)
    {
	    requestUrl="/Lookup.aspx?id=frq&val="+memberId+"&group="+groupId+"&rnd="+Math.random();
	    xmlHttp.onreadystatechange = friendReqeustCallback;
	    xmlHttp.open("GET", requestUrl, true);
	    xmlHttp.send(null);
    }			
    
}

function friendReqeustCallback()
{
	if (xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200)
		{
			eval("var d= " + xmlHttp.responseText +" ;");
			if (d==1)
			{
			    alert("Friendship request sent successfuly");
			    hideObject("divAddFriend_");
			}
			if (d==-1)
			{
			    alert("You have already sent invitation to this person");
			}
			if (d==-2)
			{
			    alert("You are already invited by this person.");
			}
			
		}
    }
}


function populateList_(ctrlName,namevalue)
{
    if (oSelect = document.getElementById(ctrlName))
    {
	    var content = "";
		
	    // clear dropdownlist
	    for(var i=oSelect.length-1; i>=0; i--)
	    {
		    oSelect.options[i] = null;
	    }
	    // populate dropdownlist from name-value object
	    for(var i=0; i<namevalue.length; i++)
	    {
			
		    if (namevalue[i].value == undefined)
		    {
			    oSelect.options[oSelect.length] = new Option(namevalue[i].name);
			    content += namevalue[i].name + self.delimiter + namevalue[i].name + self.delimiter;
		    }
		    else
		    {
			    opt = new Option(namevalue[i].name, namevalue[i].value);
			    oSelect.options[oSelect.length] = opt;
			    content += namevalue[i].name + self.delimiter + namevalue[i].value + self.delimiter;
		    }
	    }

    }
}

function fillListAjax(obj,url)
{

    var objListToPop=obj;
    this.xmlHttp_=null;

    
    try
    {
        xmlHttp_ = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e){
        try{
	        xmlHttp_ = new ActiveXObject("Microsoft.XMLHTTP");
        } catch(oc){
	        xmlHttp_ = null;
        }
    }
    if(!xmlHttp_ && typeof XMLHttpRequest != "undefined") {
        xmlHttp_ = new XMLHttpRequest();
    }

    if (xmlHttp_)
    {
	    url=url+"&rnd="+Math.random();
	    xmlHttp_.onreadystatechange = fillListAjaxCallback;
	    xmlHttp_.open("GET", url, true);
	    xmlHttp_.send(null);
    }
    
    function fillListAjaxCallback()
    {
	    if (xmlHttp_.readyState == 4)
	    {
		    if (xmlHttp_.status == 200)
		    {
			    eval("var d= " + xmlHttp_.responseText +" ;");
		            var content = "";
            		namevalue=d;
		            // clear dropdownlist
		            for(var i=objListToPop.length-1; i>=0; i--)
		            {
			            objListToPop.options[i] = null;
		            }
		            // populate dropdownlist from name-value object
		            for(var i=0; i<namevalue.length; i++)
		            {
            			
			            if (namevalue[i].value == undefined)
			            {
				            objListToPop.options[objListToPop.length] = new Option(namevalue[i].name);
				            content += namevalue[i].name + self.delimiter + namevalue[i].name + self.delimiter;
			            }
			            else
			            {
				            opt = new Option(namevalue[i].name, namevalue[i].value);
				            objListToPop.options[objListToPop.length] = opt;
				            content += namevalue[i].name + self.delimiter + namevalue[i].value + self.delimiter;
			            }
		            }
	        }
	     }
    }
}

function getSelectText(objSelect)
{
    option=objSelect.options[objSelect.selectedIndex];
    return option.innerHTML;
}

function viewImage(imgSrc)
{
    objDivO=createPopupBG();
	objDivO.innerHTML='<img src="/images/ajax_loader.gif" />&nbsp;Loading Image...';

    varImg=new Image();
	varImg.onload=onImgLoad;
	varImg.src=imgSrc;

    function onImgLoad()
    {
        var imgW=0;
        var frameW=0;
        frameW=getClientWidth()-100;
        
        if (this.width>frameW-10)
        {
            imgW=frameW-20;
        }
        else
        {
            imgW=this.width;
            frameW=imgW+20;
        }    
        createPopupFrame(frameW, null, null, 20);
       
        objDivO.innerHTML="<div id=\"popuptitle\"><div class=\"title\"></div><div class=\"close\"><A id='hlkClPop2' href=\"javascript:hidePopup2(null);\"></A></div></div>";
        objDivO.innerHTML+="<div id=\"popupcontent\" align='center'><img width='"+imgW+"' src=\""+imgSrc+"\" /></div>";
    }
}

function selectBusTab(tabName)
{
    if (document.getElementById("hlkB"+tabName)!=null)
    {
        //document.getElementById("divB"+tabName).className="TabSel";
        if(tabName=="Profile" || tabName=="Messages" || tabName=="Members")
            document.getElementById("hlkB"+tabName).className="sel";
        else
            document.getElementById("hlkBAps").className="sel";    
    }
}

function selectSchoolTab(tabName)
{
    if (document.getElementById("divS"+tabName)!=null)
    {
        document.getElementById("divS"+tabName).className="TabSel";
    }
}
function showPage(pageName,title,winW,winH, left, top)
{
    createPopupBG();
    objDivO=createPopupFrame(winW+20, winH, left, top);
    objDivO.innerHTML="<div id=\"popuptitle\"><div class=\"title\">"+title+"</div><div class=\"close\"><A href=\"javascript:closePage();\"></A></div></div>";
    objDivO.innerHTML=objDivO.innerHTML+"<div id=\"popupcontent\"><iframe height=\""+winH+"\" id=\"popupframe\" frameborder=\"0\" src=\""+pageName+"\" scrolling=\"no\" ></iframe></div>";
}
function closePage()
{
    if (document.getElementById('divOverlayBG')){ document.getElementById('divOverlayBG').parentNode.removeChild(document.getElementById('divOverlayBG'));}
    if (document.getElementById('divOverlay')){ document.getElementById("divOverlay").parentNode.removeChild(parent.document.getElementById("divOverlay")); }
}
function showPage2(pageName,title,winW,winH, left, top)
{
    objDivO=createPopupFrame(winW, winH, left, top);
    objDivO.innerHTML=objDivO.innerHTML+"<div style='padding: 0px' id=\"popupcontent\"><iframe height=\""+winH+"\" id=\"popupframe\" frameborder=\"0\" src="+pageName+"></iframe></div>";
}

function ajaxCall(url,callback)
{
    xmlHttp = getXMLHTTP_();
    if (xmlHttp)
    {
	    if (document.getElementById("ajaxMsg"))
	    {
	        document.getElementById("ajaxMsg").innerHTML="Fetching Data...;"
	        document.getElementById("ajaxMsg").className="visible";
	    }
	    requestUrl=url+"&rnd="+Math.random();
	    xmlHttp.onreadystatechange = ajaxCallBack;
	    xmlHttp.open("GET", requestUrl, true);
	    xmlHttp.send(null);
    }
    
    function ajaxCallBack()
    {
	    if (xmlHttp.readyState == 4)
	    {
			if (document.getElementById("ajaxMsg"))
			    document.getElementById("ajaxMsg").className="hidden";
		    if (xmlHttp.status == 200)
		    {
			    callback(xmlHttp.responseText);
		    }
		    else
		    {
			    alert("There was a problem in retrieving the data:\n" + xmlHttp.statusText);
		    }
	    }
    	
    }
    			
}

function getUnitInfo(unitId)
{
    
    xmlHttp = getXMLHTTP_();
    if (xmlHttp)
    {
	    document.getElementById("ajaxMsg").innerHTML="Loading Business Info;"
	    document.getElementById("ajaxMsg").className="visible";
	    requestUrl="/lookup.aspx?id=unit&val="+unitId+"&rnd="+Math.random();
	    xmlHttp.onreadystatechange = getUnitCallback;
	    xmlHttp.open("GET", requestUrl, true);
	    xmlHttp.send(null);
    }			
    
}

function getUnitCallback()
{
	if (xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200)
		{
			document.getElementById("ajaxMsg").className="hidden";
			eval("var d=" + xmlHttp.responseText +" ;");
			if (d==null)
			{
			    alert("Error fetching data");
			}
			else
			{
			    if (document.getElementById("txtName")!=null)
			        document.getElementById("txtName").value=d.Name;
			    document.getElementById("cmbUnitType").value=d.UnitType;
			    document.getElementById("txtArea").value=d.AreaName;
			    document.getElementById("txtStreet").value=d.StreetName;
			    document.getElementById("hidArea").value=d.Area;
			    document.getElementById("hidStreet").value=d.Street;
			    if (document.getElementById("txtUnitNo")!=null)
			        document.getElementById("txtUnitNo").value=d.UnitNo;
			    if (document.getElementById("txtAddress")!=null)
			        document.getElementById("txtAddress").value=d.Address;
			    if (document.getElementById("txtPhone1")!=null)
			        document.getElementById("txtPhone1").value=d.Phone1;
			    if (document.getElementById("txtPhone2")!=null)
			        document.getElementById("txtPhone2").value=d.Phone2;
			    if (document.getElementById("txtFax")!=null)
			        document.getElementById("txtFax").value=d.Fax;
			    if (document.getElementById("txtEmail")!=null)
			        document.getElementById("txtEmail").value=d.Email;
			    if (document.getElementById("txtWeb")!=null)
			        document.getElementById("txtWeb").value=d.Web;
			}
		}
		else
		{
			alert("There was a problem in retrieving the data:\n" + xmlHttp.statusText);
		}
	}
	
}

function getCompInfo(compId)
{
    xmlHttp = getXMLHTTP_();
    if (xmlHttp)
    {
	    document.getElementById("ajaxMsg").innerHTML="Loading Company Info;"
	    document.getElementById("ajaxMsg").className="visible";
	    requestUrl="/lookup.aspx?id=comp&val="+compId+"&rnd="+Math.random();
	    xmlHttp.onreadystatechange = getCompCallback;
	    xmlHttp.open("GET", requestUrl, true);
	    xmlHttp.send(null);
    }			
    
}

function getCompCallback()
{
	if (xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200)
		{
			document.getElementById("ajaxMsg").className="hidden";
			eval("var d=" + xmlHttp.responseText +" ;");
			if (d==null)
			{
			    alert("Error fetching data");
			}
			else
			{
			    document.getElementById("txtCompany").value=d.FullName;
			    document.getElementById("txtCompanyShortName").value=d.Name;
			    document.getElementById("cmbCompanyCategory").value=d.Category;
			    document.getElementById("cmbCompanyType").value=d.Type;
			    document.getElementById("cmbCompanyOrigin").value=d.Country;
			}
		}
		else
		{
			alert("There was a problem in retrieving the data:\n" + xmlHttp.statusText);
		}
	}
	
}

function updateChildList(sender,childId,lookupName)
{
	if(sender==null)
		return;
    var senderVal;
	senderVal=sender.value;
	
	xmlHttp = getXMLHTTP_();
	if (xmlHttp)
	{
		childList=childId;
		requestUrl="/Lookup.aspx?id="+lookupName+"&val="+senderVal+"&rnd="+Math.random();
		//alert(requestUrl);
		//disableFields();
		document.getElementById(childId).enabled=false;
		xmlHttp.onreadystatechange = doUpdateChildList;
		xmlHttp.open("GET", requestUrl, true);
		xmlHttp.send(null);
	}			

    function doUpdateChildList()
    {
	    if (xmlHttp.readyState == 4)
	    {
		    if (xmlHttp.status == 200)
		    {
			    eval("var d=" + xmlHttp.responseText);
			    if (d != null)
			    {
				    populateList_(childId,d);
			    }
		    }
		    else
		    {
			    alert("There was a problem in retrieving the data:\n" + xmlHttp.statusText);
		    }
		    document.getElementById(childId).enabled=true;
	    }
    }

}

function changeCity(selected, vals)
{
    if (selected==true)
    {
        var prfx;
        loc=window.location.toString();
        //window.location=loc.replace(/city=.+\&cityname=([^&])+\&{0,1}/,"city="+vals.value+"&cityname="+vals.name+"&");
        //window.location=loc.replace(/city\/.+\/([^&])+\/{0,1}\//,"/city/"+vals.value+"/"+vals.name+"/");
        prfx=loc.substring(0,loc.indexOf("/city"));
        tmp=loc.substring(loc.indexOf("/city")+6);
        tmp=tmp.substring(tmp.indexOf("/")+1);
        if(tmp.indexOf("/")>0)
            tmp="/"+tmp.substring(tmp.indexOf("/")+1);
        else
            tmp="";
        window.location=prfx+"/city/"+vals.value+"/"+vals.name.replace(" ","_")+tmp;
        return;
    }
    else
    {
        alert("City not found");
    }
        
}

function changeCityCancel()
{
    document.getElementById("txtChangeCity").value="";
    objChCity.actb_close();
    hideLayer('cityCh');
    
}

function loginMember(u,p)
{
    if (u=="" || p=="")
    {
        alert("Please provide Email and Password");
        return;
    }
    xmlHttp = getXMLHTTP_();
    if (xmlHttp)
    {
	    document.getElementById("imgloginajx").style.visibility="visible";
	    requestUrl="LoginAJ.aspx?u="+u+"&p="+p+"&rnd="+Math.random();
	    xmlHttp.onreadystatechange = loginCallback;
	    xmlHttp.open("GET", requestUrl, true);
	    xmlHttp.send(null);
    }
    
    function loginCallback()
    {
        
        if (xmlHttp.readyState == 4)
	    {
		    if (xmlHttp.status == 200)
		    {
			    document.getElementById("imgloginajx").style.visibility="hidden";
			    eval("var d=" + xmlHttp.responseText+";");
			    if (d==null)
			    {
		            alert("Error logging in...");	        
			    }
			    else
			    {
			        if (d=="success")
			        {
			            window.location=window.location;
			        }
			        else if (d=="failure")
			        {
			            alert("Invalid Username or Password");
			        }
			        else if (d=="notactivated")
			        {
			            alert("Your registration has not been activated. Please check your email address and click the registeration link.");
			        }
			    }
		    }
		    else
		    {
			    alert("There was a problem in retrieving the data:\n" + xmlHttp.statusText);
		    }
	    }
    }
}
function getDoc(docId,ItemId,docroot)
{
    ajaxCall("/lookup.aspx?id=doc&val="+docId+"&It="+ItemId,onGetDoc);
    function onGetDoc(res)
    {
        eval("var docData="+res+";");
        if(docData==null)
        {}
        else
        {
            window.location= docroot+docId+"/"+docData.key+"/"+docData.FileName;
        }
    }
}
function dropdownMenu(menu,submenu)
{
    var menuName=menu;
    var objMenu=document.getElementById(menu);
    var objSubMenu=document.getElementById(submenu);
    var prevClassName="";
    addObjEvent(objMenu,"mouseover",showDropList);
    addObjEvent(objSubMenu,"mouseover",showDropList);
    addObjEvent(objMenu,"mouseout",hideList);
    addObjEvent(objSubMenu,"mouseout",hideList);
    function showDropList()
    {
        if(objMenu.style.display=="none" || objMenu.style.display=="" )
        {
            var pos;
            pos=findPos(objMenu);
            prevClassName=objMenu.className;
            objMenu.className="activemenu";
            showLayer(submenu,"absolute",pos[0],pos[1]+objMenu.offsetHeight-1);
        }
    }
    function hideList()
    {
        objSubMenu.style.display="none";
        objMenu.className=prevClassName;
    }
}
