// This file includes common javascript functions

	var total = 0;
	var zipSum = 0;
	var zipRatio = 0;
	
	// Calculates estimated zip-file size for InvestorsKit zip-file.
	function estimateSize(box,size,ext) {

		fileExt = ext.toLowerCase();
		
		switch(fileExt){
		case "pdf" :
		zipRatio =0.70;
		break;
		case "ppt" :
		zipRatio =0.80;
		break;
		case "txt" :
		zipRatio =0.20;
		break;
		case "doc" :
		zipRatio =0.40;
		break;
		case "xsl" :
		zipRatio =0.30;
		break;
		case "jpeg" :
		zipRatio =0.40;
		break;
		default :
		zipRatio =0.5;
		}
		zipSize=size*zipRatio;
		size=size*1.0;

		for (i=0;i<document.OilDocFrm.elements.length;i++) {
			if (document.OilDocFrm.elements[i] == box) {
				if (document.OilDocFrm.elements[i].checked) {
				total += size;
				zipSum += zipSize;
			    document.OilDocFrm.totalSize.value = Math.round(total/1024);
				document.OilDocFrm.zippedSize.value = Math.round(zipSum/1024);
				} 
				else {
					if (total > 0) {
					    
						total -= size;
						zipSum -= zipSize;
			    		document.OilDocFrm.totalSize.value = Math.round(total/1024);
						document.OilDocFrm.zippedSize.value = Math.round(zipSum/1024);
					}
				}
				break;
			}
			
		}
	}

	//Checks the send this page to friend form.
	function CheckSendPageForm(strInfo) {
		
		if (document.email.ReceiverEmail.value.length == 0) {
			alert(strInfo);
			return false;
		}
		
		if (document.email.Sender.value.length == 0) {
			alert(strInfo);
			return false;
		}
		
		if (document.email.Subject.value.length == 0) {
			document.email.Subject.value = document.email.PageURL.value;
		}

		return true;
	}



	//Checks the feedback form.
	function CheckFeedbackForm(strInfo) {
		
		if (document.feedback.Subject.value.length == 0) {
			alert(strInfo);
			return false;
		}
		
		if (document.feedback.Message.value.length == 0) {
			alert(strInfo);
			return false;
		}
		
		if (document.feedback.captchacode.value.length == 0) {
			alert(strInfo);
			return false;
		}

		return true;
	}
	

	// Function to open the given url. It also checks if the url has to be opened in a new window.
	function DropDownFunction(select) {
		// The select options are formed like http://www.mylink.com''windowProperties or like http://www.mylink.com
		var strSelection = select.options[select.options.selectedIndex].value;
		var arr;
		var tmpSel;
		var arr2;
		var arr3;
		var dDomainName;
		var dPath;
		var dSelectionName = select.options[select.options.selectedIndex].text;
		
		if (strSelection.length > 0) {
			//alert(strSelection);
			arr = strSelection.split("''");
			//alert(arr.length);
			if (arr.length < 2) {
				window.location.href = strSelection;
			}
			else {
				//alert(arr[0] + ',null,' + arr[1]);
				window.open(arr[0],null,arr[1]);
				tmpSel=arr[0];
				arr2 = tmpSel.split("://");
				if (arr2.length > 1)
				{
					arr3 = arr2[1].split("/");
					if (arr3.length > 1)
					{
						dPath = "/" + arr3[1];
					}
					else
					{	
						dPath = "/";
					}
					dDomainName = arr3[0];
				}
				else
				{
					dDomainName = "";
					dPath = "/";
				}
				//alert(dSelectionName);
				//alert("domain: " + dDomainName + "   path: " + dPath);
				
				dcsMultiTrack('DCS.dcssip',dDomainName,'DCS.dcsuri',dPath,'WT.ti','Offsite: ' + dSelectionName);
			}
		}
	}
	
	// Function to create cookie for PopUp, so that PopUp won't be shown twice
	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=/";
	}
 
	// Read PopUp cookie
	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;
 
	}
    
    // Refresh CAPTCHA image
    function RefreshImage(valImageId)
    {
	    var objImage = document.images[valImageId];
	    if (objImage == undefined)
	    {
	        return;
	    }
	    var now = new Date();
	    objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
    }
    
	// Open PopUp if cookie isn't found
	function openPopup(lang){
		if(readCookie('satisfactionSurvey')==null){
			if(lang=='fi'){
				var newWindow= window.open('http://www.webropol.com/P.aspx?id=61813&cid=7924083',null, 'height=480,width=780,resizable=yes,status=yes,toolbar=no,menubar=no,location=no, scrollbars=yes');
				if(newWindow){
					createCookie('satisfactionSurvey','satisfactionSurvey',7);
				}	
			}  
			if(lang=='en'){				
				var newWindow= window.open('http://www.webropol.com/P.aspx?id=61815&cid=7780893',null, 'height=480,width=780,resizable=yes,status=yes,toolbar=no,menubar=no,location=no, scrollbars=yes');  
				if(newWindow){
					createCookie('satisfactionSurvey','satisfactionSurvey',7);
				}
			}
		}
	}


