function setAddressText( text ) {
	addr = document.getElementById( "address" );
	addr.setAttribute( "value", text );
}
function closeAndRefreshParent() {
	window.opener.location=window.opener.location;
	window.close();
}
function enablePasscode()
{
    var l_checked = document.getElementById('accessrightsid').checked;
	if( l_checked == true ) {
	document.getElementById('passcodeid').style.display='block';
	} else {
	document.getElementById('passcodeid').style.display='none';
	}
}
function checkForAllowedPasscodeChars(){
	var l_passcode = document.getElementById('accesscode_id').value;
	var l_checked = document.getElementById('accessrightsid').checked;
	invalidChars = '!@#$%^&*()_-+=}]{[:;"\'?/>.<,~`';
	if( l_checked == true ) {
		if( l_passcode.length == 0 ) {
			alert( "Please enter a valid passcode and try again!" );
			return false;
		}
		for (i = 0; i < invalidChars.length; i++) { 
		    if (l_passcode.indexOf(invalidChars.charAt(i)) > -1) { 
			  alert( "Only English Alphabets and numbers are allowed in the passcode. Please try again!" );
		      return false; 
		    } 
		} 
		return true; 
	}
}

function enableEmailField() {
    elem = document.getElementById( "inv_email_id" );
    elem.disabled = false;
    clelem = document.getElementById( "changelink" );
    clelem.setAttribute( "style", "display:none" );
    helem = document.getElementById( "inv_email_hid" );
    helem.disabled = true;
}


function enlistFriends() {
    rate_loading_objects(); 
    var select = document.getElementById( "groupid" );
    l_id = select.options[select.selectedIndex].value;
    var ajax = new Ajax.Updater('', '../ajax/ddrtrvr.php?grpids=' + l_id,{method:'get',asynchronous:true,onComplete: displayGroupMembers });
    rate_unloading_objects();
}

function displayGroupMembers( req ) {
    var l_names = req.responseText;
    names = l_names.split( "_____" );
    l_frndselem = document.getElementById( 'frndsdetid' );    
    while( l_frndselem.hasChildNodes() ) { 
    	l_frndselem.removeChild( l_frndselem.lastChild ); 
    }
    for( i = 0; i < names.length; i++ ) {
    	divelem = document.createElement( "div" );
    	divelem.id = "div_" + (i + 1);
    	divelem.innerHTML = names[i];
    	l_frndselem.appendChild( divelem );
    	
    }
}


function rate_loading_objects() {
    document.getElementById('loading-objects' ).style.display = 'inline';	
}
function rate_unloading_objects() {
	document.getElementById('loading-objects' ).style.display = 'none';	
}


function pleasewait() {
   document.getElementById('loading-objects' ).style.display = 'block';
}

function validateEventCreation() {
    ar_public = document.getElementById( "ar_id_public" );    
    if( ar_public.checked == true ) 
    {
	var choice = window.confirm( "Are you sure you want your event to appear in Public?" );
	if( choice ) {
	    return true;
	} else {	    
	    alert( "Access privacy tab to set event visibility to private. Please try again!" );
	    return false;
	}
	
    }
    return true;
}

/**
 * DHTML textbox character counter script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
maxL=100;
var bName = navigator.appName;
function taLimit_inv(taObj) {
	if (taObj.value.length > maxL) {
	    tex = taObj.value.substring(0,maxL);
	    taObj.value =tex;
	    return false;
	}
	return true;
}

function taCount_inv(taObj,Cnt) { 
	objCnt=createObject_inv(Cnt);
	objVal=taObj.value;
	if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
	if (objCnt) {
		if(bName == "Netscape"){	
			objCnt.textContent=maxL-objVal.length;}
		else{objCnt.innerText=maxL-objVal.length;}
	}
	return true;
}
function createObject_inv(objId) {
	if (document.getElementById) return document.getElementById(objId);
	else if (document.layers) return eval("document." + objId);
	else if (document.all) return eval("document.all." + objId);
	else return eval("document." + objId);
}


function setEventDates( ids ) {
    dayid = "day_" + ids;
    monthid = "month_" + ids;
    dayelem = document.getElementById( dayid );
    if( dayelem.value == 0 ) {
        alert( "Select a valid day and try again!" );
        return false;
    }
    monthelem = document.getElementById( monthid );
    if( monthelem.value == 0 ) {
        alert( "Select a valid month and try again!" );
        return false;
    }
    if( monthelem.value == 2 && dayelem.value > 29 ) {
        alert( "February month does not consist of days more than 29 days. Please try again!" );
        return false;
    }
    ids = ids + "_" + dayelem.value + "_" + monthelem.value;
    var ajax = new Ajax.Updater('', '../ajax/ddrtrvr.php?grpdatesids=' + ids ,{method:'get',asynchronous:true,onComplete: processGroupDates });
}

function processGroupDates( res ) {
    l_restxt = res.responseText; 
    elem = document.getElementById( l_restxt );
    elem.style.display = 'none';
    l_restxtblock = l_restxt + "_block";
    elem = document.getElementById( l_restxtblock );
    elem.style.display = 'none';
    l_refblock = l_restxt + "_refresh";
    elem = document.getElementById( l_refblock );
    elem.style.display = 'block';
}

function sendCode( usrid ) {
    rate_loading_objects();
    l_mobile = document.getElementById( "mobile" ).value;
    l_mobile = Trim( l_mobile );
    if( l_mobile.length < 10 ) {
        alert( "Enter 10 digit mobile number without leading 0 or country code 91 and try again!" );
        rate_unloading_objects();
        return false;
    }
    if( l_mobile.indexOf( "0" ) == 0 || l_mobile.indexOf( "91" ) == 0 ) {
        alert( "Enter 10 digit mobile number without leading 0 or country code 91 and try again!" );
        rate_unloading_objects();
        return false;
    }
    ids = usrid + "_" + l_mobile;  
    var ajax = new Ajax.Updater('', '../ajax/ddrtrvr.php?regmobnbr=' + ids ,{method:'get',asynchronous:true,onComplete: processSendCode });
}

function processSendCode( res ) {
    alert( res.responseText ); 
    rate_unloading_objects();
}

function confirmCode( usrid ) {
    rate_loading_objects();
    l_auth = document.getElementById( "authcode" ).value;
    l_auth = Trim( l_auth );
    if( l_auth.length < 4 ) {
        alert( "Enter 4 digit code that you received on your new mobile number and try again!" );
        rate_unloading_objects();
        return false;
    }
    ids = usrid + "_" + l_auth;     
    var ajax = new Ajax.Updater('', '../ajax/ddrtrvr.php?mobauthcode=' + ids ,{method:'get',asynchronous:true,onComplete: processConfirmCode });
}

function processConfirmCode( res ) {
    alert( res.responseText ); 
    rate_unloading_objects();
}
function Trim(a_value)
{
    if(a_value.length < 1)
    {
        return"";
    }
    a_value = RTrim(a_value);
    a_value = LTrim(a_value);
    if(a_value == "")
    {
        return "";
    }else
    {
        return a_value;
    }
} 

function RTrim(a_value)
{
    var w_space = String.fromCharCode(32);
    var v_length = a_value.length;
    var strTemp = "";
    if(v_length < 0)
    {
        return"";
    }
    var iTemp = v_length -1;

    while(iTemp > -1)
    {
        if(a_value.charAt(iTemp) == w_space)
        {
        }else
        {
            strTemp = a_value.substring(0,iTemp +1);
            break;
        }
        iTemp = iTemp-1;
    } 
    return strTemp;
} 

function LTrim(a_value)
{
    var w_space = String.fromCharCode(32);
    if(v_length < 1)
    {
         return"";
    }
    var v_length = a_value.length;
    var strTemp = "";
    var iTemp = 0;

    while(iTemp < v_length)
    {
        if(a_value.charAt(iTemp) == w_space)
        {
        }else
        {
            strTemp = a_value.substring(iTemp,v_length);
            break;
        }
        iTemp = iTemp + 1;
    } 
    return strTemp;
}

function previewEPForm() {        
    var ua = navigator.userAgent.toLowerCase();
    isOpera = (ua.indexOf("opera") != -1);
    if( isOpera )  {
        updateRTEE('description'); 
    } else {
        updateRTE('description');  
    }
    return true; 
}

function submitEPForm() {
    var ua = navigator.userAgent.toLowerCase();       
    isOpera = (ua.indexOf("opera") != -1);    
    if( isOpera ) {
       updateRTEE('description');  
    } else {
       updateRTE('description');  
    }
    return validateEventCreation(); 
}

function updateRTEE(rte) {
	var oHdnMessage = document.getElementById('hdn' + rte);
	var oRTE = document.getElementById(rte);
	var readOnly = false;
	if (document.all) {
		if (frames[rte].document.designMode != "On") readOnly = true;
	} else {
		if (document.getElementById(rte).contentDocument.designMode != "on") readOnly = true;
	}	
	if (document.getElementById("chkSrc" + rte).checked) {
		document.getElementById("chkSrc" + rte).checked = false;
		toggleHTMLSrc(rte);
	}
	if (oHdnMessage.value == null) oHdnMessage.value = "";
	if (document.all) {
		oHdnMessage.value = frames[rte].document.body.innerHTML;
	} else {
		oHdnMessage.value = oRTE.contentWindow.document.body.innerHTML;
	}	
	if (stripHTML(oHdnMessage.value.replace("&nbsp;", " ")) == "" 
		&& oHdnMessage.value.toLowerCase().search("<hr") == -1
		&& oHdnMessage.value.toLowerCase().search("<img") == -1) oHdnMessage.value = "";
	if (escape(oHdnMessage.value) == "%3Cbr%3E%0D%0A%0D%0A%0D%0A") oHdnMessage.value = "";
	
}