function TongleMenu(group) {
	
	var AllGroups = ["Calendars", "Polls", "Gallery", "Listings", "Miscellaneous"];
	
	if (document.getElementById(group + 'Group').style.display == 'none') {
		document.getElementById(group + 'Group').style.display = 'block';
		document.getElementById(group).style.backgroundImage = 'url(/images/menu-group-back-open.png)';
	} else {
		document.getElementById(group + 'Group').style.display = 'none';
		document.getElementById(group).style.backgroundImage = 'url(/images/menu-group-back.png)';
	}
	
	for (i=0; i<AllGroups.length; i++) {
		if (AllGroups[i] != group ) {
			document.getElementById(AllGroups[i]+"Group").style.display = 'none';
			document.getElementById(AllGroups[i]).style.backgroundImage = 'url(/images/menu-group-back.png)';
		}
	}
	
}


function tongleImage(imageid, script) {
	
	document.getElementById('home_cg_car').src = '/images/homescripts/cg_car_1.png';
	document.getElementById('home_blog').src = '/images/homescripts/blog_1.png';
//	document.getElementById('home_cart').src = '/images/homescripts/cart_1.png';
//	document.getElementById('home_ab').src = '/images/homescripts/ab_1.png';
	document.getElementById('home_im').src = '/images/homescripts/im_1.png';
	document.getElementById('home_eb').src = '/images/homescripts/eb_1.png';
	document.getElementById('home_hb').src = '/images/homescripts/hb_1.png';
	document.getElementById('home_kb').src = '/images/homescripts/kb_1.png';
//	document.getElementById('home_newsletter').src = '/images/homescripts/newsletter_1.png';
	document.getElementById('home_cg_vacation').src = '/images/homescripts/cg_vacation_1.png';
	document.getElementById('home_phpe').src = '/images/homescripts/phpe_1.png';
	imageid.src = 'images/homescripts/' + script + '_2.png';
}

function loading(containerid) {
	document.getElementById(containerid).innerHTML = '<center><img src="/images/loading.gif" width="32" height="32" style="margin:40px 0px 40px 0px" /></center>';
}



function check_comment_form(frm)  {
		re = /^([0-9a-zA-Z\.\-\_]+)@([0-9a-zA-Z\.\-\_]+)\.([0-9a-zA-Z\.\-\_]+)+$/;
	var name, email, comment, vercode, dataRight = true;
	message = "";
	name  = frm.name.value;
	email = frm.email.value;
	comment = frm.comment.value;
	vercode  = frm.vercode.value;
	if (name.length==0)     {
		message += "\n -  Your name";
		dataRight=false;
	};
	if (email.length==0)    {
	   message += "\n -  Your Email";
	   dataRight=false;
	};
	if (email.length!=0 && email.match(re)==null)    {
	   dataRight=false;
	   message += "\n -  Your Email is not valid";
	};
	if (comment.length==0)    {
	   message += "\n -  Comment";
	   dataRight=false;
	};
	if (vercode.length==0)     {
		message += "\n -  Verification";
		dataRight=false;
	};
	if (!dataRight)    {
		if (message != "")   {
		   message ="\n" +
		   "You failed to correctly fill in the form:\n" +
		   message + "\n" +
		   "\nPlease re-enter and submit it again!";
	   };
	   alert(message);
	};
	return dataRight;
};


function check_reply_form(frm)  {
		re = /^([0-9a-zA-Z\.\-\_]+)@([0-9a-zA-Z\.\-\_]+)\.([0-9a-zA-Z\.\-\_]+)+$/;
	var name, email, comment, vercode, dataRight = true;
	message = "";
	name  = frm.name.value;
	email = frm.email.value;
	reply = frm.reply.value;
	vercode  = frm.vercode.value;
	if (name.length==0)     {
		message += "\n -  Your name";
		dataRight=false;
	};
	if (email.length==0)    {
	   message += "\n -  Your Email";
	   dataRight=false;
	};
	if (email.length!=0 && email.match(re)==null)    {
	   dataRight=false;
	   message += "\n -  Your Email is not valid";
	};
	if (reply.length==0)    {
	   message += "\n -  Reply";
	   dataRight=false;
	};
	if (vercode.length==0)     {
		message += "\n -  Verification";
		dataRight=false;
	};
	if (!dataRight)    {
		if (message != "")   {
		   message ="\n" +
		   "You failed to correctly fill in the form:\n" +
		   message + "\n" +
		   "\nPlease re-enter and submit it again!";
	   };
	   alert(message);
	};
	return dataRight;
};


function check_question_form(frm)  {
		re = /^([0-9a-zA-Z\.\-\_]+)@([0-9a-zA-Z\.\-\_]+)\.([0-9a-zA-Z\.\-\_]+)+$/;
	var name, email, title, question, vercode, dataRight = true;
	message = "";
	name  = frm.name.value;
	email = frm.email.value;
	title = frm.title.value;
	question = frm.question.value;
	vercode  = frm.vercode.value;
	if (title.length==0)    {
	   message += "\n -  Summary";
	   dataRight=false;
	};
	if (name.length==0)     {
		message += "\n -  Your name";
		dataRight=false;
	};
	if (email.length==0)    {
	   message += "\n -  Your Email";
	   dataRight=false;
	};
	if (email.length!=0 && email.match(re)==null)    {
	   dataRight=false;
	   message += "\n -  Your Email is not valid";
	};
	if (question.length==0)    {
	   message += "\n -  Question";
	   dataRight=false;
	};
	if (vercode.length==0)     {
		message += "\n -  Verification";
		dataRight=false;
	};
	if (!dataRight)    {
		if (message != "")   {
		   message ="\n" +
		   "You failed to correctly fill in the form:\n" +
		   message + "\n" +
		   "\nPlease re-enter and submit it again!";
	   };
	   alert(message);
	};
	return dataRight;
};



function CheckTicketForm(){
		re = /^([0-9a-zA-Z\.\-\_]+)@([0-9a-zA-Z\.\-\_]+)\.([0-9a-zA-Z\.\-\_]+)+$/;
	var username, email, question, vercode, dataRight = true;
	message = "";
	
	username = document.frmTicket.user_name.value;	
	email = document.frmTicket.email.value;
	question = document.frmTicket.message.value;
	vercode = document.frmTicket.vercode.value;
	
	if (username.length==0){
		message += "\n -  Enter Name";
		dataRight=false;
	}
	if (email.length==0){
	   message += "\n -  Enter Email";
	   dataRight=false;
	}
	if (email.length!=0 && email.match(re)==null){
	   dataRight=false;
	   message += "\n -  Email is incorrect";
	}
	if (question.length==0){
		message += "\n -  Enter Question";
		dataRight=false;
	}
	if (vercode.length==0){
		message += "\n -  Verification code";
		dataRight=false;
	}

	if (!dataRight){
		if (message != ""){
		   message ="\n" +
		   "You failed to correctly fill in the form:\n" +
		   message + "\n" +
		   "\nPlease re-enter and click the Send button again!";
	   }
	   alert(message);
	}
	return dataRight;
}


function validate_buy_form(frm)  {
		re = /^([0-9a-zA-Z\.\-\_]+)@([0-9a-zA-Z\.\-\_]+)\.([0-9a-zA-Z\.\-\_]+)+$/;
	var name, email, dataRight = true;
	message = "";
	name=frm.name.value;
	email=frm.email.value;
	if (name.length==0)     {
		message += "\n -  Name";
		dataRight=false;
	};
	if (email.length==0)    {
	   message += "\n -  Email";
	   dataRight=false;
	};
	if (email.length!=0 && email.match(re)==null)    {
	   dataRight=false;
	   message += "\n -  Email is not valid";
	};
	
	if (!dataRight)    {
		if (message != "")   {
		   message ="\n" +
		   "You failed to correctly fill in the form:\n" +
		   message + "\n" +
		   "\nPlease re-enter and submit it again!";
	   };
	   alert(message);
	};
	return dataRight;
};


function validate_buy_form_noajax(frm)  {
	if (document.frm.ac.value!='check_code') {
		re = /^([0-9a-zA-Z\.\-\_]+)@([0-9a-zA-Z\.\-\_]+)\.([0-9a-zA-Z\.\-\_]+)+$/;
	var name, email, dataRight = true;
	message = "";
	name=frm.name.value;
	email=frm.email.value;
	if (name.length==0)     {
		message += "\n -  Name";
		dataRight=false;
	};
	if (email.length==0)    {
	   message += "\n -  Email";
	   dataRight=false;
	};
	if (email.length!=0 && email.match(re)==null)    {
	   dataRight=false;
	   message += "\n -  Email is not valid";
	};
	
	if (!dataRight)    {
		if (message != "")   {
		   message ="\n" +
		   "You failed to correctly fill in the form:\n" +
		   message + "\n" +
		   "\nPlease re-enter and submit it again!";
	   };
	   alert(message);
	};
	return dataRight;
	} else {
		return true;	
	}
};


var bustcachevar=1; //bust potential caching of external pages after initial request? (1=yes, 0=no)
var bustcacheparameter="";

function createRequestObject(){
	try	{
		xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
	}	catch(e)	{
		alert('Sorry, but your browser doesn\'t support XMLHttpRequest.');
	};
	return xmlhttp;
};

function ajaxpage(url, containerid){
	
	var page_request = createRequestObject();
	
	if (bustcachevar) bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
	page_request.open('GET', url+bustcacheparameter, true)
	page_request.send(null)

	page_request.onreadystatechange=function(){
		loadpage(page_request, containerid)
	}

}

function loadpage(page_request, containerid){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) {
		document.getElementById(containerid).innerHTML=page_request.responseText;
		
		if (containerid=='TotalPrice') {
			document.getElementById('AllProducts').innerHTML = '<img src="/images/loading.gif" width="32" height="32" style="margin:100px 0px 700px 230px" />';
			ajaxpage('/ajax/scripts.php','AllProducts');
		}
		
	};
}


function ajaxpage_promocode(url, containerid){
	
	var page_request = createRequestObject();
	
	if (bustcachevar) bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
	page_request.open('GET', url+bustcacheparameter, true)
	page_request.send(null)

	page_request.onreadystatechange=function(){
		loadpage_promocode(page_request, containerid)
	}

}

function loadpage_promocode(page_request, containerid){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) {
		document.getElementById(containerid).innerHTML=page_request.responseText;
	};
}


function CreateBubble(id, content) {
$(document).ready(function(){ //jQuery is ready!

	$('#'+id).CreateBubblePopup({
										innerHtml: content,
										width: 200,
										innerHtmlStyle: {
															color:'#FFFFFF',
															'text-align':'center'
														 },
										themePath: '/jquery/bubble/theme/',
										themeName: 	'all-black'
									 });
	});

}
