function showHideAdvanceSearch(divID){
	if(document.getElementById(divID).style.display=='block'){
		document.getElementById(divID).style.display='none';
		return;
	}
	document.getElementById(divID).style.display='block';
	return;
}
function jumpTo2(source,length,target,val) {
	//alert(val.value);
	if(isNaN(val.value)){
		alert('Please Enter Numeric Value.')
		val.value="";
		return false;
	}
	if (document.all) {
		var ascii = event.keyCode;
		if ((ascii < 20 && ascii != 8) || (ascii > 126 && ascii != 127)) {
			//event.keyCode = 0; // dbp - commented this out due to SHIFT key causing "access denied" errors
			return false;
		}
	}
	if (document.layers) {
		var ascii = source.which;
		if ((ascii < 20 && ascii != 8) || (ascii > 126 && ascii != 127)) {
			//source.which = 0; // dbp - commented this out due to SHIFT key causing "access denied" errors
			return false;
		}
	}
	if (source.value.length == length) {
		target.focus();
		target.select();
		return true;
	} else {
		return false;
	}
}
var browseFlag = "0";
//--  Functions used in admin panel ---//
function warnInBrowseEvent(eventTitle,totalChild,googleID,urltosend){
	
	if(totalChild>0){
		var msg='Parent '+'"'+eventTitle+'"'+' is associated with '+totalChild+' child';
		if(totalChild>1) msg+='(s)';
		msg+=', do you really want to delete?';
		if(googleID!=''){
			if(browseFlag=='0'){
				var msg1=confirm(msg);
				if(msg1){					
					deleteGoogleEvent(googleID,urltosend);
				}else return false;
			}
			if(browseFlag=="2"){
				return true;
			}else{ 
				//warnInBrowseEvent(eventTitle,totalChild,googleID);
			}
		}else{ /*** if no google id exist.***/
			if(confirm(msg)){
				window.location = urltosend;
				return true;
			}
		}
		return false;
	}else if(totalChild==0){
		if(googleID!=''){
			if(browseFlag=='0'){
				var msg1=confirm("Do you really want to delete?");
				if(msg1){					
					deleteGoogleEvent(googleID,urltosend);
				}else return false;
			}
			if(browseFlag=="2"){
				return true;
			}else{ 
				//warnInBrowseEvent(eventTitle,totalChild,googleID)
			}
		}else{ /*** if no google id exist.***/
			if(confirm("Do you really want to delete?")) 
			window.location = urltosend;
			return true;
		}
	}
	return false; 
 }
 
function warn(){
	if(confirm("Do you really want to delete?")) return true;
	return false;
}

function warnChild(eventTitle,totalChild,eventId,path,assoc,userType,googleID,urltosend){
	var msgFlag='0';
	if(userType!='a' && assoc>1){
		alert('You are not authorised to delete this event, as the event is currently \nassociated with multiple parent events.');
		return false;
	}else{
		if(totalChild>0){
			var msg='Child '+'"'+eventTitle+'"'+' is associated with '+totalChild+' parent';
			if(totalChild>1) msg+='(s)';
			msg+=', do you really want to delete?';
			if(googleID!=''){
				if(browseFlag=='0'){
					var msg1=confirm(msg);
					if(msg1){						
						deleteGoogleEventChild(googleID,urltosend);
					}else return false;
				}
				if(browseFlag=="2"){
					return true;
				}else{ 
					//warnChild(eventTitle,totalChild,eventId,path,assoc,userType,googleID);
				}
			}else{ /*** if no google id exist.***/
				if(confirm(msg)){
					 window.location = urltosend;
					return true;
				}
			}
			return false;
		}else if(totalChild==0){
			if(confirm("Do you really want to delete?")) return true;
			return false;
		}
	}
	return false; 
} 
var myUrl="";
	/*** Ajax call for deleting google event ****/ 
	function deleteGoogleEvent(googleID,urltosend){
		myUrl = urltosend;	
    document.getElementById("showBar").style.display= '';
	
	browseFlag = "1";
		try{ obj = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){ obj = null;}    
		
		try{ obj = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e1){	obj = null;}    
	
		if(window.XMLHttpRequest){
			obj = new XMLHttpRequest();    
		}
			
		if(obj!=null){
			obj.onreadystatechange=ProcessResponse2;
			if(window.XMLHttpRequest){
				obj.open("GET",'deleteEvent_browseList.php?googleId='+googleID,true);
			}else{
				obj.open("POST",'deleteEvent_browseList.php?googleId='+googleID,true);
			}	
			//alert('URL: deleteEvent_browseList.php?googleId='+googleID);
			obj.send(null); 
		}
	}
	function ProcessResponse2(){
		if(obj.readyState == 4 && obj.status == 200){
			var retval=obj.responseText;			
			//alert('RESParent'+retval);								
			//alert(myUrl);
			if(trim(retval)=="updated")
			{			
			 window.location = myUrl;
			}
			else
			{
			 alert("Event not deleted due to communication failure.");			 
	         document.getElementById("showBar").style.display= 'none';
			 browseFlag="0";
			return false;
			}
			
			browseFlag="2";
			return;
		}
	}

function checkAll(status)
{var frm="browseVenueChunk";
  if(document.frm.checkbox.checked==true){
	  for(i=0; i<document.frm.elements.length; i++)
	  if(document.frm.elements[i].type=='checkbox')
	   document.frm.elements[i].checked = true;
	}else{
	for(i=0; i<document.frm.elements.length; i++)
	  if(document.frm.elements[i].type=='checkbox')
	   document.frm.elements[i].checked = false;	
	}
}
function showHideAddCommentBox(sessionId,divID,commentMsgDiv){
	if(sessionId==""){
		if(document.getElementById(commentMsgDiv).style.display=='block'){
			document.getElementById(commentMsgDiv).style.display='none';
		}else{
			document.getElementById(commentMsgDiv).style.display='block';
			document.getElementById(commentMsgDiv).className='blueFontMsg';
			document.getElementById(commentMsgDiv).innerHTML='Please login to post a comment.';
			document.getElementById(divID).style.display='none';
			return;
		}
	}else{
		if(document.getElementById(divID).style.display=='block'){
			document.getElementById(divID).style.display='none';
			document.getElementById(commentMsgDiv).style.display='none';
			return;
		}else if(document.getElementById(divID).style.display=='none'){
			document.getElementById(divID).style.display='block';
			document.getElementById(commentMsgDiv).style.display='none';
			return;
		}
	}
}
function addCommentValidation(frmObj){
	var val=trim(frmObj.comment.value);
	if(val==""){
		alert('Please enter comment.');
		frmObj.comment.value="";
		frmObj.comment.focus();
		return false;
	}
	return true;
}

function CreateBookmarkLink() {

	title = "Webpage Title"; 
  	// Blogger - Replace with <$BlogItemTitle$> 
  	// MovableType - Replace with <$MTEntryTitle$>
	url = "Webpage URL";
	// Blogger - Replace with <$BlogItemPermalinkURL$> 
	// MovableType - Replace with <$MTEntryPermalink$>
    // WordPress - <?php bloginfo('url'); ?>

	if(window.sidebar){ // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
		return true; 
	}else if(window.external){ // IE Favorite
		window.external.AddFavorite(url, title);
		return true; 
	}else if(window.opera && window.print) { // Opera Hotlist
		return true; 
	}
 }
 function createBookmark(){
 	if(document.all)
		window.external.AddFavorite(location.href,document.title);
	else if(window.sidebar)window.sidebar.addPanel
	(document.title,location.href,'')
 }

//-- Function to delete records from browse panel ----//
function validate_Delete(){		
	var flag=false;
	if(delete_parent()){ 
		flag=true;
	}
	//if(delete_child()){ 
		//flag=true;
	//}
	if(flag) return true;
	return false;
}
function delete_child(){
	var x=document.getElementsByName('uc_child[]');	
	var len = x.length;
	var check_flag=0;
	for(var i= 0; i<len; i++){
		if(x[i].checked){
			check_flag=1;
			break;
		}else if(i==len-1){
			check_flag=0;
		}			
	}
	if(check_flag==0){
		 alert('Please check at least one record.');
		 return false;			
	}else if(!confirm("Do you really want to delete?")){
		return false;
	}else{
		return true;
	}
}
function delete_parent(){
	var x=document.getElementsByName('uc[]');	
	var len = x.length;
	var check_flag=0;
	for(var i = 0; i<len; i++){
		if(x[i].checked){
			check_flag=1;
			break;
		}else if(i==len-1){
			check_flag=0;
		}			
	}
	if(check_flag==0){
		 alert('Please check at least one record.');
		 return false;			
	}else if(!confirm("Do you really want to delete?")){
		return false;
	}else{
		return true;
	}
}
var globalCount=0;
function getChild(child,hiddenId){
	//alert('globalCount ='+globalCount);
	if(document.getElementById(hiddenId).style.display=="none"){
		globalCount=parseInt(globalCount)+parseInt(child);
		document.getElementById(hiddenId).style.display='block';
		return;
	}else{
		globalCount=parseInt(globalCount)-parseInt(child);
		document.getElementById(hiddenId).style.display='none';
		return;
	}
}
function validateDeleteParent(){
	//alert('globalCount ='+globalCount);
	var x=document.getElementsByName('uc[]');	
	var len = x.length;
	var check_flag=0;
	for(var i = 0; i<len; i++){
		if(x[i].checked){
			check_flag=1;
			break;
		}else if(i==len-1){
			check_flag=0;
		}			
	}
	if(check_flag==0){
		 alert('Please check at least one record.');
		 return false;			
	}else if(globalCount>0){
		if(confirm("Parent event(s) are associated with child(s), do you really want to delete?")){
			return true;
		}
	}else if(globalCount==0){
		if(confirm("Do you really want to delete?")) return true;
		return false;
	}
	return false;
}

/** Functions used for trimming a string via JS **/
function trim(s)
{
	return rtrim(ltrim(s));
}

function ltrim(s)
{
	var l=0;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	return s.substring(l, s.length);
}

function rtrim(s)
{
	var r=s.length -1;
	while(r > 0 && s[r] == ' ')
	{	r-=1;	}
	return s.substring(0, r+1);
}
/** Functions used for trimming a string via JS **/

function setSorting(obj){
	alert('obj '+obj.value);
}



var myUrlchild="";
var obj1;
	/*** Ajax call for deleting google event ****/ 
	function deleteGoogleEventChild(googleID,urltosend){
		myUrlchild = urltosend;
		
		 document.getElementById("hideButtons").style.display= 'none';
	     document.getElementById("showBar").style.display= '';
	
	browseFlag = "1";
		try{ obj1 = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){ obj1 = null;}    
		
		try{ obj1 = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e1){	obj1 = null;}    
	
		if(window.XMLHttpRequest){
			obj1 = new XMLHttpRequest();    
		}
			
		if(obj1!=null){
			obj1.onreadystatechange=ProcessResponse4;
			if(window.XMLHttpRequest){
				obj1.open("GET",'deleteEvent_browseList.php?googleId='+googleID,true);
			}else{
				obj1.open("POST",'deleteEvent_browseList.php?googleId='+googleID,true);
			}				
			obj1.send(null); 
		}
	}
	function ProcessResponse4(){
		if(obj1.readyState == 4 && obj1.status == 200){
			var retval=obj1.responseText;			
			//alert('RESChild'+retval);
			if(trim(retval)=="updated")
			{
				window.location = myUrlchild;
			}
			else
			{			 
			 alert("Event not deleted due to communication failure.");
			 document.getElementById("hideButtons").style.display= '';
	         document.getElementById("showBar").style.display= 'none';
			 browseFlag="0";			
			return false;
			}			
			browseFlag="2";
			return;
		}
	}

