/* The global modal dialog stub */
	var g_Modal = null;
	var g_ModalReady= false;
function IPScript(src) {document.write('<' + 'script src="' + src + '"' +' type="text/javascript"><' + '/script>');}

function stripSpaces (strArray) {    ssresult = new Array();    for (i = 0; i < strArray.length; i++) {        str = strArray[i];        while (str.charAt(str.length - 1) == ' ')            str = str.substring(0, str.length - 2);        while (str.charAt(0) == ' ')            str = str.substring(1, str.length);        ssresult[i] = str;    } return(ssresult);}
function checkBlank(fieldObject, Message)	{if ( fieldObject.value.length  == 0){if (Message != "") alert(Message);fieldObject.focus();return false;}return true;}

IPScript('/scripts/prototype.js');
IPScript('/scripts/aw.js');
//IPScript('/htmlplugins/modaldialog/sardalya.js');

var CurCode = null;
function GetCookie (name)					{var arg = name + "=";var alen = arg.length;var clen = document.cookie.length;var i = 0;while (i < clen) {var j = i + alen;if (document.cookie.substring(i, j) == arg)return getCookieVal (j);i = document.cookie.indexOf(" ", i) + 1;if (i == 0) break;}return null;}var expDays = 365;var exp = new Date();exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function getCookieVal(offset)				{var endstr = document.cookie.indexOf (";", offset);if (endstr == -1)endstr = document.cookie.length;return unescape(document.cookie.substring(offset, endstr));}
function RObj(ea) {var LS='';var QS=new Object();function Err(arg) {if (ea) alert("Request Object Error:\n====================\n"+arg)}function URID(t) {var d="";if (t) {for (var i=0; i<t.length; ++i) {var c=t.charAt(i);d+=(c=="+" ? " ":c);};};return unescape(d);}function OL(o) {var l=0;for (var i in o) {if (typeof(o[i])!="function") l++;};return l;}function AK(key) {var auk=true;for (var u in QS) {if (typeof(QS[u])!="function" && u.toString().toLowerCase()==key.toLowerCase()) {auk=false;return u;}};if (auk) {QS[key]=new Object();QS[key].toString=function() {return TS(QS[key])};QS[key].Count=function() {return OL(QS[key])};QS[key].Count.toString=function() {return OL(QS[key]).toString()};QS[key].Item=function(e) {if (typeof(e)=="undefined") return QS[key];else {if (typeof(e)=="number") {var a=QS[key][Math.ceil(e)];if (typeof(a)=="undefined") Err("ERROR: Index out of range in\nRequest.QueryString(\""+key+"\").Item("+e+")");return a;}else Err("ERROR: Expecting numeric input in\nRequest.QueryString(\""+key+"\").Item(\""+e+"\")");}};QS[key].Item.toString=function(e) {if (typeof(e)=="undefined") return QS[key].toString();else {var a=QS[key][e];if (typeof(a)=="undefined") Err("ERROR: Index out of range in\nRequest.QueryString(\""+key+"\").Item("+e+")");return a.toString();};};QS[key].Key=function(e) {var t=typeof(e);if (t=="string") {var a=QS[key][e];return (typeof(a)!="undefined" && a && a.toString() ? e:"");}else Err("ERROR: Object doesn't support this property or method\nRequest.QueryString.Key("+(e?e:"")+")");};QS[key].Key.toString=function() {return "undefined"};};return key}function AVTK(key, val) {if (key!="") {var key=AK(key);var l=OL(QS[key]);QS[key][l+1]=val;}}function TS(o) {var s="";for (var i in o) {var ty=typeof(o[i]);if (ty=="object") s+=TS(o[i]);else if (ty!="function") s+=o[i]+", ";};var l=s.length;if (l>1) return(s.substring(0,l-2));return (s=="" ? "undefined":s);}function KM(k, o) {var k=k.toLowerCase();for (var u in o) {if (typeof(o[u])!="function" && u.toString().toLowerCase()==k) return u;};}if (window.location && window.location.search) {LS=window.location.search;var l=LS.length;if (l>0) {LS=LS.substring(1,l);var preAmpAt=0;var ampAt=-1;var eqAt=-1;var k=0;var skip=false;for (var i=0; i<l; ++i) {var c=LS.charAt(i);if (LS.charAt(preAmpAt)=="=" || (preAmpAt==0 && i==0 && c=="=")) skip=true;if (c=="=" && eqAt==-1 && !skip) eqAt=i;if (c=="&" && ampAt==-1) {if (eqAt!=-1) ampAt=i;if (skip) preAmpAt=i+1;skip=false;};if (ampAt>eqAt) {AVTK(URID(LS.substring(preAmpAt,eqAt)),URID(LS.substring(eqAt+1,ampAt)));preAmpAt=ampAt+1;eqAt=ampAt=-1;++k;};};if (LS.charAt(preAmpAt)!="=" && (preAmpAt!=0 || i!=0 || c!="=")) {if (preAmpAt!=l) {if (eqAt!=-1) AVTK(URID(LS.substring(preAmpAt,eqAt)),URID(LS.substring(eqAt+1,l)));else if (preAmpAt!=l-1) AVTK(URID(LS.substring(preAmpAt,l)),"");};if (l==1) AVTK(LS.substring(0,1),"");};};};var TC=OL(QS);if (!TC) TC=0;QS.toString=function() {return LS.toString()};QS.Count=function() {return (TC ? TC:0)};QS.Count.toString=function() {return (TC ? TC.toString():"0")};QS.Item=function(e) {if (typeof(e)=="undefined") return LS;else {if (typeof(e)=="number") {var e=Math.ceil(e);var c=0;for (var i in QS) {if (typeof(QS[i])!="function" && ++c==e) return QS[i];};Err("ERROR: Index out of range in\nRequest.QueryString().Item("+e+")");}else return QS[KM(e, QS)];};return "undefined";};QS.Item.toString=function() {return LS.toString()};QS.Key=function(e) {var t=typeof(e);if (t=="number") {var e=Math.ceil(e);var c=0;for (var i in QS) {if (typeof(QS[i])!="function" && ++c==e) return i;}}else if (t=="string") {var e=KM(e, QS);var a=QS[e];return (typeof(a)!="undefined" && a && a.toString() ? e:"");}else Err("ERROR: Wrong number of arguments or invalid property assignment\nRequest.QueryString().Key("+(e?e:"")+")");Err("ERROR: Index out of range in\nRequest.QueryString().Item("+e+")");};QS.Key.toString=function() {Err("ERROR: Wrong number of arguments or invalid property assignment\nRequest.QueryString().Key");};this.QueryString=function(k) {if (typeof(k)=="undefined") return QS;else {var k=KM(k, QS);if (typeof(QS[k])=="undefined") {t=new Object();t.Count=function() {return 0};t.Count.toString=function() {return "0"};t.toString=function() {return "undefined"};t.Item=function(e) {return "undefined"};t.Item.toString=function() {return "undefined"};t.Key=function(e) {Err("ERROR: Object doesn't support this property or method\nRequest.QueryString.Key("+(e?e:"")+")");};t.Key.toString=function() {return "undefined"};return t;}if (typeof(k)=="number") return QS.Item(k);else return QS[k];}}; this.QueryString.toString=function() {return LS.toString();};this.QueryString.Count=function() {return (TC ? TC:0)};this.QueryString.Count.toString=function() {return (TC ? TC.toString():"0")};this.QueryString.Item=function(e) {if (typeof(e)=="undefined") return LS.toString();else {if (typeof(e)=="number") {var e=Math.ceil(e);var c=0;for (var i in QS) {if (typeof(QS[i])!="function" && ++c==e) return QS[i];};Err("ERROR: Index out of range in\nRequest.QueryString.Item("+e+")");}else return QS[KM(e, QS)];}if (typeof(e)==("number")) Err("ERROR: Index out of range in\nRequest.QueryString.Item("+e+")");return "undefined";};this.QueryString.Item.toString=function() {return LS.toString()};this.QueryString.Key=function(e) {var t=typeof(e);if (t=="number") {var e=Math.ceil(e);var c=0;for (var i in QS) {if (typeof(QS[i])=="object" && (++c==e)) {return i;}}}else if (t=="string") {var e=KM(e, QS);var a=QS[e];return (typeof(a)!="undefined" && a && a.toString() ? e:"");}else Err("ERROR: Wrong number of arguments or invalid property assignment\nRequest.QueryString.Key("+(e?e:"")+")");Err("ERROR: Index out of range in\nRequest.QueryString.Item("+e+")");};this.QueryString.Key.toString=function() {Err("ERROR: Wrong number of arguments or invalid property assignment\nRequest.QueryString.Key");};}var Request=new RObj(false);

function SetCookie (name, value)			{
//alert("setting c")
var argv = SetCookie.arguments;var argc = SetCookie.arguments.length;

var expDays = 3000;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

var expires =exp;//(argc > 2) ? argv[2] : null;
var path = "/";//(argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) +  ((secure == true) ? "; secure" : "");
}
function set_currency(CurCode){SetCookie('CurCode',CurCode);window.location.reload();}
var rn = Math.random();

function new_rn(){return Math.random();}
function write_frame(name,url,width,height){document.write('<ifr' + 'ame' +' name="'+name+'" ' +' id="'+name+'" ' +' width="'+width+'"' +' height="'+height+'"'  +' frameborder="0"' +' src=' + url +' marginwidth="0"' +' marginheight="0"' +' vspace="0"' +' hspace="0"' +' allowtransparency="true"' +' scrolling="no">');document.write('</ifr' + 'ame>');}

function getForm(obj){
 var getstr = "";
 //alert(obj.innerHTML);
 //alert(obj.childNodes.length);
      for (var i=0; i < obj.elements.length; i++) {
    //  alert(obj.elements[i].tagName);
         if (obj.elements[i].tagName == "INPUT") {
       
      //  alert(obj.childNodes[i].type);
            if (obj.elements[i].type == "text" || "hidden" ) {
			  // alert(obj.elements[i].type);
               getstr += obj.elements[i].name + "=" +  str_encode(obj.elements[i].value) + "&";
            }
            if (obj.elements[i].type == "checkbox") {
               if (obj.elements[i].checked) {
                  getstr += obj.elements[i].name + "=" + obj.elements[i].value + "&";
               } else {
                  getstr += obj.elements[i].name + "=&";
               }
            }
            if (obj.elements[i].type == "radio") {
               if (obj.elements[i].checked) {
                  getstr += obj.elements[i].name + "=" + obj.elements[i].value + "&";
               }
            }
            
         }   
         if (obj.elements[i].tagName == "SELECT") {
            var sel = obj.elements[i];
            getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
         }
          if (obj.elements[i].type == "textarea") {
			 getstr += obj.elements[i].name + "=" + str_encode(obj.elements[i].value) + "&";
			   //getstr += obj.elements[i].name + "=" + obj.elements[i].value + "&";
            }
       //  else{alert(obj.elements[i].type );}
         
         
      }
      return getstr;
}


 function str_encode(inputstr) {
   
    try
    {
        outstr = encodeURIComponent(inputstr);
    }
    catch(e)
    {
        outstr = escape(inputstr);
    }
    return outstr;
}



function CreateBookmarkLink() {

 title =document.title;// "Webpage Title"; 
  // Blogger - Replace with <$BlogItemTitle$> 
  // MovableType - Replace with <$MTEntryTitle$>

 url = location.href;
  // Blogger - Replace with <$BlogItemPermalinkURL$> 
  // MovableType - Replace with <$MTEntryPermalink$>
  // WordPress - <?php bloginfo('url'); ?>

/*	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
		*/
		
		
		 var ua=navigator.userAgent.toLowerCase();
    var isKonq=(ua.indexOf('konqueror')!=-1);
    var isSafari=(ua.indexOf('webkit')!=-1);
    var isMac=(ua.indexOf('mac')!=-1);
    var buttonStr=isMac?'Command/Cmd':'CTRL';

    if(window.external && (!document.createTextNode ||
      (typeof(window.external.AddFavorite)=='unknown'))) {
        // IE4/Win generates an error when you
        // execute "typeof(window.external.AddFavorite)"
        // In IE7 the page must be from a web server, not directly from a local 
        // file system, otherwise, you will get a permission denied error.
        window.external.AddFavorite(url, title); // IE/Win
    } else if(isKonq) {
      alert('You need to press CTRL + B to bookmark our site.');
    } else if(window.opera) {
      void(0); // do nothing here (Opera 7+)
    } else if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if(window.home || isSafari) { // Firefox, Netscape, Safari, iCab
      alert('You need to press '+buttonStr+' + D to bookmark our site.');
    } else if(!window.print || isMac) { // IE5/Mac and Safari 1.0
      alert('You need to press Command/Cmd + D to bookmark our site.');    
    } else {
      alert('In order to bookmark this site you need to do so manually '+
        'through your browser.');
    }

 }

var expDays = 365;var exp = new Date();exp.setTime(exp.getTime() + (expDays*24*60*60*1000));function setCookie (name, value) {document.cookie = name + "=" + escape (value) +"; expires=" + exp.toGMTString() +  "; path=/";}function getCookieVal(offset){var endstr = document.cookie.indexOf (";", offset);if (endstr == -1)endstr = document.cookie.length;return unescape(document.cookie.substring(offset, endstr));}function GetCookie(name){var arg = name + "=";var alen = arg.length;var clen = document.cookie.length;var i = 0;while (i < clen){var j = i + alen;if (document.cookie.substring(i, j) == arg)return getCookieVal (j);i = document.cookie.indexOf(" ", i) + 1;if (i == 0) break;}return null;}


function DoNothing(){return;}


function  NotifyLogin(){
	//alert('Youve been loged in!');
	ShowLogoutButton(true);
}

function  NotifyLogout(){
	//alert('Youve been loged out!');
	ShowLogoutButton(false);ShowLogoutButton(false);
}

function signin(){
	loadSection('login');
	//setDetails('../Signin/Default.asp?OnlyContent=true');
}

function DoSignin(){

	//var oForm = document.getElementById("page_data");
	//oForm.action = '/signin/signin.asp';
	//oForm.method = 'POST';
	//oForm.submit();
	
	

var url = '/signin/signin.asp'
var pars = getForm(document.getElementById("page_data"));
//alert(document.getElementById("page_data"));
//alert(pars);
//return;

show_pleasewait();

	new Ajax.Request(url,
	{
		method:'POST'
		,defaultHeaders: {'Content-Type': 'text/html;charset=ISO-8859-15'}
		,postBody: pars
		,onSuccess: function(transport){
		var response = transport.responseText || "no response text";

	//	alert('Response:'+response);
		document.getElementById("container-main").innerHTML =response;
		return false;
		},
		onFailure: function(transport){ alert('Something went wrong...\n' + transport.responseText) }
	});
}

function eventsNewCheck(){

var url = '/events/default.asp'
var pars = 'action=get_newevents';
//alert(document.getElementById("page_data"));
//alert(pars);
//return;

	new Ajax.Request(url,
	{
		method:'POST'
		,defaultHeaders: {'Content-Type': 'text/html;charset=ISO-8859-15'}
		,postBody: pars
		,onSuccess: function(transport){
		var response = transport.responseText || "no response text";

	//	alert('Response:'+response);
		if(response=='True'){
		//alert('Is Logged In');
		NotifyLogin();
		}else{
		//alert('NOt Logged In'); 
		NotifyLogout();
		}
	//	document.getElementById("container-main").innerHTML =response;
		return false;
		},
		onFailure: function(transport){ alert('Something went wrong...\n' + transport.responseText) }
	});
}

function signout(){
	//setDetails('../Signin/Default.asp?RESPONSE=LOGOUT&OnlyContent=true');
	document.getElementById("action").value="logout";
	DoProcess();
}

function ShowLogoutButton(bDisplayLogout){
	
	if (bDisplayLogout==true)
		{
						document.getElementById("sign_in_btn").innerHTML = '<A href="Javascript:signout();" title="Sign out!"><img border="0" src="http://mediaserver.networkmaple.com/MBS/PassportOrange/iFace/sign_out.gif" width="66" height="19"></a>';

					}
		else
		{
			document.getElementById("sign_in_btn").innerHTML = '<A href="Javascript:signin();"><img border="0" src="http://mediaserver.networkmaple.com/MBS/PassportOrange/iFace/sign_in.gif" width="66" height="19"></a>';

		}
}


function LoadDefault(){
	//if(txt_defaulturl==" "){
	//	setDetails('MyPassport.asp?OnlyContent=true');
		setDetails(txt_defaulturl)
		
		
		var bIsLoggedIn = '<%=UCASE(bIsLoggedIn)%>';
		if(bIsLoggedIn == 'FALSE'){ShowLogoutButton(true);}else{ShowLogoutButton(false);}
	//}
//	else{
	//
//	}
}




function loadSection(code){
show_pleasewait();

//alert(code);
var url = '/incs/home_page_sections/default.asp'
var pars = 'code='+code; // + '&' + getForm(document.getElementById("frm_PageData"))
	new Ajax.Request(url,
	{
		method:'POST'
		,defaultHeaders: {'Content-Type': 'text/html;charset=ISO-8859-15'}
		,postBody: pars
		,onSuccess: function(transport){
		var response = transport.responseText || "no response text";

	//	alert('Response:'+response);
		document.getElementById("container-main").innerHTML =response;
		return false;
		},
		onFailure: function(transport){ alert('Something went wrong...\n' + transport.responseText) }
	});
}

function show_pleasewait(){
var sHtml = '<div id="main"><div id="pageTitle"><h1>Please wait...</h1></div><div id="mainBody"><h2 style="margin-top:55px;"><div class="wait_anim"></div></h2></div>';
document.getElementById("container-main").innerHTML =sHtml;

}

function DoProcess(){

var url = '/incs/exec/default.asp'
var pars = getForm(document.getElementById("page_data"));
//alert(document.getElementById("page_data"));
//alert(pars);
//return;

show_pleasewait();

	new Ajax.Request(url,
	{
		method:'POST'
		,defaultHeaders: {'Content-Type': 'text/html;charset=ISO-8859-15'}
		,postBody: pars
		,onSuccess: function(transport){
		var response = transport.responseText || "no response text";

	//	alert('Response:'+response);
		document.getElementById("container-main").innerHTML =response;
		return false;
		},
		onFailure: function(transport){ alert('Something went wrong...\n' + transport.responseText) }
	});
}


function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   if(document.getElementById('action').value!==''){  DoProcess();};
    //document.getElementById('formlogin').submit();
   //myfield.form.submit();
   return false;
   }
else
   return true;
}


function Signin_submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   DoSignin();
    //document.getElementById('formlogin').submit();
   //myfield.form.submit();
   return false;
   }
else
   return true;
}

function start(){
window.setInterval('eventsNewCheck();',5000);
//alert(bAutorunProcess);
if(bAutorunProcess){
//alert('Run Process');
DoProcess();
}
else{loadSection('home');}
}