/*
 * This function changes the font-size of the current page by adjusting the style.
 * element(dhtml element) with an id attribute
 * The id of the given element should be set to either 'small', 'medium', or 'large'
 */
function selectFontSize(element) {
	if (element) {
		switch(element.id) {
			case 'small':
				if (document.body.style) document.body.style.fontSize = 'x-small';
				break;
			case 'medium':
				if (document.body.style) document.body.style.fontSize = 'small';
				break;
			case 'large':
				if (document.body.style) document.body.style.fontSize = 'medium';
				break;
		}
	}
	
	return false;
}

/*
 * Toggels the display of the survey form
 */
function toggleSurvey() {
	var survey = document.getElementById('surveyCover');
	survey.style.height = document.body.scrollHeight + 'px';
	survey.style.display = survey.style.display == 'block' ? 'none' : 'block';
	
	var surveyContent = document.getElementById('surveyContent');
	surveyContent.style.top = (document.body.clientHeight - surveyContent.clientHeight) / 2 + 'px';
	surveyContent.style.left = (document.body.clientWidth - surveyContent.clientWidth) / 2 + 'px';
  
  return false;
}

/*
 * Sets the page tool tip field
 */
function setPageToolTip(el) {
	var pageToolTip = document.getElementById("pageToolTip");
	if (!el)
		pageToolTip.style.display = 'none';
	else {
		pageToolTip.innerText = el.innerText;
		pageToolTip.style.display = '';
	}
}

/*
 * Toggles the display of the contact form
 */
var contactSliding = false;
var oldtype = '';
var contactStausOn = false;
var oldTitle = "";
function toggleContactForm(type) {
	
	contactCurrent=1;
	
	document.getElementById("dinamic_survey").innerHTML="";
	
	if (contactSliding)
		return false;
	contactSliding = true;
	
	var pageToolChoice = document.getElementById(type);
	var pageToolOther; 
	var pageToolOther2;
	
	var isSafari = navigator.userAgent.toLowerCase().indexOf('safari') != -1;
	//var isSafari = false;
	
	var duration = isSafari ? 0.0 : 0.4;
	var newHeight = document.body.offsetHeight;
	if (newHeight<(document.getElementById('content').offsetHeight + 230)) newHeight = document.getElementById('content').offsetHeight + 230;
	document.getElementById('contentCover').style.height = newHeight + 'px';
	
	setHidden("countrySelector");
	setHidden("onlineBankingSelector");
	
	if ((oldtype==type) || (oldtype=='')) {
	
		if (document.getElementById('surveyContactCover').style.display == 'block')
		{
			document.getElementById('surveyContactCover').style.display = 'none';
			document.title = oldTitle;
		}	
		else
		{
			setTimeout("document.getElementById('surveyContactCover').style.display = 'block';", duration * 1000);
			oldTitle = document.title;
		}
		setTimeout("contactSliding = false;", duration * 1000);
	
		if (document.getElementById('contentCover').style.display == 'block')
			document.getElementById('contentCover').style.display = 'none';
		else
			setTimeout("document.getElementById('contentCover').style.display = 'block';", duration * 1000);
			
		if (contactStausOn == false) 
			contactStausOn = true;
		else
			contactStausOn = false;
	
	}else{
		
		if (contactStausOn == false) {
		
				if (document.getElementById('surveyContactCover').style.display == 'block')
					document.getElementById('surveyContactCover').style.display = 'none';
				else
					setTimeout("document.getElementById('surveyContactCover').style.display = 'block';", duration * 1000);
					
				setTimeout("contactSliding = false;", duration * 1000);
			
				if (document.getElementById('contentCover').style.display == 'block')
					document.getElementById('contentCover').style.display = 'none';
				else
					setTimeout("document.getElementById('contentCover').style.display = 'block';", duration * 1000);
					
				if (contactStausOn == false) 
					contactStausOn = true;
				else
					contactStausOn = false;
					
		}else{
		
			document.getElementById('surveyContactCover').style.display = 'none';
			setTimeout("document.getElementById('surveyContactCover').style.display = 'block';", duration * 500);
					
			contactSliding = false;
		}
					
	}
	
	if (document.getElementById('surveyContactCover').style.display == 'none') {
		var myPage=hashpage();
		if (myPage.indexOf("/")==-1) {
			changeMetaData('WT.si_n','ContactForm'); 
			changeMetaData('WT.si_p','HomePage');
		}else{
			changeMetaData('WT.si_n',''); 
			changeMetaData('WT.si_p','');
		}
	}
	
	oldtype=type;
	
	return false;
}

/*
 * Sets the contact window to the next page
 */
function contactNext() {
	contactCurrent++;
	return showContactPage();
}

/*
 * Sets the contact window to the previous page
 */
function contactPrev() {
	contactCurrent--;
	return showContactPage();
}

/*
 * Show the current contact window page en sets the appropriate elements
 */
function showContactPage() {
	document.getElementById('contactProgressCount').innerHTML = contactCurrent+'/'+contactMax;

	var contactProgressNav = document.getElementById('contactProgressNav');
	contactProgressNav.innerHTML = '';
	if (contactCurrent > 1)
		contactProgressNav.innerHTML += '< <a href="#" onclick="return contactPrev();">Previous</a>'
	if (contactCurrent > 1 && contactCurrent < contactMax)
		contactProgressNav.innerHTML += ' | ';
	if (contactCurrent < contactMax)
		contactProgressNav.innerHTML += '<a href="#" onclick="return contactNext();">Next</a> >';
	
	document.getElementById('contactPage'+contactLast).style.display = 'none';
	document.getElementById('contactPage'+contactCurrent).style.display = '';
	
	document.getElementById('contactStep'+contactLast).className = '';
	document.getElementById('contactStep'+contactCurrent).className = 'currentStep';
	
	contactLast = contactCurrent;
	
	return false;
}

function displayHeader(image, xstart, ystart, l1, l2, l3, l4) {
  document.writeln('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="650" height="300" id="popup_header" align="middle">');
  document.writeln('<param name="allowScriptAccess" value="sameDomain" />');
  document.writeln('<param name="movie" value="?image='+image+'&xstart='+xstart+'&ystart='+ystart+'&l1='+l1+'&l2='+l2+'&l3='+l3+'&l4='+l4+'" /><param name="quality" value="high" /><param name="bgcolor" value="#b4b48d" /><embed src="?image='+image+'&xstart='+xstart+'&ystart='+ystart+'&l1='+l1+'&l2='+l2+'&l3='+l3+'&l4='+l4+'" quality="high" bgcolor="#b4b48d" width="650" height="300" name="popup_header" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
  document.writeln('</object>');
}

function setuploadImage(){
	document.newsform.uploadImage.value="yes";
}

function setPoolImage(imageUrl){
	document.newsform.pictureDB.value=imageUrl;
}

function loopSelected(selId) {
  var selObj = document.getElementById(selId);
  var selectValue = "";
  for (var i=0; i<selObj.options.length; i++) {
    if (selObj.options[i].selected) {
      selectValue += selObj.options[i].value+",";
    }
  }
  selectValue = selectValue.substring(0,(selectValue.length-1));
  return selectValue;
}

function setHidden(divId) {
	var actionbox = document.getElementById(divId);
	if (actionbox) {
		if (actionbox.style.display == 'none')
			actionbox.style.display = 'block';
		else
			actionbox.style.display = 'none';
	}
}

function setOpacity(divId) {
	var actionbox = document.getElementById(divId);
	if (actionbox) {
		if (actionbox.style.opacity == 0.7)
			actionbox.style.opacity = 1;
		else
			actionbox.style.opacity = 0.7;
	}
}

function fnCheckSession()
	{
		var currloc = document.location.href;
		
		var callFunc = false;
		if ( currloc.length > 0 )
		{
			var split = currloc.split("#");
			var ajaxSplit;
			
			if (split.length > 1)
			{
				ajaxSplit = split[1].split("/");
				if (ajaxSplit.length <= 1)
					{
						callFunc = true;
					}	
			}	
			else
			{
				
				var chkSplit=split[0];
				var chkLen=chkSplit.length;
				
				var chkslash=chkSplit.substr(chkLen-1);
			
				
				if ( chkslash == "/")
				{
					
					chkSplit = chkSplit.substr(0,chkLen-1)
				}	
				
				
				var normalSplit = chkSplit.split("/");
				var len = normalSplit.length;
				
				
				
				
				if (len > 0) 
				{
					if ( (normalSplit[len-1].toLowerCase() == "switzerland") || (normalSplit[len-1].toLowerCase() == "switzerland.htm") || (normalSplit[len-1].toLowerCase() == "switzerland.html") )
					{
						callFunc = true;
					}
				}
			}
		}		
	
		var chkAccess=createCookie(); 

		if (callFunc && chkAccess )
			setTimeout("getContent(\'ch-contact-tool-popup?step=1&contact=mail&client=1&subject=Expert advice on portfolio structure&popup=yes&generation=\',\'dinamic_survey\',\'ajax\'); toggleContactForm(\'pagetoolEmail\')",1);
	}
	
	
	function createCookie() 
	{
		var name="userattempt"
		var PgAccessCount=readCookie() ;
		
		
		
		PgAccessCount=parseInt(PgAccessCount);
		
		var chkusrAccess=false;
		if (PgAccessCount <= 5)
		{
			chkusrAccess=true;
		
		}
		
		document.cookie = name+"="+PgAccessCount+"; path=/";
		return chkusrAccess;
	}

	function readCookie() 
	{
		
		var varListCookie = document.cookie.split(';');
		var cookieLength=varListCookie.length;
		var value;
		var chkAttempt=false;
		for(var i=0;i < cookieLength;i++) 
		{
			
			var cookieName = varListCookie[i];
			
			if(cookieName.indexOf("userattempt") >=0)
			{
				
				chkAttempt=true
				var a=cookieName.split('=');
				var val1=a[1];
				value= parseInt(val1) + 1;
				
			}
		
		}
		if(chkAttempt)
		{
			value=value
			
		}else
		{
			value=1
		}
			
		
		return value;
	}
	

function Home_onClick(urlid,Hght,Wdth)
 {
 Hght = parseInt(Hght);
 Wdth = parseInt(Wdth);
 Wdth = Wdth + 4;
 Hght = Hght + 12;
 url = "video_window?varid=" + urlid;
 param = "toolbar=0,scrollbars=0,location=0,top=1,left=1,statusbar=0,menubar=0,resizable=1,width=" + Wdth + " , height=" + Hght ;
 window.open(url,"test",param);
 }
 
function ext_onClick(urlid,Hght,Wdth)

{
Hght = parseInt(Hght);
 Wdth = parseInt(Wdth);
 Wdth = Wdth + 4;
 Hght = Hght + 12;

 url = "video_ext_window?varid=" + urlid;

 name1= "Video";
 param = "toolbar=0,scrollbars=0,location=0,top=1,left=1,statusbar=0,menubar=0,resizable=1,width=" + Wdth + " , height=" + Hght ;

 window.open(url,"test",param);

}
	
function test1()
{

	var selectValue = loopSelected('selCountry');
	if(document.newsform.newsTitle.value == '')
	{
		alert('Please enter the title');
	} 
	else if(selectValue == '') 
	{
		alert('Please select the country');
	} 
	else 
	{ 
		setuploadImage(); 
		loadPageElementsILink(mycurrentLocation +"/" + 'admin-news?createnews='+document.newsform.createnews.value+'&newsTitle='+escape(document.newsform.newsTitle.value)+'&newsAbstract='+escape(document.newsform.newsAbstract.value)+'&Country='+selectValue+'&newsUrl='+document.newsform.newsUrl.value+'&uploadImage='+document.newsform.uploadImage.value+'&pictureDB='+document.newsform.pictureDB.value,'Admin News'); 
		this.disabled=true; 
	}  
	return false;

}


function fnOfficeOpenWindow(strvalue)
{

	
	
	window.open(strvalue,'officelocator', 'width=770, height=859');

}

		