function GetXmlHttpObject()

{

var xmlHttp=null;

try

 {

 // Firefox, Opera 8.0+, Safari

 xmlHttp=new XMLHttpRequest();

 }

catch (e)

 {

 // Internet Explorer

 try

  {

  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

  }

 catch (e)

  {

  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

  }

 }

return xmlHttp;

} 





function create_modulegrouptype(grptype, task, counting,thisform){

	if(grptype=="all"){

		tmpgrpid = "";

		tmptask = "";

		chk = group_type_validation();

		if(!chk){

			return;

		}

		/************ devteam patch 04/01/2010 *******************/

		var formname = thisform.name;

		var forloggedout = document.getElementById('forloggedout').value;

		if(forloggedout != '')

		{

			

			

			var firstname = eval("document."+formname+".firstname.value");

			var lastname = eval("document."+formname+".lastname.value");

			var email = eval("document."+formname+".email.value");

			var fake_address = eval("document."+formname+".fake_address.value");

			if(!notEmpty(firstname, "Please enter first name")){

				return false;

					}

			if(!notEmpty(lastname, "Please enter last name")){

				return false;

				}

			if(!emailValidator(email, "Please enter a valid email address")){

				return false;

			}

		}

		/************* End of patch *******************/

		path = document.getElementById("hiddenPath_module").value;

		successmsg = document.getElementById("hidden_grouptype_success_msg").value;

		grp_ids = document.getElementById("hiddengrptype").value

		divhiddenBasePath = document.getElementById("hiddenBasePath").value;
		
		div=document.getElementById("groupTypeInfo");

		div.style.display='block';

		
		div.innerHTML= '<img border="0" src="'+divhiddenBasePath+'modules/mod_joomconnect_marketing_groups/loading.gif"/>'
		
		count= document.getElementById("count").value;
		
		var grptype=new Array();

		

		if(forloggedout != '')

		{

			for(i=1;i<=count;i++)

			{ 

				if(document.getElementById("grptype_"+i).checked==true){

				grptype[i]= document.getElementById("grptype_"+i).value;

				}

				else{

					grptype[i]=0;

				}

			}

		}

		else{

			for(i=1;i<=count;i++){

				if(document.getElementById("grptype_"+i).checked==true){

					grptype[i]= document.getElementById("grptype_"+i).value;

				

					divtxt = '<a href="#jcmrktmoduleid" onClick="return create_modulegrouptype(\''+grptype[i]+'\',\'unpublish\',\''+i+'\')"><img border="0" alt="Unpublished" src="'+divhiddenBasePath+'/administrator/images/tick.png"/></a>';

					

				showdivtxt = document.getElementById("link_"+grptype[i]);

				showdivtxt.innerHTML=divtxt;

				

				

			}

			else{	

				grptype[i]=0;

				if(document.getElementById("grptype_"+i)){

					divgrptype = document.getElementById("grptype_"+i).value;

					divtxt = '<a href="#jcmrktmoduleid" onClick="return create_modulegrouptype(\''+divgrptype+'\',\'publish\',\''+i+'\')"><img border="0" alt="Published" src="'+divhiddenBasePath+'/administrator/images/publish_x.png"/></a>';

					

					showdivtxt = document.getElementById("link_"+divgrptype);	

					showdivtxt.innerHTML=divtxt;

				}

			}

		}

		}

		grptype[0]=0;

		xmlHttp2=GetXmlHttpObject()

		if (xmlHttp2==null)

		{

			alert ("Browser does not support HTTP Request");

			return;

		}

		

		var url=path+"&grptype="+grptype+"&smsg="+successmsg+"&getalllist=yes&grp_ids="+grp_ids;

		if(forloggedout != '')

		{

			url += "&firstname="+firstname+"&lastname="+lastname+"&email="+email+"&fakeaddress="+fake_address;

		}

		//alert(url);

		xmlHttp2.onreadystatechange=createmodulegrouptype;

		xmlHttp2.open("GET",url,true);

		xmlHttp2.send(null);

	}else{ 		

		chk = group_type_validation();

		if(!chk){

			return;

		}

		

		hiddenBasePath = document.getElementById("hiddenBasePath").value;

		divhiddenBasePath = document.getElementById("hiddenBasePath").value;

		

		

		showdivtxt = document.getElementById("link_"+grptype);	

		

		if(task == 'publish')

		{

				divtxt = '<a href="#jcmrktmoduleid" onClick="return create_modulegrouptype(\''+grptype+'\',\'unpublish\',\''+counting+'\')"><img border="0" alt="Unpublished" src="'+divhiddenBasePath+'/administrator/images/tick.png"/></a>';

				document.getElementById("grptype_"+counting).checked = true;

		}

		else

		{

			divtxt = '<a href="#jcmrktmoduleid" onClick="return create_modulegrouptype(\''+grptype+'\',\'publish\',\''+counting+'\')"><img border="0" alt="Published" src="'+divhiddenBasePath+'/administrator/images/publish_x.png"/></a>';

			document.getElementById("grptype_"+counting).checked = false;

		}

		showdivtxt.innerHTML= divtxt;

		

		path = document.getElementById("hiddenPath_module").value;

		

		tmpgrpid = grptype;

		tmptask = task;

		sendpath = path;

		chkcounting = counting;

		

		

		successmsg = document.getElementById("hidden_grouptype_success_msg").value;

		divhiddenBasePath = document.getElementById("hiddenBasePath").value;
		
		div=document.getElementById("groupTypeInfo");

		div.style.display='block';

		div.innerHTML='<img border="0" src="'+divhiddenBasePath+'modules/mod_joomconnect_marketing_groups/loading.gif"/>'

		



		xmlHttp2=GetXmlHttpObject()

		if (xmlHttp2==null)

		{

			alert ("Browser does not support HTTP Request");

			return;

		}



		var url=path+"&grptype="+grptype+"&smsg="+successmsg+"&task="+task;

		//alert(url);

		xmlHttp2.onreadystatechange=createmodulegrouptype;

		xmlHttp2.open("GET",url,true);

		xmlHttp2.send(null);

	}

}//end of function



function notEmpty(elem, helperMsg){

	if(elem.length == 0){

		alert(helperMsg);

		elem.focus();

		return false;

	}

	return true;

}//end of function



function emailValidator(elem, helperMsg){

	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;

	if(elem.match(emailExp)){

		return true;

	}else{

		alert(helperMsg);

		elem.focus();

		return false;

	}

}//end of function



function createmodulegrouptype() 

{ 

	if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete")

	{	

		if(tmpgrpid!="" && tmptask!="" && hiddenBasePath!=""){

			div=document.getElementById("groupTypeInfo");

			div.style.display='block';

			div.innerHTML=xmlHttp2.responseText;

			

			if(chkcounting && chkcounting>0){

				chkboxget = document.getElementById("grptype_"+chkcounting);

				if(tmptask=="publish"){

					chkboxget.checked=true;	

				}else{

					chkboxget.checked=false;		

				}

			}

			

			

			if(tmptask=="publish"){

			txt = '<a href="#jcmrktmoduleid" onClick="return create_modulegrouptype(\''+tmpgrpid+'\',\'unpublish\',\''+chkcounting+'\')"><img border="0" alt="Unpublished" src="'+hiddenBasePath+'/administrator/images/tick.png"/></a>';

			}else{

				txt = '<a href="#jcmrktmoduleid" onClick="return create_modulegrouptype(\''+tmpgrpid+'\',\'publish\',\''+chkcounting+'\')"><img border="0" alt="Published" src="'+hiddenBasePath+'/administrator/images/publish_x.png"/></a>';

			}



div1 = document.getElementById("link_"+tmpgrpid);

			div1.innerHTML=txt;

		}else{

			div=document.getElementById("groupTypeInfo");

			div.style.display='block';

			var forloggedout = document.getElementById('forloggedout').value;

			//alert(xmlHttp2.responseText);

			if(forloggedout != '')

			{

				window.location.reload();

			}

			else

			{

				div.innerHTML=xmlHttp2.responseText;

			}

		}

	}

}//end of function



function call_group_type(){

	group_type_validation();

	document.CUSTOM_GROUP_TYPE_FORM.submit();

	return false;

}



function group_type_validation(){

	return true;

}//end of function



function checkuncheckall(){

	if(document.getElementById("checkUncheckall")){

		chkbox = document.getElementById("checkUncheckall").checked;

		count= document.getElementById("count").value;

		var grptype=new Array();

		for(i=1;i<=count;i++){

		field = document.getElementById("grptype_"+i);

		if(chkbox){

			field.checked = true ;

		}else{

			field.checked = false ;

			}

		}

	}

	

	

}
