//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Common JS Script
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Redirect from iframe to Fullpage
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    if(top.location != self.location)
    {
        top.location.href = self.location;
    }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Retrieve Single Parameter
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Usage: writeIFrame('index2.html', 'successPage=/ausidol/login.html', 'height="300 width="300"');
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function writeIFrame(src, params, iframeoptions) {
  var str=window.location.href;
  if (str.indexOf('?') != -1)
  {
        str = (str.substr(str.indexOf('?'), str.length));
  }
  else 
        str='';
     
  if (params != null && params != '')
  {
     if (str.indexOf('?') != -1)
          str = str + '&' + params;
     else 
          str = '?' + params;
  }
  document.write('<iframe src="' + src + str + '" '+ iframeoptions + '/></iframe>');
  
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Usage: writeIFrameExternal('index2.html', 'successPage=/login.html', 'height="300 width="300"');
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function writeIFrameExternal(src, params, iframeoptions) {
  document.write('<iframe src="' + src + '" '+ iframeoptions + '/></iframe>');
  //alert('writeIFrameExternal called from common.js <iframe src="' + src + '" '+ iframeoptions + '/></iframe>' );
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Write Error Messages
//Usage: write error messages on div error_msg
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function writeError(errorMsg)
{
  document.getElementById('error_msg').innerHTML = errorMsg;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//For Header Animated Logo
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getCookie(c_name)
{
            if (document.cookie.length>0)
              {
              c_start=document.cookie.indexOf(c_name + "=");
              if (c_start!=-1)
                        { 
                        c_start=c_start + c_name.length+1;
                        c_end=document.cookie.indexOf(";",c_start);
                        if (c_end==-1) c_end=document.cookie.length
                                    return unescape(document.cookie.substring(c_start,c_end));
                        } 
              }
            return "";
}

function setCookie(c_name,value,expiredays)
{
            var exdate=new Date();
            exdate.setDate(exdate.getDate()+expiredays);
            document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

var cookieName = 'flashSession';

function isNewSession()
{
            if (getCookie(cookieName) == 'true') {
                        return false;
            }
            else {
                        setCookie(cookieName, 'true', null);
                        return true;
            }
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Update iframe height
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function updateIFrame( height ) {
   var iframe = document.getElementById( 'iclpFrame' );
   iframe.setAttribute( 'height', height );
   setTimeout('window.stop()',20000);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Validate String for URL
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function validateURL(urlString) {
    var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
    return regexp.test(urlString);
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Drop Down/ Overlapping Content- © Dynamic Drive (www.dynamicdrive.com)
// This notice must stay intact for legal use.
// Visit http://www.dynamicdrive.com/ for full source code
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getposOffset(overlay, offsettype){
    var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
    var parentEl=overlay.offsetParent;
    while (parentEl!=null){
        totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
        parentEl=parentEl.offsetParent;
    }
    return totaloffset;
}
function overlay(curobj, subobjstr, opt_position){
if (document.getElementById){
    var subobj=document.getElementById(subobjstr)
    subobj.style.display=(subobj.style.display!="block")? "block" : "none"
    var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0) 
    var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
    subobj.style.left=xpos+"px"
    subobj.style.top=ypos+"px"
    return false
}
else
    return true
}
function overlayclose(subobj){
    document.getElementById(subobj).style.display="none"
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// URL encode / decode
// http://www.webtoolkit.info/
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var Url = {
    // public method for url encoding
    encode : function (string) {
        return escape(this._utf8_encode(string));
    },
    // public method for url decoding
    decode : function (string) {
        return this._utf8_decode(unescape(string));
    },
    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";
        for (var n = 0; n < string.length; n++) {
            var c = string.charCodeAt(n);
            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }
        }
        return utftext;
    },
    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;
        while ( i < utftext.length ) {
            c = utftext.charCodeAt(i);
            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }
        }
        return string;
    }
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Function for lightbox url params
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getURLParam(strParamName){
    var strReturn = "";
    var strHref = window.location.href;
    if ( strHref.indexOf("?") > -1 ){
        var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
        var aQueryString = strQueryString.split("&");
        for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
            if (
                aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
                var aParam = aQueryString[iParam].split("=");
                strReturn = aParam[1];
                break;
            }
        }
    }
    return unescape(strReturn);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//End Common JS Script
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////