var sShlyId =-1;            
var sSelCatOrLoc='C'  

function ad_offsetLeft(obj) {
    try
    {
        curtop = 0;
        if (obj.offsetParent) {
        curtop = obj.offsetLeft;
            while (obj = obj.offsetParent) {
              curtop += obj.offsetLeft;
            }
        }
    }
    catch(e){};
    return curtop;
}

function ad_offsetTop(obj) {
    try
    {
        curtop = 0;
        if (obj.offsetParent) {
            curtop = obj.offsetTop
            while (obj = obj.offsetParent) {
              curtop += obj.offsetTop
            }
        }
    }
    catch(e){};
    return curtop;
}    

function fnSetCatOrLoc(sCatorLoc)
{ 
    if (sSelCatOrLoc != sCatorLoc)
    sSelCatOrLoc = sCatorLoc;
}

function fnshowcats(){
    document.getElementById("hat_cat_menu").style.display="none";
    document.getElementById("hat_loc_menu").style.display="none";
    
    if(sSelCatOrLoc=='C'){
        document.getElementById("hat_cat_menu").style.display="block";        
    }
    else{
        document.getElementById("hat_loc_menu").style.display="block";
    }
}


//modified by praks on jan 25th 2012
function fnShowCatOrLoc(){
    document.getElementById("divGeoLoc").style.display="none";
    document.getElementById("divCatList").style.display="none";    
    fncloselayer();
    
//    alert(sSelCatOrLoc);
    document.getElementById("hat_loc_menu").style.display="block";        
    if(sSelCatOrLoc=='C')
    {        
        document.getElementById("divCatList").style.display="block";        
    }
    else
    {
        document.getElementById("divGeoLoc").style.display="block";
    }
}

//modified by praks on jan 25th 2012
function fnhidecats(){

    try{
    document.getElementById("hat_loc_menu").style.display="none";
    document.getElementById("hat_cat_menu").style.display="none";
    }
    catch(err){}
    
    try{
    document.getElementById("divGeoLoc").style.display="none";
    document.getElementById("divCatList").style.display="none";
    }
    catch(err){}
}
function fnmoremenu(){
    var moretab = document.getElementById("hat_tab5");
    moretab.className = "hat_tab hat_more_sel";
    document.getElementById("hat_more_menu").style.display="block";
}
function fnmoremenuhide(){
    var moretab = document.getElementById("hat_tab5");
    moretab.className = "hat_tab";
    document.getElementById("hat_more_menu").style.display="none";
}

function fnshowlayer(currobj,sCurrShlyId, sadid, sadtype, sact)
{

    //modified by praks on jan 25th 2012
    fnhidecats();
    
    currobj=document.getElementById('dvSendEmail' + sCurrShlyId);    
    var snwid= document.getElementById('_nwid').value;
    var slocation=window.location.href;
    slocation=slocation.toUpperCase();
    var adjustlayertoppos =270;
    var adjustlayerleftpos=0;
    if(slocation.indexOf('WSJPROFILE.ASPX')!=-1){
        adjustlayertoppos+=380;
        adjustlayerleftpos=43;
    }
    
    try
    {
        if (sCurrShlyId>=0){

            var container = document.getElementById('dvwsjsharefra'+sCurrShlyId);
            var iframe = document.createElement('iframe');
            iframe.src='wsjshare.aspx?adid='+sadid+'&act='+sact+'&nwid='+snwid + "&adtp="+sadtype
            
            fncloselayer();
            sShlyId=sCurrShlyId;

            var close_img = document.createElement('img');
            close_img.src = 'images/close1.gif';
            close_img.style.position = 'absolute';
            close_img.style.top = '26px';
            close_img.style.right = '27px';                    
            close_img.style.border = '0';
            close_img.style.cursor = 'pointer';
            close_img.style.zIndex = '100001';
            close_img.onclick = function() {
                    fncloselayer();
                }
            
            document.getElementById("dvwsjsharefra"+sShlyId).style.display="block";                        
            document.getElementById('dvwsjshare'+sCurrShlyId).style.display="block";                                                
            document.getElementById('dvwsjshare'+sCurrShlyId).style.left=(adjustlayerleftpos+80)+'px';
            document.getElementById('dvwsjshare'+sCurrShlyId).style.top=ad_offsetTop(currobj)-600+adjustlayertoppos +ynshareposplus  + 'px';                    
            
            iframe.id = 'frawsjShare';
            iframe.style.border = '0';
            iframe.frameBorder = 0;
            iframe.allowTransparency = true;
            iframe.style.width = '100%';
            iframe.style.height = '100%';
            iframe.style.overflow = 'hidden';
            iframe.scrolling = 'no';
            iframe.style.visibility = 'visible';
            iframe.style.borderColor="#f5f5f5";
                                
            try{
                  setTimeout(function() {
                  container.appendChild(close_img);
                  container.appendChild(iframe);
                }, 100);
            }
            catch(e){
                container.appendChild(close_img);  
                container.appendChild(iframe);  
            }
            document.getElementById('dvwsjsharearrow'+sCurrShlyId).style.display="block";                    
        }
    }
    catch(err){};
}

function fncloselayer(){
    try{
        if (sShlyId!=-1){
            try{
                document.getElementById('dvwsjsharearrow'+sShlyId).style.display="none";
            }
            catch(e){}
            el = document.getElementById('frawsjShare');
            if (el) {
                el.parentNode.removeChild(el);
            } 
            document.getElementById('dvwsjshare'+sShlyId).style.display='none';
            sShlyId=-1;
        }
    }
    catch(err){};
}    
 

function fngcads(scid,spgct, scatdesc)
{
    try
    {
        document.getElementById("_pgct").value = spgct;
        if (scid!=0)
        {
           document.getElementById("_sacat").value = scid;    
            document.getElementById("txtSearchCat").value = scatdesc;
        }    
        document.forms(0).submit();
    }
    catch(e)
    {
       window.location.href = 'wsjlisting.aspx?cid='+ scid
    }
}   

function fngeoads(currobj, sgeocode,srlevel)
{
   var sprevlevelname =document.getElementById("gc"+sgeocode).innerHTML;
   document.getElementById("_hgeoloc").value = sgeocode;
   document.getElementById("_hmygeoloc").value = sgeocode+'@'+sprevlevelname;
   document.getElementById("txtSearchWhere").value = sprevlevelname;
   document.getElementById('_hfact').value='submit';
   document.forms(0).submit();
}   

//modified by praks on jan 25th 2012
function fnSearchAdsForLoc()
{
   document.getElementById("_hgeoloc").value = '';
   document.getElementById("_hmygeoloc").value = '';
   document.getElementById("txtSearchWhere").value = document.getElementById("txtSearchLocation").value;
   document.getElementById('_hfact').value='submit';
   //document.frmwsjlisting.submit();
   document.forms(0).submit();
}

//modified by praks on jan 25th 2012
function fnAdsForLoc(currobj, sgeocode, sgeoname)
{
   document.getElementById("_hgeoloc").value = sgeocode;
   document.getElementById("_hmygeoloc").value = sgeocode+'@'+sgeoname;
   document.getElementById("txtSearchWhere").value = sgeoname;
   document.getElementById('_hfact').value='submit';
   //modified by praks on jan 12th 2012
   //document.frmwsjlisting.submit();
   document.forms(0).submit();
}   

//modified by praks on jan 25th 2012
function fnSearchAdsForText()
{
   document.getElementById("_sacat").value = '';    
   document.getElementById("txtSearchCat").value = document.getElementById("txtSearchWhat").value;
   document.getElementById('_hfact').value='submit';
   //document.frmwsjlisting.submit();
   document.forms(0).submit();    
}

//modified by praks on jan 25th 2012
function fnAdsForCat(scid, scatdesc, spgct )
{
   try
    {
        document.getElementById("_pgct").value = spgct;
    //    alert(scid);
        if (scid!=0)
        {
            document.getElementById("_sacat").value = scid;    
            document.getElementById("txtSearchCat").value = scatdesc;
        }    
        document.forms(0).submit(); //modifed by praks on jan 25 2012
    }
    catch(e)
    {
       window.location.href = 'wsjlisting.aspx?cid='+ scid
    }
}

function fnSearch()
{
    document.getElementById('_sacat').value='';
    document.getElementById('_hgeoloc').value='';
    document.getElementById('_hfact').value='submit';
    document.forms(0).submit();
}   
        
function keypress_number(decimal) 
{

    var keypressed = window.event.keyCode;
    var ElementText  = window.event.srcElement.value ;
    if (keypressed == 45)
    {
        window.event.keyCode = 0;
    }
    else 
    {
        if (decimal) 
        {
            var Reg = /\./g;
			
            if (Reg.test(ElementText)) 
            {
	            if( (keypressed >= 48 && keypressed <= 57) == false) 
	            {
		            window.event.keyCode = 0;
	            }
            }
            else 
            {
	            if ((keypressed >= 48 && keypressed <= 57 || keypressed == 46) == false) 
	            {
		            window.event.keyCode = 0;
	            }
            }
        }

        else 
        {
            if ((keypressed >= 48 && keypressed <= 57) == false) 
            {
	            window.event.keyCode = 0;
            }
        }
    }
}        

function fntransdisplay()
{
//    try{
    //document.getElementById("AreaNavigation").style.display="block";    
    document.getElementById("trans_div").style.display="none";
    
//    }catch(err){};

    try{
    document.getElementById("divsplashlay").style.display="none";
    document.getElementById("wsjmaindiv").style.display="block"
    }catch(err){};
}
