﻿// JScript File


var images = new Array();
var imgCtr = 0;
var cycleCtr = 0;
var fadeCtr = 100;
var intervalPtr = '';
var activeId = 1;
var timerId = '';
var initInterval = '';
var cycleTime = 7000;

function setBrandExpImg(imageFile)
{    
    var obj = document.getElementById('globalImgBrandExp');
    var obj2 = document.getElementById('globalImgBrandExpAlt');    
    var flag = document.getElementById('rotateBrandExp');
    
    if(imageFile.length != 0)
    {    
        if(obj != null)
        {   
            
            try{         
                clearInterval(intervalPtr);
                clearInterval(initInterval);
                               
                obj.src = imageFile;
                obj.style.opacity = '';
                obj.style.filter = '';
                obj.style.display = '';
                obj2.style.display = 'none';
                
                for (var x = 0; x < images.length; x++) {

                    if (images[x] == imageFile) {
                        cycleCtr = x + 1;

                        if (cycleCtr > images.length - 1)
                            cycleCtr = 0;

                        if (cycleCtr > 0)
                            obj2.src = images[cycleCtr - 1];
                        else
                            obj2.src = images[images.length - 1];
                                                                          
                        break;
                    }
                }                                           
                
                if(flag != null)
                {
                    flag.value = '1';
                };
            }catch(e){}
                
        }
    }
}

function setOpacity(obj1, obj2, value1) {
	obj1.style.opacity = value1/10;
	obj1.style.filter = 'alpha(opacity=' + value1*10 + ')';
	
}



function rotateBrandExpression(image1, image2, image3, image4, image5)
{
    document.getElementById('globalImgBrandExpAlt').style.display='none';        
    document.getElementById('globalImgBrandExpAlt').src = '';
    document.getElementById('globalImgBrandExpAlt').style.opacity = "0.0";
    document.getElementById('globalImgBrandExpAlt').style.filter = "alpha(opacity=\'0\')";

   //Count number of valid images
         
   if(image1.length != 0)
   {
    images[imgCtr] = image1;
    imgCtr++;
   }
    
   if(image2.length != 0)
   {
    images[imgCtr] = image2;
    imgCtr++;
   }


   if(image3.length != 0)
   {
    images[imgCtr] = image3;
    imgCtr++;
   }


   if(image4.length != 0)
   {
    images[imgCtr] = image4;
    imgCtr++;
   }


   if(image5.length != 0)
   {
    images[imgCtr] = image5;
    imgCtr++;
   }
   
   //cycleImages();
   
   if(imgCtr > 1)   
   {
    cycleCtr++;
    initInterval = setInterval('cycleImages()',cycleTime); //Wait for 5 seconds before starting first cycle
   }
}

function restartInterval() {
    clearInterval(intervalPtr);
    clearInterval(initInterval);    
    document.getElementById('rotateBrandExp').value = '0';
    initInterval = setInterval('cycleImages()', cycleTime);    
}

function cycleImages() {   
  var flag = document.getElementById('rotateBrandExp');
  
  if (initInterval != '')
    {
        fadeCtr = 100;
        clearInterval(initInterval);        
    }
  
  
  if (cycleCtr == imgCtr) {
    cycleCtr = 0;
  }
  
  if(flag.value != "1") {
    var obj1 = document.getElementById('globalImgBrandExp');
    var obj2 = document.getElementById('globalImgBrandExpAlt');
       
    
    imgSrc = images[cycleCtr];                                         
        
    if(obj2.style.display == 'none') //Display the alternate image                    
    {                                
        obj2.style.opacity= "0.0;";
        obj2.style.filter = "alpha(opacity=0)";       
        obj2.style.display = '';                    
        intervalPtr = setInterval('fadeOut(\'' + obj1.id + '\',\'' + obj2.id + '\',\'' + imgSrc + '\',\'true\',5);',50);                       
    }
    else
    {     
        obj1.style.opacity= "0.0";
        obj1.style.filter = "alpha(opacity=0)";
        obj1.style.display = '';                                             
        intervalPtr = setInterval('fadeOut(\'' + obj2.id + '\',\'' + obj1.id + '\',\'' + imgSrc + '\',\'true\',5);',50);     
        
    }
    
    cycleCtr++;
  }
  

}

function fadeOut(id1, id2, imgSrc, cycle, fadeRate)
{
    //id1 is the object to fade, id2 is the object to put in foreground
    var obj1 = document.getElementById(id1);
    var obj2 = document.getElementById(id2);

    if(imgSrc != obj2.src){
        if (obj1 != null && obj2 != null) {
            var opa = fadeCtr / 100;
            if (opa <= 0) {
                if (activeId == 1)
                    activeId = 0;
                else
                    activeId = 1;

                fadeCtr = 100;
                clearInterval(intervalPtr);
                obj1.style.opacity = "0.0";
                obj1.style.filter = "alpha(opacity=0)";
                obj1.style.display = 'none';

                obj2.style.opacity = "1.0";
                obj2.style.filter = "alpha(opacity=100)";
                obj2.style.display = '';

                if (cycle == 'true') {
                    initInterval = setInterval('cycleImages()', cycleTime); //Wait for a period of 'cycleTime' before setting next cycle
                }
            }
            else {
                obj1.style.opacity = opa.toString();
                obj1.style.filter = 'alpha(opacity=' + fadeCtr + ')';

                obj2.style.opacity = ((100 - fadeCtr) / 100).toString();
                obj2.style.filter = "alpha(opacity=" + (100 - fadeCtr) + ")";

                if (obj2.src != imgSrc)
                    obj2.src = imgSrc;

                fadeCtr -= fadeRate;

            }
        }
    }
   

}






String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function ShowItemDetail(title, id, newslist, language, workarea)
{        
    var url = "/NewsDetail.aspx?nid=" + id + "&nwslst=" + newslist + "&lang=" + language + "&title=" + title + "&area=" + workarea;      
    window.open(url,'','toolbar=no,location=no, scrollbars=yes');    
}

function ShowCareerDetail(title, id, newslist, language, workarea)
{        
    var url = "/CareerDetail.aspx?nid=" + id + "&nwslst=" + newslist + "&lang=" + language + "&title=" + title + "&area=" + workarea;;      
    window.open(url,'','toolbar=no,location=no, scrollbars=no');
    return false;
}


function ShowAllItems(title, list, language, workArea)
{        
    var url = "/AllItems.aspx?lf=" + list + "&lang=" + language + "&title=" + title + "&area=" + workArea;      
    window.open(url,'','toolbar=no,location=no, scrollbars=yes');
    return false;        
}

//Protect email from crawlers...
function dM(email2, email1) {
    document.write(unescape("<a class='urlLinkStd' href=mailto:" + email1 + "@" + email2 + ">" + email1 + "@" + email2 + "</a>"));

}

function doSearchClick(btn, keycode) {

    if (keycode == 13) {
        document.getElementById(btn).click();
    }
    
    //btn.click();
}