var divid;
var flag = 0;


// End of Contect Form Related Javascript //		
/* Cookie function starts */
// JavaScript Document
function writeCookie(name, value, hours, path) {
    var expire = "";
    var pathUrl = "";
    if (hours != null) {
        expire = new Date((new Date()).getTime() + hours * 3600000);
        expire = "; expires=" + expire.toGMTString();
    }
    if (path != null) {
        pathUrl = "; path=" + path;
    } else {
        pathUrl = "; path=/";
    }
    document.cookie = name + "=" + escape(value) + expire + pathUrl;
}

function readCookie(name) {
    var cookieValue = "";
    var search = name + "=";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = document.cookie.indexOf(";", offset);
            if (end == -1) end = document.cookie.length;
            cookieValue = unescape(document.cookie.substring(offset, end));
        }
    }
    return cookieValue;
}

function eraseCookie(name) {
    writeCookie(name, "", -1);
}

/* functionality to set the cookies */
function showFlySel() {
    a = readCookie('tabSelect');
    if (a) {
        showFly(a);
        if (typeof showTab == "function") {
            showTab(a);
        }
    }
}

/* Function to hightlight the tab based on the cookie */
function showFly(val) {
    objLi = document.getElementsByTagName('li');
    objLiLen = objLi.length;
    for (i = 0; i < objLiLen; i++) {
        if ((String(objLi[i].id)).substring(0, 2) == "li") objLi[i].className = "none";
    }
    document.getElementById("li" + val).className = "tabOn";
}

/* Function to resset cookie for country page  starts*/
function resetCookieAndRedirect(p_name, p_value, p_hours, p_url) {
    writeCookie(p_name, p_value, p_hours);
    location.href = p_url;
    return false;
}
/* Function to resset cookie for country page  endss*/
/* Cookies function end */

/* Additional EBP 1.0 functions starts */
function removedrop() {
    document.getElementById('drop1').innerHTML = "<img src='images/aig_pixel.gif' alt='' width='1' height='28' border='0'></a>";
}
function putdrop() {
    document.getElementById('drop1').innerHTML = "<table width='200' border='0' cellspacing='0' cellpadding='0'><tr><td><select name='select' class='fld'><option>Select one</option></select></td><td><input name='Button' type='image' src='images/go_btn.jpg' class='Btn' value='Go'></td></tr></table>";
    document.getElementById('motioncontainer').style.display = 'block';
    document.getElementById('motiongallery').style.display = 'block';
    document.getElementById('trueContainer').style.display = 'block';
}



/********************************************************/
/*********** Script for Home page bottom tab **********/
/********************************************************/

// JavaScript Document
function selTab(currIndex, tabLen, tabPrefix) {
    for (i = 1; i <= tabLen; i++) {
        document.getElementById(tabPrefix + i).className = "inactive";
    }
    document.getElementById(tabPrefix+currIndex).className = "active";
	document.getElementById(tabPrefix+"btm" + currIndex).style.display = "block";
	
	
    for (i = 1; i <= tabLen; i++) {
        document.getElementById(tabPrefix+"btm" + i).className=document.getElementById(tabPrefix+"btm" + i).className.replace("tabDispOn", "tabDispOff");
		
		if(document.getElementById(tabPrefix+"btm" + i).className = "tabDispOff"){
			document.getElementById(tabPrefix+"btm" + i).style.display = "none";
		}		
		
    }
	
	document.getElementById(tabPrefix+"btm" + currIndex).className=document.getElementById(tabPrefix+"btm" + currIndex).className.replace("tabDispOff", "tabDispOn");
	
	if(document.getElementById(tabPrefix+"btm" + currIndex).className = "tabDispOn"){
		document.getElementById(tabPrefix+"btm" + currIndex).style.display = "block";
	}
}


/* ////// End - Script for Home page bottom tab /////// */


/********************************************************/
/*********** Script for Top-top navigation **********/
/********************************************************/

function closeDiv(id,currInd){
	document.getElementById(id).style.display="none";
	document.getElementById(currInd).className = "none"
}

function startList() {
	//START ==> script added to show the top menu when JS is disabled
	var getID = document.getElementById('topMenu_nonjs');	
	getID.removeAttribute('id');	
	var newAttribute = document.createAttribute("id");
	newAttribute.nodeValue = "topMenu";
	getID.setAttributeNode(newAttribute);
	//END ==> script added to show the top menu when JS is disabled
	
  	if (document.all&&document.getElementById) {
  		navRoot = document.getElementById("navList");
  		for (i=0; i<navRoot.childNodes.length; i++) {
  			node = navRoot.childNodes[i];
  			if (node.nodeName=="LI") {
  				node.onmouseover=function() {
  					this.className+=" hover";
  				}
  				node.onmouseout=function() {
  					this.className=this.className.replace(" hover", "");
  				}
  			}
  		}
  	}
  }


/********************************************************/
/*********** START Script for Font Resize **********/
/********************************************************/
var divs=document.getElementsByTagName('body');
function fontSize(obj){
	  for(i=1; i<4; i++)
            {
                document.getElementById('link'+i).href='#';
            }
            divs[0].className = obj.className;
            obj.removeAttribute('href');
}
/********************************************************/
/*********** END Script for Font Resize **********/
/********************************************************/

/*URL Encoding Functionality Starts Here*/
var unreserved = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.~";
var reserved = "!*'();:@&=+$,/?%#[]";
var allowed = unreserved + reserved;
var hexchars = "0123456789ABCDEFabcdef";


function gethex(decimal) {
  return "%" + hexchars.charAt(decimal >> 4) + hexchars.charAt(decimal & 0xF);
  }

function encode(decodedString) {
    if(decodedString == null || decodedString == ''){
        return "";
    }
    var encodeValue  = "";
    var decoded = decodedString;
    var encoded = "";

    for (var i = 0; i < decoded.length; i++ ) {
      var ch = decoded.charAt(i);
      // Check if character is an unreserved character:
      if (unreserved.indexOf(ch) != -1) {
        encoded = encoded + ch;
      } else {

               var charcode = decoded.charCodeAt(i);
        // Position 0 - 127 is equal to percent-encoding with an ASCII character encoding:
        if (charcode < 128) {
          encoded = encoded + gethex(charcode);
        }

        // Position 128 - 2047: two bytes for UTF-8 character encoding.
        if (charcode > 127 && charcode < 2048) {
          // First UTF byte: Mask the first five bits of charcode with binary 110X.XXXX:
          encoded = encoded + gethex((charcode >> 6) | 0xC0);
          // Second UTF byte: Get last six bits of charcode and mask them with binary 10XX.XXXX:
          encoded = encoded + gethex((charcode & 0x3F) | 0x80);
        }

        // Position 2048 - 65535: three bytes for UTF-8 character encoding.
        if (charcode > 2047 && charcode < 65536) {
          // First UTF byte: Mask the first four bits of charcode with binary 1110.XXXX:
          encoded = encoded + gethex((charcode >> 12) | 0xE0);
          // Second UTF byte: Get the next six bits of charcode and mask them binary 10XX.XXXX:
          encoded = encoded + gethex(((charcode >> 6) & 0x3F) | 0x80);
          // Third UTF byte: Get the last six bits of charcode and mask them binary 10XX.XXXX:
          encoded = encoded + gethex((charcode & 0x3F) | 0x80);
        }

        // Position 65536 - : four bytes for UTF-8 character encoding.
        if (charcode > 65535) {
          // First UTF byte: Mask the first three bits of charcode with binary 1111.0XXX:
          encoded = encoded + gethex((charcode >> 18) | 0xF0);
          // Second UTF byte: Get the next six bits of charcode and mask them binary 10XX.XXXX:
          encoded = encoded + gethex(((charcode >> 12) & 0x3F) | 0x80);
          // Third UTF byte: Get the last six bits of charcode and mask them binary 10XX.XXXX:
          encoded = encoded + gethex(((charcode >> 6) & 0x3F) | 0x80);
          // Fourth UTF byte: Get the last six bits of charcode and mask them binary 10XX.XXXX:
          encoded = encoded + gethex((charcode & 0x3F) | 0x80);
        }

      }

    }  // end of for ...

    // Write result:
    return encoded;
}
/*URL Encoding ends here*/
/* Printer friendly functionality starts here*/
    function printPreview(){
        document.hiddenPrintForm.action = document.location.href;
        document.hiddenPrintForm.submit();     
    }
/* Printer friendly functionality ends here*/


/*Building the pdf page url starts here*/
   
function pdfPreview(hbxPdfTitlePrefix, varIsHbxEnabled, pdfServiceUrl, htmlUrl){
        var fileName = getPDFFileName(htmlUrl);
        var actionUrl = pdfServiceUrl + "/" + fileName;
        if( varIsHbxEnabled == 'true'){
            if(hbxPdfTitlePrefix == 'null' || hbxPdfTitlePrefix == ""){
                hbxPdfTitlePrefix = "PDF";   
             }  
            _hbPageView(hbxPdfTitlePrefix +' '+ document.title , "");
        }
        document.hiddenPdfForm.action = actionUrl;
        document.hiddenPdfForm.submit();
}

 
function getPDFFileName(htmlURL) {
       var pdfFileName = "";
       lastSlashIndex = htmlURL.lastIndexOf("/");
       if(lastSlashIndex != -1) {
             htmlFileName = htmlURL.substr(lastSlashIndex+1);
              if(htmlFileName.split(".").length == 2) {
                     pdfFileName = htmlFileName.split(".")[0] + ".pdf";
              }
       }
       return pdfFileName;
 }
