var t = Number(900000);
//t = t-30000;
function getMaxSessIdleTime(){

	return(t-30000);
}

function isAjaxCallReq(){
	return false;
}


function whichBrowser() {
    var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("opera") != -1) return 'Opera';
    if (agt.indexOf("staroffice") != -1) return 'Star Office';
    if (agt.indexOf("webtv") != -1) return 'WebTV';
    if (agt.indexOf("beonex") != -1) return 'Beonex';
    if (agt.indexOf("chimera") != -1) return 'Chimera';
    if (agt.indexOf("netpositive") != -1) return 'NetPositive';
    if (agt.indexOf("phoenix") != -1) return 'Phoenix';
    if (agt.indexOf("firefox") != -1) return 'Firefox';
    if (agt.indexOf("safari") != -1) return 'Safari';
    if (agt.indexOf("skipstone") != -1) return 'SkipStone';
	if (agt.indexOf("msie 6.0") != -1) return 'ie6';
    if (agt.indexOf("msie") != -1) return 'Internet Explorer';
    if (agt.indexOf("netscape") != -1) return 'Netscape';
    if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
    if (agt.indexOf('\/') != -1) {
        if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
            return navigator.userAgent.substr(0,agt.indexOf('\/'));
        } else {
            return 'Netscape';
        }
    } else if (agt.indexOf(' ') != -1) {
        return navigator.userAgent.substr(0,agt.indexOf(' '));
    } else {
        return navigator.userAgent;
    }
} 


// get the current URL
var url = window.location.toString();

//get the parameters
url.match(/\?(.+)$/);
var params = RegExp.$1;

 // split up the query string and store in an
 // associative array
var params = params.split("&");
var queryStringList = {};
var qryval;
for(var i=0;i<params.length;i++)
{
	var tmp = params[i].split("=");
 	queryStringList[i] = unescape(tmp[1]);
}


var mpt_flag = false;
if(queryStringList[0]){
	if(queryStringList[0] == 'mpt'){
		mpt_flag = true;
	}
}
function getMPTurl(){
	return url;
}
function isMPTUrl(){
	return mpt_flag;
}




var timer1 = null,timer= null;

/* Getting Maximum session idle time from skin.wmt */
var t = getMaxSessIdleTime();

/* Timer is set when only if user is logged in. */
function invokeSessionTracker(){
	chk_loginStatus = true;
	//timer=setInterval("showPopup()",t);
	jQuery(document).mousemove(reset_interval);
	timer=setTimeout("showPopup()",t);
}

function getLoginUrl(){
	var url = 'http://www.paltalk.com/browse/webapp/login.wmt'
	return url;
}


/* Getting Login Url required fro lightbox */
var loginurl = getLoginUrl();

/* Functions to trim string */
function ltrim(testStr) { 
   if (testStr == "") 
      return ""; 
   else { 
      var pattern = /[^\s]+.*/; 
      result = testStr.match(pattern); 
      return result[0]; 
   } 
} 
function rtrim(testStr) { 
   if (testStr == "") 
      return ""; 
   else { 
      var pattern = /.*[\S]/; 
      result = testStr.match(pattern); 
      return result[0]; 
   } 
} 

function trim(testStr) { 
   return rtrim(ltrim(testStr)); 
} 


var isClose = false;
function reset_interval()
{
	//clearInterval(timer1);
	//timer1 = null;
	if(isClose){
		resume();
		if(isAjaxCallReq()){
			ajaxFunction(getAjaxurl()+'true&date='+new Date(),'GET');
		}
	}
	timerreset()

}
var isReset = false;
function timerreset(){

	//timer = null;
	//clearInterval(timer);
	clearTimeout(timer);
	//timer=setInterval("showPopup()",t);
	timer=setTimeout("showPopup()",t);
}
var flag1 = true;
var isResume = false;
function resume(){
		isResume = true;
		isReset = true;
		isClose = false;
}

function showPopup()
{
	if(chk_loginStatus){
		isClose = true;
		timer = null;
		flag1 = false;
		//document.getElementById('TB_overlay_warn').className="TB_overlayBG";
		//document.getElementById('WarningBox').className="warning_box";
		jQuery.jGrowl('<h4>You will be logged out of Paltalk</h4><p>Due to inactivity you will be logged out soon. To stay logged in please move your mouse or click on the site.</p>',{life:10000,theme:'growl-message',speed: 'slow',  beforeClose: function(e,m) {
		if(!isResume){
			isReset = false;
			inValidate();
			
		}
		isResume = false;
    }});
		//clearTimeout(timer);
		//timer= setTimeout("inValidate()",10000);
	}
}

var sessionExpired = false;
function isSessionExpired(){
	return sessionExpired;
}

function showLoginDiv(){
	return flag1;
}

function inValidate(){
	if(!isReset){
		var myDate = new Date();
		myDate.setDate(myDate.getDate()+5);
		set_cookie('postLogoutMessage', 'User logged out due to inactivity.',myDate,'paltalk.com');
		clearInterval(timer);
		isClose=false;
		//document.getElementById('TB_overlay_warn').className="hide";
		//document.getElementById('WarningBox').className="hide";
		userLogout();
	}
	else{
		timerreset();
		isReset = false;
		return;
	}
}

function userLogout(){
	clearInterval(timer);
	clearInterval(timer1);
	chk_loginStatus = false;
	document.logout.submit();
}

function closepopup(){
	if(isClose){
		reset_interval();
		isClose = false;
	}
}

var popup;
var isPopupOpened = false;
var warnlogout_flag = false;
function warnLogout(){
		flag1 = false;
		warnlogout_flag = true;
		if(isPopupOpened){
			popup.close();
			isPopupOpened = false;
		}
		showLogin();
		clearInterval(timer1);
		timer1 = setInterval("userLogout()",5000);
}

function isWarnLogout(){
	return warnlogout_flag;
}

var target="";
function getTarget(){	
	return target;
}

function offensivePopup(win){
	popup = win;
	isPopupOpened = true;
	//alert(popup);
}
function refreshIframe(){
	var newdiv = document.createElement('div');
	var divIdName = "TB_window";
	newdiv.setAttribute('id',divIdName);
	newdiv.className="hide";  
	document.body.appendChild(newdiv); 
	var ifr = "IF_"+new Date().getTime();
	newdiv.innerHTML = "<iframe id='"+ifr+"' src='"+loginurl+"' frameborder='0' class='login-window'></iframe>";
	//newdiv.parentNode.removeChild(newdiv);
}





