var switchSize = 1024;

// Open PopUp PDF window
function openpdfWindow(theURL)
{
        window.open(theURL,'PopUp','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=700,height=500');
}

// Open HTMl page in PopUp window

function openWindow(theURL)
{
        window.open(theURL,'PopUp','width=700,height=500, toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
}

// Open HTMl page in PopUp window

function openWebWindow(theURL)
{
        window.open(theURL,'PopUp','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=700,height=700');
}

// Open OLS tour page in PopUp window
function openOlsWindow(theURL)
{
        window.open(theURL,'PopUp','scrollbars=yes,width=764,height=540,top=50,left=50');
} 

function MM_openBrWindow(theURL,winName,features) 
{ 
         window.open(theURL,winName,features);
}

// Open OLS Security page in PopUp window
function openOlsSecureWindow(theURL)
{
        window.open(theURL,'PopUp','scrollbars=yes,resizable=no,width=440,height=270,top=50,left=50');
}


function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object()
	this.get=Querystring_get
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key]
	if (value==null) value=default_;
	
	return value
}

function openNewWindow(theURL,width,height,warn,siteId,warnf)
{
		if (width == null)
			width = 700;
		if (height == null)
			height = 500;
		if (warn == null) 
			warn = false;			

		// This retrieves values from incoming request, and parses respectively
		var qs = new Querystring();
		
		// Determine if we are previewing on the CMA. If yes, then the location of the warning message will be different than CDA.
		var preview = qs.get('prev','no');
		var host = location.hostname;
		var port = location.port;
		// Initialize host to be preappended to the location of the warning.
		var preappender = "";
		
		if (preview=="yes") {
			// preappender = "oos";			
		} else {
			// Set the hostname
			preappender = "http://" + host + ":" + port;
		}


		if (warn == 'true') {
	        window.open(preappender + '/staticfiles/'+siteId+'/documents/'+warnf+'?exturl='+theURL+'&openincaller=false','ExtPopUp','width='+width+',height='+height+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');			        
		} else {
			window.open(theURL,'ExtPopUp','width='+width+',height='+height+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
		}
}

function openNewSite(theURL,siteId,warningfilename)
// This function is used when opening a new site in the active window.
// warn is boolean on whether to redirect user to a warning page prior to the external site.
{

		// This retrieves values from incoming request, and parses respectively
		var qs = new Querystring();
		
		// Determine if we are previewing on the CMA. If yes, then the location of the warning message will be different than CDA.
		var preview = qs.get('prev','no');
		var host = location.hostname;
		var port = location.port;
		// Initialize host to be preappended to the location of the warning.
		var preappender = "";
		
		if (preview=="yes") {
			// preappender = "oos";			
		} else {
			// Set the hostname
			preappender = "http://" + host + ":" + port;
		}
		
		// This was commented, as the warning is no longer optional and not passed in any longer as parameter.
		//if (warn == 'true') {
	    
	        window.open(preappender + '/staticfiles/'+siteId+'/documents/'+warningfilename+'?exturl='+theURL+'&openincaller=true','ExtPopUp','width=700,height=500,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');			        
		
		//} else {
		//	document.location=theURL;
		//}
}

/***
document.writeln("<style type=\"text/css\">\n");
// define styles that can only be used for last generation browser
if (w3c || ie4)
{
	document.writeln(".textinput { font-size: 11px; background-color: #ffffff; color: #003366; border-width: 1px; border-style: solid; border-color: #647c8c; height: 17px; padding-left: 2px; }\n");
}
else
{
	document.writeln(".textinput { font-size: 11px; background-color: #ffffff; color: #003366; height: 17px; padding-left: 2px; }\n");
}
document.writeln("</style>\n");
**/

function UBS_getBrowserWidth()
{
	var outerWidth = (document.all) ? document.body.clientWidth + 28 : window.outerWidth;
	return outerWidth;
}


function UBS_getBrowserWidth12() {
	
	 alert("coming here");

	browserNm = getBrowserName();
	
	if (browserNm == "NN") {
	  var switchSizeBody = 1024;
	  var browserWidth = (document.all) ? document.body.clientWidth + 28 : window.outerWidth;
	  //alert("browserWidth is " + browserWidth);
	} else {
	  var switchSizeBody = 1024;
	  var browserWidth = window.document.body.scrollWidth + 28;
	  //alert("browserWidth is vvv" + browserWidth);
  	  return browserWidth;
       }	  
}

function UBS_getContentWidth( type )
{
	var contentWidth;
	var browserWidth = UBS_getBrowserWidth();
	//alert("browserWidth is " + browserWidth);
    //alert("browserWidth --" + browserWidth + ";  switchSize --" +switchSize);
	if (checkHighResolution())
	{
		switch( type )
		{
			
			case "homepage": contentWidth = 726; break;
			case "homeleft": contentWidth = 265; break; // 252+13
			case "homemiddle": contentWidth = 259; break; // 246+13
			case "rightfeature": contentWidth = 526; break; //with left nav, mid, right box
			case "rightfeaturemiddle": contentWidth = 291; break; //with left nav, mid, right box. ONLY FOR TOP IMAGES
			case "restop": contentWidth = 688; break; //top image
			case "rightfeatureworbox": contentWidth = 651; break; //with left nav, mid
			case "box": contentWidth = 200; break; //middle subnode
			case "teaser": contentWidth = 168; break; //width of teasers
			
			default: contentWidth = 648;
			
			//alert(browserWidth);
			
		}
	}
	else
	{
		switch( type )
		{
			case "homepage": contentWidth = 585; break;
			case "homeleft": contentWidth = 159; break; // 146+13
			case "homemiddle": contentWidth = 224; break; // 211+13
			case "rightfeature": contentWidth = 385; break; //with left nav, mid, right box
			case "rightfeaturemiddle": contentWidth = 150; break; //with left nav, mid, right box. ONLY FOR TOP IMAGES
			case "restop": contentWidth = 547; break; //top image
			case "rightfeatureworbox": contentWidth = 510; break; //with left nav, mid
			case "box": contentWidth = 154; break; //middle subnode
			case "teaser": contentWidth = 121; break; //width of teasers
			
			default: contentWidth = 506;
			
			//alert(browserWidth);
		}
	}

	return contentWidth;
}

function getBrowserName() {
	var browserName = navigator.appName;
	var browserVer = parseInt(navigator.appVersion);
	if (browserName == "Netscape"){
		var ver = "NN";
	} else if (browserName == "Microsoft Internet Explorer"){
		var ver = "IE";	
	}
	return ver; 
}
	


function UBS_getContentBodyWidth( type )
{
	
	var contentWidth;
	
	browserNm = getBrowserName();
	
	if (browserNm == "NN") {
	  var switchSizeBody = 1024;
	  var browserWidth = (document.all) ? document.body.clientWidth + 28 : window.outerWidth;
	  //alert("browserWidth is " + browserWidth);
	} else {
	  var switchSizeBody = 1024;
	  //alert("original " + window.document.body.scrollWidth);
	  var browserWidth = window.document.body.scrollWidth + 28;
	  //alert("browserWidth is " + browserWidth);

	}
	
		
	if (checkHighResolution())
	{
		switch( type )
		{
			case "homepage": contentWidth = 726; break;
			case "homeleft": contentWidth = 265; break; // 252+13
			case "homemiddle": contentWidth = 259; break; // 246+13
			case "rightfeature": contentWidth = 526; break; //with left nav, mid, right box
			case "rightfeaturemiddle": contentWidth = 291; break; //with left nav, mid, right box. ONLY FOR TOP IMAGES
			case "rightfeatureworbox": contentWidth = 651; break; //with left nav, mid
			case "teaser": contentWidth = 168; break; //width of teasers
			
			default: contentWidth = 648;
		}
	}
	else
	{
		switch( type )
		{
			case "homepage": contentWidth = 585; break;
			case "homeleft": contentWidth = 159; break; // 146+13
			case "homemiddle": contentWidth = 224; break; // 211+13
			case "rightfeature": contentWidth = 385; break; //with left nav, mid, right box
			case "rightfeaturemiddle": contentWidth = 150; break; //with left nav, mid, right box. ONLY FOR TOP IMAGES
			case "rightfeatureworbox": contentWidth = 510; break; //with left nav, mid
			case "teaser": contentWidth = 121; break; //width of teasers
						
			default: contentWidth = 506;
		}
	}
	return contentWidth;
}



function UBS_getBackgroundImage( type, image )
{
	var width = UBS_getContentWidth( type );
	return "<img src=\"/mcs/cda/images/bg_"+image+"_"+width+"x1.gif\" width=\""+width+"\" height=\"1\" alt=\"\" border=\"0\">";
}

function UBS_getContentImage( type )
{
	return "<img src=\"/mcs/cda/images/1px_trans.gif\" width=\""+UBS_getContentWidth( type )+"\" height=\"1\" border=\"0\">";
}

function checkHighResolution()
{
	var browserWidth = UBS_getBrowserWidth();
    var hasHighResolution = isHighResolution();

    if(typeof disableLowResolution != "undefined") {
	    if (disableLowResolution) {
			hasHighResolution = true;
		}
    }
	
	return hasHighResolution;
}


function UBS_getContentImageWithWidth( maxWidth, minWidth) {
	var width = minWidth;
	if (checkHighResolution()) {
		width = maxWidth;
	}
	var content = "<img src=\"/mcs/cda/images/1px_trans.gif\" width=\"" + width + "\" height=\"1\" border=\"0\">";
	return content;
}

function UBS_getContentBodyImage( type )
{
	return "<img src=\"/mcs/cda/images/1px_trans.gif\" width=\""+UBS_getContentBodyWidth( type )+"\" height=\"1\" border=\"0\">";
}


function UBS_getContentTable( type )
{
	return "<table width=\""+UBS_getContentWidth( type )+"\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
}

function isHighResolution() {
	var isHighResolution = false;
	browserNm = getBrowserName();
	
	if (browserNm == "NN") {
	  var switchSizeBody = 1024;
	  var browserWidth = (document.all) ? document.body.clientWidth + 28 : window.outerWidth;
	} else {
	  var switchSizeBody = 1024;
	  var browserWidth = window.document.body.scrollWidth + 28;
	}
	
	if (browserWidth >= switchSizeBody)	{
		isHighResolution = true;		
	}
	
	return isHighResolution;
}
function KeyPress(e){
	if(e==13){
		findFAbyZip('afterHittingSearchByZipCodeSubmitButton');
	}
}
function findFAbyZip(type){
	var actTyp = type;
    var base = "/mcs/faSearch.do";	
    var zipcode = document.searchFinancialAdvisorFormBean.zipCodeForFASearchByLoc.value;
 	var action = base + "?actTyp="+actTyp+"&distanceSelectedForSearchByZipcode=50&zipCodeForFASearchByLoc=" + zipcode;
 	var errString = "";
 	
 	if(document.searchFinancialAdvisorFormBean.zipCodeForFASearchByLoc.value==null||document.searchFinancialAdvisorFormBean.zipCodeForFASearchByLoc.value==''){
    errString = "Please Enter the Zipcode";
    }

	if(errString.length!=0){
	alert(errString);
	}
	
	if(errString.length==0){
	//alert(action);
	document.searchFinancialAdvisorFormBean.action = action;	 
    // document.searchFinancialAdvisorFormBean.submit();
    document.location=action;
    
	}
}
// Alex Ridlovsky Aug. 09, 2007 Right Contentlet - search FA by Zip code
function validateZip(field) {

   var actTyp = "afterHittingSearchByZipCodeSubmitButton";
   var zipcode = searchFinancialAdvisorFormBean.zipCodeForFASearchByLoc.value;
   var url = "";
	
   if (field == "") {
	    alert("Please enter a zip code");
	    return false;
   } else {
	   document.searchFinancialAdvisorFormBean.action+="?actTyp="+actTyp;
 	   document.searchFinancialAdvisorFormBean.action += "&zipCodeForFASearchByLoc="+zipcode+"&aid=pws";
	   document.searchFinancialAdvisorFormBean.action += "&distanceSelectedForSearchByZipcode=25";
       //alert(document.searchFinancialAdvisorFormBean.action);  
	
 	   document.searchFinancialAdvisorFormBean.submit();  
  } 
}


