﻿
//****************************************

var StyleSheetFile = "/includes/GlobalStyles_800.css"
var blnRes800 = "true"
var FadedImagePath = "/images/bkgStepsFade_800.gif" 
var varBrowser ,cookieBrowserVal;
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;
var varFormName ="";


xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

InitVars();    

function InitVars(){    
    
    if (screen.width > 800 && screen.height > 600) {
        //StyleSheetFile = "/includes/GlobalStyles.css";
        blnRes800 ="false";        
    }
    
    //GetBrowserType into cookie so that it is not checked again within the session.
   // cookieBrowserVal = readCookie("MIMNewBrowser");
    
    //alert(cookieBrowserVal );
    //if (cookieBrowserVal == null){    
        //alert('firsttime');
        GetBrowserType();                
      //  createCookie("MIMBrowser",varBrowser,"");                  
    //}
    
    
    //if (cookieBrowserVal !="IE") FadedImagePath = "/images/bkgStepsFade_1024.gif";
    /*
    var headID = document.getElementsByTagName("head")[0];         
    var cssNode = document.createElement('link');
    cssNode.type = 'text/css';
    cssNode.rel = 'stylesheet';
    cssNode.href = StyleSheetFile;
    cssNode.media = 'all';
    headID.appendChild(cssNode);
*/


}

function CheckBrowserType(){
    
    if (varBrowser == "Safari" || cookieBrowserVal == "Safari") {
       /* alert("We apologize for the inconvenience but the Safari Internet browser does not support the .NET code used to develop this site.  On your Macintosh you could instead download and use the free Mozilla Firefox browser available at http://www.mozilla.com/en-US/firefox/all.html or the Opera browser available at http://www.opera.com/download/index.dml?custom=yes. ")
        window.location="/Default.aspx";
        return false;*/
        //window.location="/default.aspx"
    }
    return true;
}

function GetBrowserType(){    
    if (checkIt('safari')) varBrowser = "Safari"
    else if (checkIt('omniweb')) varBrowser = "OmniWeb"
    else if (checkIt('opera')) varBrowser = "Opera"
    else if (checkIt('webtv')) varBrowser = "WebTV";
    else if (checkIt('icab')) varBrowser = "iCab"
    else if (checkIt('msie')) varBrowser = "IE"
    else if (checkIt('mozilla')) varBrowser = "mozilla"
    else if (!checkIt('compatible'))
    {
	    browser = "Netscape Navigator"
	    version = detect.charAt(8);
    }
    else varBrowser = "An unknown browser";

    if (!version) version = detect.charAt(place + thestring.length);

    /*if (!OS)
    {
	    if (checkIt('linux')) OS = "Linux";
	    else if (checkIt('x11')) OS = "Unix";
	    else if (checkIt('mac')) OS = "Mac"
	    else if (checkIt('win')) OS = "Windows"
	    else OS = "an unknown operating system";
    }*/
     
}
    
function checkIt(string) {
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}


function GetScreenRes(){
	
	var intColFormat = 3;
					
	/*if (screen.width > 800 && screen.height > 600) { 
		intColFormat = 3;	
	}*/
	
	if (blnRes800 == "true") intColFormat = 2;

	createCookie("MIMFormat",intColFormat,7);		
				
}

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; 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 fncAgtOfcWin(sURL,sType) { 
			
	var sWidth = 800;
	var sHeight= 700;
	var sWinName = "PopDetUpWin";
	var sScrollBars = "yes"
	var sResizable = "yes"
	var sMenuBar = "yes"
	
	//alert(sWidth + ';' + sHeight + ';' + sType)
			
	if (sType == '0') {
		sWinName = "PopUpWin";
		/*sWidth = 700;
		sHeight= 700;
		sWinName = "PopUpOfcWin";
		sScrollBars ="yes"
		sResizable = "yes"
		sMenuBar = "no"*/
	}
	
	if (sType == '1') {
		sWinName = "PopUpWin";
		sWidth = 690;
		sHeight= 700;
		sWinName = "PopUpOfcWin";
		sScrollBars ="yes"
		sResizable = "yes"
		sMenuBar = "no"
	}
	if (sType == '2') {	// 2 - is for office contact page.
		sWidth = 600;
		sHeight= 300;
		sWinName = "PopUpOfcWin";
		sScrollBars ="no"
		sResizable = "no"
		sMenuBar = "no"
	}
	
	if (sType == '3') {	//  - is for Agent page.
		sWidth = 600;
		sHeight= 350;
		sWinName = "PopUpAgtWin";
		sScrollBars ="no"
		sResizable = "no"
		sMenuBar = "no"
	}
	
	if (sType == '4') {	//  - is for Email page.
	
		sWidth = 600;
		sHeight= 370;
		sWinName = "PopUpEmailWin";
		sScrollBars ="no"
		sResizable = "yes"
		sMenuBar = "no"
	}	
	
	if (sType == '5') {
		sWinName = "PopUpWinPrint";
		/*sWidth = 700;
		sHeight= 700;
		sWinName = "PopUpOfcWin";
		sScrollBars ="yes"
		sResizable = "yes"
		sMenuBar = "no"*/
	}
	
	//alert(escape(sURL));
	//window.open(sURL ,'','toolbar=no,status=no,resizable=yes,scrollbars=yes,location=no,menubar=no,directories=no,width=' + sWidth + ',height=' + sHeight + ',top=10,left=70'); 
	var windowOptions  = "toolbar=no,status=no,resizable=" + sResizable + ",scrollbars=" + sScrollBars + ",location=no,menubar=" + sMenuBar + ",directories=no,width=" + sWidth + ",height=" + sHeight + ",top=50,left=50";	
	myWindowHandle = window.open(sURL,sWinName, windowOptions);	
		
	myWindowHandle.focus();			
} 

function fncOpenAgtOfcPopUp(sURL,sType,intSource,sParentInfo) { 
	
//	alert("Type=" + sType + "; src=" + intSource);
	
	var	sWidth = 600;
	var	sHeight= 370;
	var	sWinName = "PopUpEmailWin";
	var	sScrollBars ="no"
	var	sResizable = "yes"
	var	sMenuBar = "no"
	var windowOptions  = "toolbar=no,status=no,resizable=" + sResizable + ",scrollbars=" + sScrollBars + ",location=no,menubar=" + sMenuBar + ",directories=no,width=" + sWidth + ",height=" + sHeight + ",top=50,left=50";	
	
	//Run Lead Capture Scripts - on Type - 1: web address, 2: email clicks    
    //RunLeadCaptureScripts(sType,intSource,sParentInfo);
    
    //alert (sURL);
    //alert(sParentInfo);
    
    var strBrowserData = readCookie("MIM_BRowserInfo");
        
    sURL = sURL + "&BrowserInfo=" + strBrowserData + "&LCInfo=" + sType + "|" + intSource + "|" + sParentInfo;
        
	myWindowHandle = window.open(sURL,sWinName, windowOptions);	
		
	myWindowHandle.focus();			
} 

function fncOpenAgtOfcPopUp_Orig(sURL,sType,intSource,sParentInfo) { 
	
//	alert("Type=" + sType + "; src=" + intSource);
	
	var	sWidth = 600;
	var	sHeight= 370;
	var	sWinName = "PopUpEmailWin";
	var	sScrollBars ="no"
	var	sResizable = "yes"
	var	sMenuBar = "no"
	var windowOptions  = "toolbar=no,status=no,resizable=" + sResizable + ",scrollbars=" + sScrollBars + ",location=no,menubar=" + sMenuBar + ",directories=no,width=" + sWidth + ",height=" + sHeight + ",top=50,left=50";	
	
	//Run Lead Capture Scripts - on Type - 1: web address, 2: email clicks    
    RunLeadCaptureScripts(sType,intSource,sParentInfo);
    
	myWindowHandle = window.open(sURL,sWinName, windowOptions);	
		
	myWindowHandle.focus();			
} 

function fncOpenWebWin(sURL,sType,intSource,sParentInfo) { 

//    alert("Type=" + sType + "; src=" + intSource + ";" + sParentInfo);

    //Run Lead Capture Scripts - on Type - 1: web address, 2: email clicks    
    RunLeadCaptureScripts(sType,intSource,sParentInfo);
    
    window.open (sURL);
}

function fncOpenPrintWindow(sURL,sType) { 
			
    var sWidth = 800;
	var sHeight= 410;
	var sWinName = "PrintWin";	
	var sScrollBars ="no"
	var sResizable = "no"
	var sMenuBar = "no"
		
	if (sType == 2) sHeight= 360;
	var windowOptions  = "toolbar=no,status=no,resizable=" + sResizable + ",scrollbars=" + sScrollBars + ",location=no,menubar=" + sMenuBar + ",directories=no,width=" + sWidth + ",height=" + sHeight + ",top=150,left=150";	
	myWindowHandle = window.open(sURL,sWinName, windowOptions);			
	myWindowHandle.focus();			
} 

function mouseX(evt) {
    
    if (evt.pageX) return evt.pageX;
    else if (evt.clientX)
    return evt.clientX + (document.documentElement.scrollLeft ?   document.documentElement.scrollLeft :   document.body.scrollLeft);
    else return null;
}

function mouseY(evt) {
    if (evt.pageY) return evt.pageY;
    else if (evt.clientY)
    return evt.clientY + (document.documentElement.scrollTop ?    document.documentElement.scrollTop :   document.body.scrollTop);
    else return null;
}


function ltrim ( s ){
	return s.replace( /^\s*/, "" );
}

function rtrim ( s ){
	return s.replace( /\s*$/, "" );
}

function trim ( s ){
	return rtrim(ltrim(s));
}

function FindAbsolutePosition(obj) 
{
    var posX = 0;
    var posY = 0;
    // alert("obj=" + obj.id + ";" + posX + ";" + posY); 
    while (obj != null)
    {
        posX += obj.offsetLeft;
        posY += obj.offsetTop;
        obj = obj.offsetParent;
    }
     //alert(posX + ";" + posY);
     return posY;
	//return {top:posY, left:posX};
}

function RedirectToHome(){        
    window.location ="Default.aspx";
}

function captureMousePosition(e) {
    
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has 
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position 
        // reflects the position from the top/left of the screen the 
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no 
        // matter if the user has scrolled or not.
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard 
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
    
    //alert("xMousePos=" + xMousePos + ", yMousePos=" + yMousePos + ", xMousePosMax=" + xMousePosMax + ", yMousePosMax=" + yMousePosMax);

}


function RemoveNonAlphaChars(output) {    

    //Space allowed.
    output = output.replace(/[^a-zA-Z 0-9@]+/g,'');
    
    return output;
} 
