// Text size
// Include appropiate font definition file 

var IDsArray = new Array();

/*
this block is moved to getcookie.php page in this folder
if(getCookie("textsize") == 'medium') {
  // document.write('<link rel=stylesheet type="text/css" href="http://snowbirds.org/birdtalk/include/style2.css">'); 
document.write('<link rel=stylesheet type="text/css" href="http://snowbirds.org/jose/ScriptandStyles/style2.css">'); 
}else if(getCookie("textsize") == 'large') {
   //document.write('<link rel=stylesheet type="text/css" href="http://snowbirds.org/birdtalk/include/style3.css">'); 
document.write('<link rel=stylesheet type="text/css" href="http://snowbirds.org/jose/ScriptandStyles/style3.css">');
}else {
   //document.write('<link rel=stylesheet type="text/css" href="http://snowbirds.org/birdtalk/include/style1.css">'); 
document.write('<link rel=stylesheet type="text/css" href="http://snowbirds.org/jose/ScriptandStyles/style1.css">');
}
*/


/**
function setCookie(name, value, expires, path, domain, secure) {
  * name       Name of the cookie
  * value      Value of the cookie
  * [expires]  Expiration date of the cookie (default: end of current session)
  * [path]     Path where the cookie is valid (default: path of calling document)
  * [domain]   Domain where the cookie is valid
  *              (default: domain of calling document)
  * [secure]   Boolean value indicating if the cookie transmission requires a
  *              secure transmission
}
 */
function setCookie(name, value ,reloadParam) {


    var expires = new Date();
    var expDays = 30;
    expires.setTime(expires.getTime() + (expDays * 24 * 60 * 60 * 1000));
    var path = "/";
    var domain = "";
    var secure = "";

    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
 if(reloadParam == 1)
    window.location.reload(false);
}


function getCookie(name) {
   var dc = document.cookie;
   var prefix = name + "=";
   var begin = dc.indexOf("; " + prefix);
   if(begin == -1) {
      begin = dc.indexOf(prefix);
      if (begin != 0) return null;
   }else {
      begin += 2;
   }
   var end = document.cookie.indexOf(";", begin);
   if(end == -1) {
      end = dc.length;
   }
   return unescape(dc.substring(begin + prefix.length, end));
}


// Date function in the upper right corner
var daysOfWeek = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
//var daysOfWeek = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
var months=new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
//var months=new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec");
var today = new Date();
var date = "<b>today:</b> " + daysOfWeek[today.getUTCDay()] + ", " + months[today.getUTCMonth()] + " " + today.getUTCDate() + " &nbsp;";


// Email this page top of the page
function emailit(){
  var url=escape(window.location.href.toString());
  //window.open("http://snowbirds.org/cgi-bin/email/emailit.pl?url=" + url,"",'status=no,toolbar=no,location=no,scrollbars=no,resizable=yes,directories=no,menuBar=no,width=570,height=530');
window.open("https://www.snowbirds.org/popup_Emailfriend.php?url="+url,"",'status=no,toolbar=no,location=no,scrollbars=1,resizable=1,directories=no,menuBar=no,width=580,height=600');
}


//
// Left Navigaton Bar 
//
function LmOver(elem, clr) {
   elem.style.backgroundColor = clr;
  if(navigator.appName == "Microsoft Internet Explorer")
   elem.children.tags('A')[0].style.color = "#000000"; // Supported in IE only
   elem.style.cursor = 'hand'                          // Supported in IE only
}

function LmOut(elem, clr) {
   elem.style.backgroundColor = clr;
   if(navigator.appName == "Microsoft Internet Explorer")
   elem.children.tags('A')[0].style.color = "#000000";
}

function LmDown(elem, clr) {
   elem.style.backgroundColor = clr;
    if(navigator.appName == "Microsoft Internet Explorer")
   elem.children.tags('A')[0].style.color = "#FFFFFF";
}

function LmUp(path) {location.href = path;}


//Validation functions
function validate_frm_login(obj){

if(obj.txt_user_id.value==""){
alert('Member ID cannot be empty !');
obj.txt_user_id.focus();
return false;
}

if(obj.txt_user_pass.value==""){
alert('Password cannot be empty !');
obj.txt_user_pass.focus();
return false;
}

return true;
}

function validate_frm_Submitbt(obj){
if(obj.txt_fname.value==""){
alert('Name cannot be empty !');
obj.txt_fname.focus();
return false;
}

if(obj.sel_province.value==""){
alert('Province cannot be empty !');
obj.sel_province.focus();
return false;
}

// if(obj.txt_topic.value==""){
// alert('Topic cannot be empty !');
// obj.txt_topic.focus();
// return false;
// }

if(obj.txt_comment.value==""){
alert('Comment cannot be empty !');
obj.txt_comment.focus();
return false;
}

if(obj.txt_email.value==""){
alert('Email cannot be empty !');
obj.txt_email.focus();
return false;
}
return true;
}

function changeDisplayState (entryID) {
     // Show Entry
 // alert('p_'+entryID);

     idHtm=document.getElementById('p_'+entryID);
//alert('Entered 0');
//alert(eval('question' + entryID));
//alert(eval('answer' + entryID));
//var Qns_Var='question'+entryID;
//var Ans_Var='answer'+entryID;
//strval1='START  QN' + eval(Qns_Var) + ' END QN';
//strval2='START  ANS' + eval(Ans_Var) + ' END ANS';

//alert(strval1);
//alert(strval2);
//strval3=strval1+strval2;
//alert('Ctrl+ID : '+idHtm.id);
//alert('INNER HTML : '+ idHtm.innerHTML);
//idHtm.innerHTML = strval3;
   idHtm.innerHTML = eval('question' + entryID) + eval('answer' + entryID) + '<br><br>' ;
//idHtm.innerHTML = 'THIS IS MY TEST TEXT,just for checkingth eout put ';
//idHtm.innerHTML = eval('question' + entryID) + '<br><br>' ;
//idHtm.innerHTML =  eval('answer' + entryID) + '<br><br>' ;
//alert('Entered 1');
     // Hide the other entries
//alert(IDsArray.length);
   if(IDsArray.length > 1) {
        for(i=0; i<IDsArray.length; i++) {
          if(IDsArray[i] != entryID) {
             idHtm = document.getElementById('p_'+IDsArray[i]);
             idHtm.innerHTML = '&nbsp;';
          }
        }
     }
//alert('Entered 2');



//hide and display the teaser text on the listing page
objarr=document.getElementsByTagName('span');
 for(elementCnt=0;elementCnt< objarr.length; elementCnt++){

if(objarr[elementCnt].id == 'teaser'+entryID )
objarr[elementCnt].style.display="none";
else
objarr[elementCnt].style.display="block";
 //alert(objarr[elementCnt].id);
 }


//teaserObj=document.getElementById('teaser'+entryID);
//teaserObj.style.display="none";
//alert('teaser'+entryID);
   }

   function hideEntry (entryID) {
     idHtm=document.getElementById('p_'+entryID);
     idHtm.innerHTML = '&nbsp;';
teaserObj=document.getElementById('teaser'+entryID);
teaserObj.style.display="block";
   }

function currentDisplay() {
//function to open article  from email Links with anchors in that
var url_current = window.location.href;
if(url_current.indexOf('#') >= 0){
var id_current = url_current.substr(parseInt(url_current.indexOf('#'))+7,url_current.length);
//alert(id_current);
	if( id_current ) {
//		changeDisplayState(id_current);
	}
}
}




function validate_CurrentForm(frmObj){
/*Form object (frmObj) is passed to the function to validate its controlls the Id attribute of 
the form contolls should be in the format ==>>  id="fn__X__N__E__EC__First_Name"
 
Usage Example   : <input type=text id="fn__1__0__1__1__Confirm_Email" name=txtConfirmEmail >
This triggers the function like this -> The function will check whether the field
is not null,Checks the Email field and then checks the Confirm Email field

Explaining the ID parameters
ID = fn__X__N__E__EC__First_Name  [This is a sample, based on this the following is prepared]

fn  - identifies the ctrl
__  - seperator
X   - can be 0 or 1, it says the null validation is needed ,if 0 no null validation needed
N   - can be 0 or 1, it says the num validation is needed ,if 0 no num validation needed
E   - can be 0 or 1, it says the email validation is needed ,if 0 no email validation needed
EC  - can be 0 0r 1, it says asks for confirm email chk,if 0 no confirm email function is sneeded
First_Name - mandatory field display text for alert- this alerts 'First Name is mandatory'
*/
var arrCtrlsObj;
arrCtrlsObj=frmObj.elements;
var ctrlID;
for(i=0;i<arrCtrlsObj.length;i++){
ctrlID=arrCtrlsObj[i].id;
arrAttr=ctrlID.split("__");
/*
arrAttr[0]- id ,   
arrAttr[1]- (0/1) -should validate or not ,
arrAttr[2]- (0/1) num validate or not ,
arrAttr[3]- (0/1) email validate or not ,
arrAttr[4]- (0/1) confirm email chk ,
......
......
arrAttr[n]- err msg 
*/
msgIndex=arrAttr.length-1
arrMsg=arrAttr[msgIndex].split("_");
errMsg=arrMsg.join(' ');
	if(arrAttr[1]==1){

		ctrlValue=arrCtrlsObj[i].value;
		ctrlValue=ctrlValue.replace(/^\s*|\s*$/g,"");
		if( ctrlValue=="" ){
		arrCtrlsObj[i].value='';
		alert(errMsg+' is mandatory. ');
		arrCtrlsObj[i].focus();
		return false;
		}
	}

	if(arrAttr[2]==1){
      if(isNaN(arrCtrlsObj[i].value)==true){
      alert(errMsg+' must be numeric.');
      arrCtrlsObj[i].focus();
	  return false;
      }
	}

	if(arrAttr[3]==1){
      str=arrCtrlsObj[i].value;
		if(str.indexOf(".") > 2  && str.indexOf("@") > 0)
        str="";
        else{
        alert('Invalid Email. ');
		arrCtrlsObj[i].focus();
		return false;
		}
	}

	if(arrAttr[4]==1){
        prevIndex=i-1;
		if(arrCtrlsObj[i].value!=arrCtrlsObj[prevIndex].value){
		alert('Emails does not Match. ');
		arrCtrlsObj[i].focus();
		return false;
		}
	}

 

}

return true;
}