//
//   
//    Copyright     :   Confidential and Proprietary. 
//                      Copyright RISI, 2007
//                                      
//    File name     :   Community.js
//   
//    Description   :   Javascript used across community portal
//   
//    Author        :   Cognizant
//   
//    Date          :   Sep 25, 2007
//    
//    Modification History      
//   
//    Revision No.      Author              Date                Comments
//      
//   
//


//popup funtion to open adwebsites

function popup(pageurl){

	window.open(pageurl,"home");
}



//swap image store

function MM_swapImgRestore() { //v3.0

  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

}



//preload images
function MM_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

  var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

  if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

}




function MM_findObj(n, d) { //v4.01


  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

  d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function MM_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

  if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}

// Blog Archives - Checks if the the author name or date range is empty
// Modified by Cognizant offshore Team for blog archives date fix
function getArchives()
{

				if(document.blogselect.author.value.length > 0){
				
							    if(document.blogselect.month.value.length == 2){
											if(document.blogselect.year.value=="null"){
												alert("Please select the Year");
												return false;
											}
								}else if(document.blogselect.year.value != "null"){
											if(document.blogselect.month.value == "null"){
												alert("Please select the Month");
												return false;
											}
								}else if(document.blogselect.day.value.length == 2){
											if(document.blogselect.month.value == "null" || document.blogselect.year.value == "null"){
												if(document.blogselect.month.value == "null"){ 
												alert("Please select the Month");
												return false;
												}else if(document.blogselect.year.value == "null"){ 
												alert("Please select the Year");
												return false;
												}
											}
								}
				
				}else if(document.blogselect.author.value==""){
						if(document.blogselect.month.value=="null" && document.blogselect.year.value=="null"){
									if(document.blogselect.day.value.length == 2){
									alert("Please select the Month and Year");
									return false;
									}else{
									alert("Please select either the date/author");
									return false;
									}
						}else if(document.blogselect.month.value.length == 2){
									if(document.blogselect.year.value=="null"){
										alert("Please select the Year");
										return false;
									}
						}else if(document.blogselect.year.value != "null"){
									if(document.blogselect.month.value == "null"){
										alert("Please select the Month");
										return false;
									}
						}else if(document.blogselect.day.value.length == 2){
									if(document.blogselect.month.value == "null" || document.blogselect.year.value == "null"){
										if(document.blogselect.month.value == "null"){ 
										alert("Please select the Month");
										return false;
										}else if(document.blogselect.year.value == "null"){ 
										alert("Please select the Year");
										return false;
										}
									}
						}
					
				}
	
	
	return true;
}
// Modified by Cognizant offshore Team for blog archives date fix


//Blog Archives - Submit
function blogFormSubmit()
	{
	document.blogselect.blogArchives.value="blogArchives";
	document.blogselect.pageid.value="";
	document.blogselect.author.value=document.blogselect.author.value;
	document.blogselect.month.value=document.blogselect.month.value;
	document.blogselect.year.value=document.blogselect.year.value;
	document.blogselect.day.value=document.blogselect.day.value;
	document.blogselect.action="/blogs";
	document.blogselect.submit();
}

// Blog Details - Email article
function gettitle()
{	
	document.blogarticle.emailstoryid.value=document.blogarticle.emailstoryid.value;
	document.blogarticle.blogtitle.value=document.blogarticle.blogtitle.value;
	document.blogarticle.firstpara.value=document.blogarticle.firstpara.value;
	document.blogarticle.comurl.value=document.blogarticle.comurl.value;
	document.blogarticle.blogauthor.value=document.blogarticle.blogauthor.value;
	document.blogarticle.pageid.value="articleDetails";
	document.blogarticle.action="/email.html";
	document.blogarticle.submit();
}

//Blog Details - Print Article
function articlePrint()
{
	var sId=document.blogarticle.comurl.value;
	PageURL="/pages/printForm.jsp?stremailstoryid="+sId;
	settings="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=600,height=300";
	WindowName="MyPopUpWindow";
	window.open(PageURL,WindowName,settings);
}

//Blog Email  - Validates Email
function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
			if(elem.value.match(emailExp)){
			return true;
			}
			else{
				alert(helperMsg);
				elem.focus();
				return false;
				}
}

//Blog Email  - Validates empty content
function isEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

//Blog Email  - Email form Submit
function blogEmailSubmit(){
		document.blogemailsend.sessionId.value=document.blogemailsend.sessionId.value;
		if(isEmpty(document.blogemailsend.fromemail,"Please enter an Email Address in Source column")){
			if(emailValidator(document.blogemailsend.fromemail,"Please enter a valid Email Address in Source column")){
				if(isEmpty(document.blogemailsend.toemail,"Please enter an Email Address in Destination column")){
					if(emailValidator(document.blogemailsend.toemail,"Please enter a valid Email Address Destination column")){
					       
						if(isEmpty(document.blogemailsend.jcaptcha,"Please enter the word as it is shown in the box")){
						return true;
						}
					}
				}
			}
		}
		return false;
}


