function loadFlash(path, ele, w, h){
	var flashvars = {};
	var params = {};
	params.play = "true";
	params.loop = "true";
	params.menu = "true";
	params.quality = "high";
	params.scale = "showall";
	params.salign = "tl";
	params.wmode = "transparent";
//	params.allowScriptAccess = "sameDomain";
	var attributes = {};
	attributes.id = ele;
	attributes.name = ele;
	attributes.styleclass = ele;
	attributes.align = "middle";
	swfobject.embedSWF(path, ele, w, h, "8.0.0", false, flashvars, params, attributes);
}

function openURL(val){
	if (val!='')
		window.open(val,'NewWin');
}



function openattachment(Page)
{
        if (Page.indexOf('preview=1') == -1) 
        {
            Page = Page.replace('preview=','new=1');
        }
        
        if (Page.indexOf('http://') >=0)
        {
            Page = Page.replace("&preview=1","");
            Page = Page.replace("&preview=","");
            Page = Page.replace("&new=1","");
        }
		if (Page.indexOf('Tw_Sch_theme_plan_detail.aspx') >=0)
		{
			window.location.href = Page;
		}
        else if (Page.indexOf('attach.aspx') >= 0) {
            window.open(Page , '', 'resizable=yes, status=yes, scrollbars=yes, toolbar=no, menubar=no, width=640, height=480, left=0, top=0');
        }
        else {
            window.open(Page , '', 'resizable=yes, status=yes, scrollbars=yes, toolbar=no, menubar=no, width=768, height=768, left=0, top=0');
        }
}

//-------------------------------------------------------------------------
// Date: 2009-04-20
// Check which page is necessary to show disclaimer / https.
//-------------------------------------------------------------------------
var disclaimerLink = 'Tw_Sch_disclaimer.html';

// Redirect the following page(s) to show disclaimer.
var showDisclaimer = [
];

// Redirect the following page(s) for HTTPS.

var useHTTPS = [
    'Tw_Sch_Channel_Member_Login.aspx',
    'Tw_Sch_channel_sub.aspx',
    'Tw_Sch_Channel_Member_Landing.aspx',
    'Tw_Sch_channel_sub.aspx',
    'Tw_Sch_channel_sub_update.aspx',
    'Tw_Sch_channel_sub_update_Pop.aspx',
    'Tw_Sch_contact_us.aspx',
    'Tw_Sch_eDM_subscription.aspx',
    'Tw_Sch_event_registration.aspx',
    'Tw_Sch_event_registration_success.aspx',
    'Tw_Sch_insurancebooking.aspx',
    'Tw_Sch_ChangePassword.aspx'

];
var HTTP_Port = 80;//default 80
var HTTPS_Port = 443;

function findCurrentPageName(url)
{
    var s = url.toLowerCase();
    if (s.indexOf('?') >= 0)
    {
        s = s.substring(0, s.indexOf('?'));
    }
    s = s.substring(s.lastIndexOf('/')+1);
    return s;
}

function findCurrentSiteName(url)
{
    var s = url.toLowerCase();
    var c = '/' + findCurrentPageName(s);
    for (var i=0; i<showDisclaimer.length; i++)
    {
        if (c.indexOf(showDisclaimer[i].toLowerCase()) >= 0)
        {
            return 'disclaimer';
        }
    }
    var matched = 0;
    for (var i=0; i<useHTTPS.length; i++)
    {
        if (c.indexOf(useHTTPS[i].toLowerCase()) >= 0)
        {
            if (s.indexOf('http://') == 0 )
            {
                return 'https';
            }
            matched++;
        }
    }
    // No matched. Make sure that HTTPS must be redirected to HTTP.
    if (matched == 0 && s.indexOf('https://') == 0)
    {
        return 'http';
    }
    return null;
}

function createCookie(name, value) {
	document.cookie = name + "=" + value + "; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function queryString(name) {
    qs = window.location.search.substring(1);
    qs = qs.split('&');
    for (var i=0; i<qs.length; i++) {
        p = qs[i].split('=');
        if (p[0] == name)
            return p[1];
    }
}

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 acceptDisclaimer()
{
    var site = findCurrentSiteName(Url.decode(queryString('referrer')));
    if (!site) return false;
	createCookie('accept_'+site, 'Y');
	window.location.href = Url.decode(queryString('referrer'));
}

function checkDisclaimer()
{
    var current = findCurrentPageName(window.location.href);
    var site = findCurrentSiteName(window.location.href);
    if (!site)
    {
        return;
    }
    var myHostname = window.location.host;
    var myLocation = window.location.href;
    if (myHostname.indexOf('.com') > 0){ HTTP_Port = 80; }
    if (site == 'disclaimer')
    {
        if (window.location.href.indexOf('https://') == 0)
        {
            // Force redirect to HTTP for all disclaimer pages.
            if (HTTPS_Port == 443)
            {
                if (HTTP_Port == 80) {
                    myLocation = 'http://' + myLocation.substring(8);
                } else {
                    myLocation = 'http://' + myLocation.substring(8).replace(myHostname + '/', myHostname + ':' + HTTP_Port + '/');
                }
            }
            else
            {
                myLocation = 'http://' + myLocation.substring(8).replace(':' + HTTPS_Port + '/',':' + HTTP_Port + '/');
            }
        }
        if (readCookie('accept_'+site) == null || readCookie('accept_'+site) != 'Y' )
        {
            window.location.href = disclaimerLink + '?referrer=' + Url.encode(myLocation);
            return;
        }
        else if (window.location.href.indexOf('https://') == 0)
        {
            window.location.replace( myLocation );
            return;
        }
    }
    if (site == 'https')
    {
        if (HTTP_Port == 80)
        {
            myLocation = 'https://' + myLocation.substring(7);
        }
        else
        {
            myLocation = 'https://' + myLocation.substring(7).replace(':' + HTTP_Port + '/',':' + HTTPS_Port + '/');
        }
        window.location.replace( myLocation );
        return;
    }
    else if (site == 'http')
    {
        if (HTTPS_Port == 443)
        {
            if (HTTP_Port == 80) {
                myLocation = 'http://' + myLocation.substring(8);
            } else {
                myLocation = 'http://' + myLocation.substring(8).replace(myHostname + '/', myHostname + ':' + HTTP_Port + '/');
            }
        }
        else
        {
            myLocation = 'http://' + myLocation.substring(8).replace(':' + HTTPS_Port + '/',':' + HTTP_Port + '/');
        }
        window.location.replace( myLocation );
        return;
    }
    return;
}

//added by allen for not show disclaim in preview
if (window.location.href.indexOf("prepublish") == -1)
	checkDisclaimer();