




/* --------------------------------------------- */
/*  Global Symphony Website Javascript           */
/* --------------------------------------------- */


/* ---------------------------------------------------------- */
/*  For footer setting	          			                  */
/* ---------------------------------------------------------- */

function setFooter(){
	var windowHeight = 0;
			if (typeof(window.innerHeight) == 'number') {
				windowHeight = window.innerHeight;
			}
			else {
				if (document.documentElement && document.documentElement.clientHeight) {
					windowHeight = document.documentElement.clientHeight;
				}
				else {
					if (document.body && document.body.clientHeight) {
						windowHeight = document.body.clientHeight;
					}
				}
			}
	if(document.body.clientHeight<windowHeight){
		document.getElementById("bottom").style.height=windowHeight +"px";
	}
}

/* ---------------------------------------------------------- */
/*  Open demo 			          			                  */
/* ---------------------------------------------------------- */

function opendemo(i) {
           
           var open_url = "";
	   if(i==1)open_url="swf/we/DocumentFilePref/DocumentFilePref_viewlet_swf.html";
	   else if(i==2)open_url="swf/we/DocumentsFrame/DocumentsFrame_viewlet_swf.html";
	   else if(i==3)open_url="swf/pe/prezOverview/prezOverview_viewlet_swf.html";
	   else if(i==4)open_url="swf/pe/prezFilePref/prezFilePref_viewlet_swf.html";
	   else if(i==10)open_url="swf/pe/changeLayout/changeLayout_viewlet_swf.html";
	   else if(i==5)open_url="swf/se/spreadshFilePref/spreadshFilePref_viewlet_swf.html";
	   else if(i==0)open_url="swf/se/speadsheetNavigator/speadsheetNavigator_viewlet_swf.html";
	   else if(i==9)open_url="swf/we/tableofcontents/tableofcontents_viewlet_swf.html";
	   else if(i==6)open_url="tutorial/we/start_documents.htm";
	   else if(i==7)open_url="tutorial/pe/start_presentations.htm";
	   else if(i==8)open_url="tutorial/se/start_spreadsheets.htm";
	   
	   window.open(open_url,'','status=0,directories=0,resizable=0,toolbar=0,location=0,scrollbars=0');
	  

}
function opendemo_new(URL){
       open_url=URL;
       window.open(open_url,'','status=0,directories=0,resizable=0,toolbar=0,location=0,scrollbars=0');
}


function closewindow(){   
    window.close();
}
var cancelPost= false;

function checkTags()
{
    if (cancelPost) {
        return true;
    }
    var hasError = false;
    var tags = document.getElementById('tags-0');
    if (typeof(tags) != "undefined" && trimString(tags.value) == '') {

        var t = document.getElementById('post-error-table');
        if (t) {
            t.style.display = "block";
            t = document.getElementById('post-error-tags');
            if (t) {
                t.style.display = "block";
            }
        }
        hasError = true;
    }
    else {
        var t = document.getElementById('post-error-tags');
        if (t) {
            t.style.display = "none";
        }
    }
    //plugin title empty validation
    var sub = document.getElementById('subject01');
    if (typeof(sub) != "undefined" && trimString(sub.value) == '') {

        var t = document.getElementById('post-error-table');
        if (t) {
            t.style.display = "block";
            t = document.getElementById('post-error-subject');
            if (t) {
                t.style.display = "block";
            }
        }
        hasError = true;
    }
    else {
        var t = document.getElementById('post-error-subject');
        if (t) {
            t.style.display = "none";
        }
    }
    //description large validation
    var body = document.getElementById('textEditor');
    if (typeof(body) != "undefined" && body.value.length == '') {

        var t = document.getElementById('post-error-table');
        if (t) {
            t.style.display = "block";
            t = document.getElementById('post-error-body');
            if (t) {
                t.style.display = "block";
            }
        }
        hasError = true;
    }
    else {
        var t = document.getElementById('post-error-body');
        if (t) {
            t.style.display = "none";
        }
    }
    if (hasError) {
      return false;
    }
    var t = document.getElementById('post-error-table');
    if (t) {
      t.style.display = "none";
    }


    return true;        
}
function checkValid()
{
 var a = document.postform.body;
 
 if(a.value.length > 10000)
 {
  alert("The maximal length of message is 10000!");
  return false;
 }
 return true;
}

/* ---------------------------------------------------------- */
/*  Inviete a friend	          			                  */
/* ---------------------------------------------------------- */

function previewPopUp(mailBody){
	var previewWin = window.open('','Preview','height=640,width=685,status=0,directories=0,resizable=0,toolbar=0,location=0,scrollbars=yes');
	
	if (mailBody==null || mailBody=="undefined"){
		mailBody="";
	}
	
	if (previewWin!=null && previewWin!="undefined"){
		var pageCode="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"> <html> <head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> <meta name=\"Description\" content=\"Preview the invitation before you send it\"/> <title><$title$></title> <style> a{text-decoration:none;color: #038beb;} a:hover{text-decoration:underline;color: #038beb;} </style> </head> <body> <h1 style=\"font: normal  1.5em Helvetica, Arial, Verdana, sans-serif;color:#58595B;margin-bottom:0px;\">Preview the Invitation</h1> <p style=\"font: normal 0.75em Helvetica, Arial, Verdana, sans-serif;color:#58595B;margin-bottom:30px;\">This is an example of the e-mail that will be sent. A separate e-mail will be sent for each e-mail address that you provide.</p> <table width=\"640\" style=\"border: 1px solid #000;font-size:0.625em;\"> <tr> <td> <$mailBody$> </td> </tr> </table> <p style=\"margin-top:20px;font: normal 0.75em Helvetica, Arial, Verdana, sans-serif;\"> <a href=\"#\" onclick=\"window.close();\">Close</a> </p> </body> </html>";
		pageCode = pageCode.replace("<$title$>","IBM Lotus Symphony - Invite a Friend: Preview the Invitation");
		pageCode = pageCode.replace("<$mailBody$>",mailBody);
		previewWin.document.writeln(pageCode);
		previewWin.document.close();
		previewWin.focus();
	}
}

function getNameFromRecipient(recipient){
	var name = "";
	if (recipient!=null && recipient!="undefined"){
		var index1 = -1;
		index1 = recipient.indexOf(",");
		if( index1 == -1)
			index1 = recipient.indexOf("\n");
		if( index1 == -1)
			index1 = recipient.indexOf("\r");
		var index2 = recipient.indexOf("<");
		if( index2!= -1)
		{
			if(index1 == -1 || ( (index2 < index1) && (index1!=-1) ))
			{
				var name =trim(recipient.substring(0,index2-1));
			}
		}
	}
	
	return name;
}

function composeMailBody(HTMLorText,recipientName,senderName,themeMsg,greeting,marketingMsg,imgURL){
	var mailBody="";
	//alert(HTMLorText);
	if (HTMLorText=="HTML"){
		mailBody+="<table cellpadding=\"12\" cellspacing=\"0\" width=\"640\" style=\"font-size:1em;\">  <tr valign=\"top\">     <td  background=\"<$jiveurl$>theme/images/background.gif\" bgcolor=\"#FFFFFF\"><font style=\"font-family:Helvetica, Arial, sans-serif; font-size:1.4em; font-weight:normal; color:#666666\">             <img alt=\"\" src=\"<$jiveurl$><$banner_left$>\">                                <p><$recipient$></p>				<p><$themeMsg$></p>				<p><strong>Download</strong> your copy of Lotus Symphony at <a href=\"http://symphony.lotus.com\" target=\"_blank\">http://symphony.lotus.com</a></p>				<p>This greeting was sent to you by <strong><$sender$></strong><$followSender$></p>                                <p><$greeting$></p>				</font>		</td>	</tr>	<tr>		<td><font style=\"font-family:Helvetica, Arial, sans-serif; font-size:1.2em; font-weight:normal; color:#666666\">				<p><$marketingMsg$>				</p>				</font>		  <font style=\"font-family:Helvetica, Arial, sans-serif; font-size:1.2em; font-weight:normal; color:#666666\">				<p>Need more reasons to try Lotus Symphony? See  <a target=\"_blank\"  href=\"http://www.youtube.com/watch?v=E4ZhPI1eic4\">Lotus Symphony on YouTube</a>.				</p>				</font></td></tr>	<tr>		<td ><img alt=\"Lotus Symphony\" src=\"<$jiveurl$>theme/images/IBMLotusSymphony.gif\">		</td>	</tr></table>";
	}else{
		mailBody+="<p><font style=\"font-family:Helvetica, Arial, sans-serif; font-size:1.2em; font-weight:normal; color:#000\"> <$recipient$><br /><$themeMsg$><br /><br />Download your copy of Lotus Symphony at <a href=\"http://symphony.lotus.com\" target=\"_blank\">http://symphony.lotus.com</a><br /><br />This greeting was sent to you by <strong><$sender$></strong><$followSender$><br /><$greeting$><br />For people who are seeking alternatives to proprietary office productivity software, IBM(R)&nbsp; Lotus(R)&nbsp;Symphony(tm) &nbsp; is a suite of applications for creating, editing, and sharing documents, spreadsheets, and presentations. Unlike other productivity suites, Lotus Symphony supports open standards, is easy to acquire and use, is available at no charge, and is supported by a web-based worldwide community. <br /><br />Need more reasons to try Lotus Symphony? See <a target=\"_blank\" href=\"http://www.youtube.com/watch?v=E4ZhPI1eic4\">Lotus Symphony on YouTube</a>.</font></p>";
	}
	
	if (recipientName!=null && recipientName!="undefined" && recipientName!="")
		mailBody=mailBody.replace("<$recipient$>",recipientName+",<br />");
	else
	 	mailBody=mailBody.replace("<$recipient$>","");
	 	
	 if(imgURL!=null && imgURL!="undefined" && trim(imgURL)!="")
	 	 mailBody=mailBody.replace("<$banner_left$>",imgURL);
	 else
	 	 mailBody=mailBody.replace("<$banner_left$>","");
	
	if (themeMsg==null || themeMsg=="undefined")
		themeMsg="";
	mailBody=mailBody.replace("<$themeMsg$>",themeMsg);
	
	if (senderName==null || senderName=="undefined")
		senderName="";
	mailBody=mailBody.replace("<$sender$>",senderName);
	
	if (marketingMsg==null || marketingMsg=="undefined")
		marketingMsg="";	
	mailBody=mailBody.replace("<$marketingMsg$>",marketingMsg);	
	
	if (greeting==null || greeting=="undefined")
		greeting="";	
	greeting=escapeHTML(greeting);
	
	if (trim(greeting)!="" ){
		mailBody=mailBody.replace("<$followSender$>",", who also wants you to know:");
		mailBody=mailBody.replace("<$greeting$>",greeting+"<br />");
	} else{
	    mailBody=mailBody.replace("<$followSender$>",".");
	    mailBody=mailBody.replace("<$greeting$>","");
	}
	mailBody=mailBody.replace(/<\$jiveurl\$>/g,"");
	
	return mailBody;
}

/* ---------------------------------------------------------- */
/*  Utility  			        			                  */
/* ---------------------------------------------------------- */

function getRadioValue(radiogroup){
   if (radiogroup!=null && radiogroup!="undefined"){
   		var numradios = radiogroup.length;

		for (var i = 0; i < numradios; i++)
	      	if (radiogroup[i].checked)
	      	  return radiogroup[i].value;
	         //	alert('radio '+i+' with value of '+radiogroup[i].value);
   }
}

function trim(stringToTrim) {
    if (stringToTrim!=null && stringToTrim!="undefined" && (typeof stringToTrim)=="string" )
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	return "";
}

function escapeHTML(text){
	if (text!=null && text!="undefined"){
		text=text.replace(/</g,"&lt;");
		text=text.replace(/>/g,"&gt;");	
	}
	
	return text;
}

function checkLength(strTarget,length,prompt){
	if (strTarget!=null){
		if(strTarget.length > length){
		  alert("The maximal length of "+prompt+" is "+ length +"!");
		  return false;
		 }
	}
	return true;
}

function checkEmpty(strTarget,isPrompt){
	if (strTarget!=null){
		if(trim(strTarget).length == 0 ){
			if (isPrompt){
			  alert("You can't leave this field blank!");
		  	}
		  	return false;
		 }
		 return true;
	}
	return false;
}

function addSpamToURL(oldURL){
	var spam = "buzz";
	var reg = /.+\?\w+=\S*/;
	var newURL="";
	if(oldURL!=null && oldURL!="undefined" ){
		if(oldURL.match(reg)){
			newURL=oldURL+"&chk="+spam;
		} else {
			newURL=oldURL+"?chk="+spam;
		}
	}
	
	return newURL;
}

function textCounter(field,maxlimit) { 
	if (field!=null && field.value.length > maxlimit) 
 		field.value = field.value.substring(0, maxlimit); 
} 

function symphonyStyleTag(tag, ta) { 
    var end = 0;
    var scrollTop = ta.scrollTop;
    
    if (document.selection) {
        if (document.selection.createRange().parentElement().tagName == 'TEXTAREA') {
            var selected = document.selection.createRange().text;
            
            // now determine the cursor position
            end = getSelectionRangeEnd(ta);
            
            // r is an array
            var r = _markupText(selected, tag); 
            // update text
            document.selection.createRange().text = r[0];            
            // update end position
            end += r[1];
        } 
        else
        {
	        ta.value= ta.value + tag + tag;
	        return;
        }
    } 
    else if (typeof(ta.selectionStart) != 'undefined' && typeof(ta.selectionEnd) != 'undefined') {
        if (ta.selectionStart == ta.selectionEnd) {
        	ta.value= ta.value + tag + tag;
            return;
        }
        var selLength = ta.textLength;
        var selStart = ta.selectionStart;
        var selEnd = ta.selectionEnd;
        if (selEnd == 1 || selEnd == 2) {
            selEnd = selLength;
        }
        var s1 = (ta.value).substring(0, selStart);
        var s2 = (ta.value).substring(selStart, selEnd);
        var s3 = (ta.value).substring(selEnd, selLength);
        
        // r is an array
        var r = _markupText(s2, tag); 
        // update text
        ta.value = s1 + r[0] + s3;            
        // update end position
        end = selEnd + r[1];
    } 
    else {
        return;
    }
    
    if (end > 0) { 
        setCaretTo(ta, end, scrollTop); 
    }
}