﻿/*********************************************************************
23-Sept-2011    Usha A. Yeli        Modified for MP-23Sept2011-1 2popup opening on click of adds
**********************************************************************/

// JScript File

var __gbl_Div_Id;
var __adClicked=false;
var ObjSel="";
/******************************************Below block to show the link "Click Here to Advertise" in various formats***************************************************************/
var adLinks=new Array();

function pausescroller(content, divId, divClass, delay,strAdEmail)
{
    adLinks[0]='<div style="font-family: Century Gothic;font-size: 18px;font-weight: bold;color: white;text-decoration: none;height:10px;	vertical-align:middle;" title="Click here to Contact MigrantPlanet for Advertisement"><center>Advertise here</center></div>';
    adLinks[1]='<div style="font-family: Century Gothic;font-size: 18px;font-weight: bold;color: white;text-decoration: none;height:10px;	vertical-align:middle;" title="Click here to Contact MigrantPlanet for Advertisement"><center>Your Ad can be here</center></div>';
    adLinks[2]='<div style="font-family: Century Gothic;font-size: 18px;font-weight: bold;color: white;text-decoration: none;height:10px;	vertical-align:middle;" title="Click here to Contact MigrantPlanet for Advertisement"><center>Click here for details</center></div>';
    //adLinks[3]='<a class="ADS_LINK_S" href="'+strAdEmail+'"  title="Click here to Contact MigrantPlanet for Advertisement"><center></center></a>';

     this.content=content; //message array content
     this.tickerid=divId; //ID of ticker div to display information
     this.delay=delay; //Delay between msg change, in miliseconds.
     this.mouseoverBol=0; //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
     this.hiddendivpointer=1; //index of message array for hidden div
     
     document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden;width:190px;height:23px"><div class="innerDiv" style="position: absolute; width: 190px; height:60px;vertical-align:middle" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 190px; height:60px; visibility: hidden;vertical-align:middle" id="'+divId+'2">'+content[1]+'</div></div>');
     var scrollerinstance=this;
     if (window.addEventListener) //run onload in DOM2 browsers
        window.addEventListener("load", function(){scrollerinstance.initialize()}, false);
     else if (window.attachEvent)//run onload in IE5.5+
        window.attachEvent("onload", function(){scrollerinstance.initialize()});
     else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
        setTimeout(function(){scrollerinstance.initialize()}, 500);
}

function funcHref()
{
    
    __adClicked=true;
    var arrObj=document.getElementsByTagName("a");
    var linkObj;
    for(var i=0;i<arrObj.length;i++)
    {
        if(arrObj[i].className=="ADS_LINK_S")
        {
            linkObj=arrObj[i];
            break;
        }
    }
    linkObj.click();

}

// -------------------------------------------------------------------
        // initialize()- Initialize scroller method.
        // -Get div objects, set initial positions, start up down animation
        // --
pausescroller.prototype.initialize=function()
{
        this.tickerdiv=document.getElementById(this.tickerid);
        this.visiblediv=document.getElementById(this.tickerid+"1");
        this.hiddendiv=document.getElementById(this.tickerid+"2");
        this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv));
        
           //set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
        this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px";
        this.getinline(this.visiblediv, this.hiddendiv);
        this.hiddendiv.style.visibility="visible";
        
         var scrollerinstance=this;
        document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1};
        document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0};
        if (window.attachEvent) //Clean up loose references in IE
            window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null});
        setTimeout(function(){scrollerinstance.animateup()}, this.delay);
}
 // -------------------------------------------------------------------
        // animateup()- Move the two inner divs of the scroller up and in sync
        // --
        
pausescroller.prototype.animateup=function()
{
        var scrollerinstance=this;
        if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5))
        {
            this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px";
            this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px";
            setTimeout(function(){scrollerinstance.animateup()}, 50);
        }
        else
        {
             this.getinline(this.hiddendiv, this.visiblediv);
            this.swapdivs();
            setTimeout(function(){scrollerinstance.setmessage()}, this.delay);
        }
}

 // -------------------------------------------------------------------
        // swapdivs()- Swap between which is the visible and which is the hidden div
        // 
        
pausescroller.prototype.swapdivs=function()
{
        var tempcontainer=this.visiblediv;
        this.visiblediv=this.hiddendiv;
        this.hiddendiv=tempcontainer;
}

pausescroller.prototype.getinline=function(div1, div2)
{
        div1.style.top=this.visibledivtop+"px";
        div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px";
}

 // -------------------------------------------------------------------
        // setmessage()- Populate the hidden div with the next message before it's visible
        // -----
pausescroller.prototype.setmessage=function()
{
        var scrollerinstance=this;
        if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
        setTimeout(function(){scrollerinstance.setmessage()}, 100);
        else
        {
            var i=this.hiddendivpointer;
            var ceiling=this.content.length;
            this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1;
            this.hiddendiv.innerHTML=this.content[this.hiddendivpointer];
            this.animateup();
        }
          
}

pausescroller.getCSSpadding=function(tickerobj)
{
        //get CSS padding value, if any
        if (tickerobj.currentStyle)
            return tickerobj.currentStyle["paddingTop"];
        else if (window.getComputedStyle) //if DOM2
            return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top");
        else
            return 0;
}
/*************************************************End Block****************************************************/

function funLoadPage(strPageName,strTargetDiv)
{
    __gbl_Div_Id="";
    __gbl_Div_Id=strTargetDiv;
    //var strCntryId=document.getElementById("hidCntryId").value;    
    var strCntryId="";
    
    // ********************* Retrieve Cookie value ******************************/
    var result = document.cookie.match ( '(^|;) ?' + 'cntry_id' + '=([^;]*)(;|$)' );
    if (result)
    {
        strCntryId= result[2];
    }   
    // ***************************************************************************/
     
    //var strCntryId=document.getElementById("txt_cc").value;
    if(strCntryId=="Please select country")
    {
       strCntryId=""; 
    }
    strPageName=strPageName+"&QgblCntryId="+strCntryId+"&now=";
    fnProgress();
    GetAjaxData(strPageName+Math.floor(Math.random()*1000),funPage);
}

function funPage(strData)
{
    if(document.getElementById("load"))
    {
        var d=document.getElementById("load");
        document.body.removeChild(d); 
        //document.getElementById("load").innerHTML=""; 
    }
    
    var objDiv=document.getElementById(__gbl_Div_Id);
    var id="#"+objDiv.id;
    objDiv.innerHTML=strData;
    objDiv.style.display='none';
    $(id).fadeIn("normal"); 

}

function fnProgress()
{
      
      var obj=document.getElementById(__gbl_Div_Id);  
      //obj.innerHTML="";
      var y=findPosY(obj);
      var x=findPosX(obj);
      //alert("X="+x+"\nY="+y);
      
      var ht=parseInt(obj.offsetHeight);
      var wd=parseInt(obj.offsetWidth);
      //alert(ht+"\n"+wd);
      
       var elem;
       var img = "<img src='/Images/website/loading.gif' height='32px' width='32px' border='0'>";
       var obLoad = document.createElement('div');
       obLoad.setAttribute('id', 'load');
       obLoad.style.display = 'block';
       obLoad.style.position = 'absolute';
       
       var ht_img=32; //The height of the div which will contain the image.
       var wd_img=32; //The width of the div which will contain the image.
   
       //var top = y + (ht/2)-(ht_img/2);
       var top = y + 50 -(ht_img/2);
       var left = x + (wd/2) - (wd_img/2);
       
        
       obLoad.style.top = (top < 0 ? 0 : top) + 'px';
       obLoad.style.left = (left < 0 ? 0 : left) + 'px';
       obLoad.style.width = wd_img + 'px';
       obLoad.style.height = ht_img + 'px';
       obLoad.style.zIndex = 999;
       obLoad.innerHTML=img;
     
       var oParent = document.getElementsByTagName('body')[0];
       oParent.appendChild(obLoad);
       
        /*document.getElementById('divProcessing').style.display='block';
        var img = "&nbsp;&nbsp;<img src='../Images/Pross_crcl.gif' border='0'>";
        document.getElementById('divProcessing').innerHTML = img;*/
}

function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (1) {
            curleft+=obj.offsetLeft;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.x) {
        curleft+=obj.x;
    }
    return curleft;
}

function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (1) {
            curtop+=obj.offsetTop;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.y) {
        curtop+=obj.y;
    }
    return curtop;
}

function openPDF(strId)
{
    //alert(strId);
    var strUrl="/WebPages/downloadForm.aspx?QId="+strId;
    var strWin=window.open(strUrl,'msgwin','toolbar=no,menubar=yes,resizable=Yes,scrollbars=yes,width=680,height=550');
    strWin.focus();
}

function openPopUp(strUrl,strSrc)
{
    if(!(strUrl.startsWith("http://") || strUrl.startsWith("https://")))
    {        
        strUrl="http://"+strUrl;  
    }
    
    var strWin=window.open(strUrl,"contentWin","toolbar=yes,menubar=yes,status=yes,scrollbars=yes,resizable=yes,top=10,left=10,width=650,height=450");
    //,width=800,height=800,
    strWin.focus();
}

function slide(strElemId,objImg)
{
    strElemId="#" + "slide_" +strElemId;
    if ($(strElemId).is(":hidden")) 
    {
        $(strElemId).slideDown("slow");
        objImg.src="/Images/website/title_left_img.png"
    } 
    else 
    {
        $(strElemId).slideUp("slow");
        objImg.src="/Images/website/title_left_img_2.png"
    }
    
}
function showPageProgress()
{
       var elem;
       var img = "<img src='/Images/website/loading.gif' height='48px' width='48px' border='0'>";
       var obLoad = document.createElement('div');
       obLoad.setAttribute('id', 'load');
       obLoad.style.display = 'block';
       obLoad.style.position = 'absolute';
       
       var ht_img=48; //The height of the div which will contain the image.
       var wd_img=48; //The width of the div which will contain the image.
   
       //var top = y + (ht/2)-(ht_img/2);
       //var left = x + (wd/2) - (wd_img/2);
       
       var top = posTop() + ((pageHeight() - ht_img) / 2);
       var left = posLeft() + ((pageWidth() - wd_img) / 2);
       
        
       obLoad.style.top = (top < 0 ? 0 : top) + 'px';
       obLoad.style.left = (left < 0 ? 0 : left) + 'px';
       obLoad.style.width = wd_img + 'px';
       obLoad.style.height = ht_img + 'px';
       obLoad.style.zIndex = 999;
       obLoad.innerHTML=img;
     
       var oParent = document.getElementsByTagName('body')[0];
       oParent.appendChild(obLoad);
}

function removeElement(id)
{
   if(document.getElementById(id))
   { 
     var d=document.getElementById(id);
     document.body.removeChild(d);  
   }
}

function loadBookMarkScript(){

    //var script = document.createElement("script")
    //script.type = "text/javascript";
    //debugger;
/*
    //IE
    if (script.readyState)
    { 
        script.onreadystatechange = function(){
            if (script.readyState == "loaded" || script.readyState == "complete")
            {
                script.onreadystatechange = null;
                callback();
            }
        };
    } else {  //Others
        script.onload = function(){
            callback();
        };
    }
*/
    //script.src = "http://s7.addthis.com/js/250/addthis_widget.js?pub=xa-4a6477304b9be991";
    //document.getElementsByTagName("head")[0].appendChild(script);
}

function openAd(url,id)
 {
    var strUrl="/WebPages/logAds.aspx?QId="+id+"&Qurl="+escape(url);
    var strWin=window.open(strUrl,"AdWin","toolbar=yes,menubar=yes,status=yes,scrollbars=yes,resizable=yes,top=10,left=10,width=800,height=640");
    strWin.focus();
 }


function navigateHRZUrl(url,ind)
{
    //changeHRZClass(document.getElementById(ind));
    document.location.href=url;
} 

function goHome()
 {
    document.location.href="/HomePage.aspx";
 }
 
function changeHRZ(elem,ind)
{
  if(ind=="in")
  {
    //elem.className="TD_HRZ_ACTIVE";
    elem.style.backgroundcolor="Gray";
    elem.style.color="White";
  }
  else
  {
    elem.style.backgroundColor="";
    elem.style.color="black";
  }
  
}

function changeHRZClass(ObjElement)
{	
    ObjSel=ObjElement;
    var arrElem=document.getElementsByTagName("td");
    
    for(var i=0;i<arrElem.length;i++)
    {
        if(arrElem[i].getAttribute('TI')=="HRZ")
        {
            if(arrElem[i]==ObjElement)
            {
                //arrElem[i].style.backgroundColor="Gray";
                //arrElem[i].style.backgroundImage = 'url(images/website/button_rollover_img.png)';
                arrElem[i].style.backgroundImage = 'url(/images/website/active_button_img.png)';
            }
            else
            {
                arrElem[i].style.backgroundImage="";  
            }    
        }       
    }
    
    arrElem=document.getElementsByTagName("a");
    
    for(var i=0;i<arrElem.length;i++)
    {   
        if(arrElem[i].getAttribute('TI')=="HRZ")
        {
            if(arrElem[i].parentNode.parentNode==ObjElement)
            {
                /*arrElem[i].blur();                 // most browsers 
                arrElem[i].hideFocus = true;       // internet explorer
                arrElem[i].style.outline = 'none'; // mozilla*/
                arrElem[i].style.color="White";
            }
            else
            {
                arrElem[i].style.color="Black";  
            }    
        }       
    }
    
    
}

function changeHRZOnMouseMove(objElem)
{
        if(objElem!=ObjSel)
            objElem.style.backgroundImage="url(/images/website/button_rollover_img.png)"; 
        arrElem=document.getElementsByTagName("a");
        for(var i=0;i<arrElem.length;i++)
        {
            if(arrElem[i].getAttribute('TI')=="HRZ")
            {
                if(arrElem[i].parentNode.parentNode==objElem)
                {
                    arrElem[i].style.color="White";
                } 
            }      
        }
}
function resetHRZColor(objElem)
{

        if(objElem!=ObjSel)
        {
            objElem.style.backgroundImage="";
            arrElem=document.getElementsByTagName("a");
            for(var i=0;i<arrElem.length;i++)
            {
                if(arrElem[i].getAttribute('TI')=="HRZ")
                {
                    if(arrElem[i].parentNode.parentNode==objElem)
                    {
                        arrElem[i].style.color="Black";
                    } 
                }       
            }
        }
        
        
}

function swap(elem)
  {
    elem.className="current";
    
    var all=document.getElementsByTagName("li");
    
    for(var i=0;i<all.length;i++)
      {
        if(all[i]==elem)
          continue;
        else if(all[i].getAttribute('TI')==elem.getAttribute('TI'))
           all[i].className="";
      }


    /**********************************************************************************************/
    /* The below code is written so that when tabs are clicked we dont get a dotted border, which is
       is a default behaviour of Anchor elements <a>. So to solve the problem on onclick event we are getting
       all the <a> elements in the page whose TI attribute (custom attribute added of categorizing elements) matches
       the TI attribute of <li> which is clicked, and doing settings to remove the focus from the <a> element 
    **********************************************************************************************/
        
   all=document.getElementsByTagName("a");
   
   for(var i=0;i<all.length;i++)
      {
       if(all[i].getAttribute('TI')==elem.getAttribute('TI'))
       {
           all[i].blur();                 // most browsers 
           all[i].hideFocus = true;       // internet explorer
           all[i].style.outline = 'none'; // mozilla
       }
      }
    
  }
 
