
var xmlRequest = new xmlObj(false);

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* israel_onSelectTopCat																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function israel_onSelectTopCat (id)
{
	var oTopCat = document.getElementById("topCategory" + id);

	if (oTopCat.value == "")
	{
		setSignOptions (id);
	}
	else
	{
		xml  = 	"<request>" +
					"<command>private.getSubCats</command>"	+
					"<parentId>" 	+ oTopCat.value 		+ "</parentId>"		+
					"<id>"			+ id					+ "</id>"			+
				"</request>";
			
		xmlRequest.init (xml);
		xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "israel_onSelectTopCat_response");
	}

}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* israel_onSelectTopCat_response																								*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function israel_onSelectTopCat_response (i)
{
	xmlRequest.init(commonDecode(asyncHttpObj.responseText));

	try
	{
		var options  = xmlRequest.getValue("options");
		var id	     = xmlRequest.getValue("id");
	}
	catch (e)
	{
		alert ("AJAX Error");
		return false;
	}

	israel_setOptions (id, options);
}

function israel_setOptions (id, options)
{
	var selectHtml = "&nbsp;Sub category:&nbsp;<select name='category" + id + "' id='category" + id + "' class='selectSubCategory'>";

	if (options != undefined)
		selectHtml += options;
	else
		selectHtml += "<option value=''></option>";

	selectHtml += "</select>";
			
	document.getElementById("selectSubCat" + id).innerHTML = selectHtml;
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* israel_validateUpdateBiz																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function israel_validateUpdateBiz ()
{
	var formValidator = new Validator("updateBizForm");
	var oForm		  = document.getElementById("updateBizForm");

	var foundCat = false;

	for (var i = 1; i <= oForm.numCats.value; i++)
	{
		if (document.getElementById("category" + i).value != "")
		{
			foundCat = true;
			break;
		}
	}

	if (!foundCat)
	{
		alert ("Please select at least one category");
		document.getElementById("category1").focus ();
		return false;
	}

	formValidator.addValidation('name',				'required',	'Please enter your company name');
	formValidator.addValidation('email',			'required',	'Please enter your e-Mail address');
	formValidator.addValidation('email',			'email',	'Please enter a valid e-Mail address');
	formValidator.addValidation('contactEmail1',	'email',	'Please enter a valid e-Mail address');
	formValidator.addValidation('contactEmail2',	'email',	'Please enter a valid e-Mail address');
	formValidator.addValidation('contactEmail3',	'email',	'Please enter a valid e-Mail address');

	return (formValidator.validate ());

}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* israel_onSelectPackage																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function israel_onSelectPackage ()
{
	var oForm = document.getElementById("addBizForm");

	var thePackage = oForm.package.value;

	if (thePackage == 4 || thePackage == 0)
	{
		theDisplay = "none";
	}
	else
	{
		theDisplay = "";
	}

	if (thePackage == 0)
		document.getElementById("showExampleLink").style.display 	= "none";
	else
		document.getElementById("showExampleLink").style.display 	= "";

	document.getElementById("logoTr").style.display 		= theDisplay;
	document.getElementById("profileTr").style.display 		= theDisplay;
	document.getElementById("siteUrlTr").style.display 		= theDisplay;
	document.getElementById("contactTitleTr").style.display = theDisplay;
	document.getElementById("contactSep1").style.display 	= theDisplay;
	document.getElementById("contactTr1").style.display 	= theDisplay;
	document.getElementById("contactTr2").style.display 	= theDisplay;
	document.getElementById("contactSep2").style.display 	= theDisplay;
	document.getElementById("contactTr3").style.display 	= theDisplay;
	document.getElementById("contactTr4").style.display 	= theDisplay;
	document.getElementById("contactSep3").style.display 	= theDisplay;
	document.getElementById("contactTr5").style.display 	= theDisplay;
	document.getElementById("contactTr6").style.display 	= theDisplay;

	document.getElementById("movieTr").style.display 		= "none";
	document.getElementById("picturesTr").style.display 	= "none";
	document.getElementById("catsTitleTr").style.display	= "none";
	document.getElementById("catsSep").style.display		= "none";
	document.getElementById("catTr1").style.display			= "none";
	document.getElementById("catTr2").style.display			= "none";
	document.getElementById("catTr3").style.display			= "none";

	switch (thePackage)
	{
		case "1"  	:
			document.getElementById("catTr3").style.display			= "";
		case "2" 	:
			document.getElementById("catTr2").style.display			= "";
			document.getElementById("movieTr").style.display		= "";
		case "3"	: 
			document.getElementById("picturesTr").style.display		= "";
		case "4"	:
			document.getElementById("catTr1").style.display			= "";
			document.getElementById("catsTitleTr").style.display	= "";
			document.getElementById("catsSep").style.display		= "";
	}
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* israel_validateUpdateBiz																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function israel_validateAddBiz ()
{
	var formValidator = new Validator("addBizForm");
	var oForm		  = document.getElementById("addBizForm");

	formValidator.clearAllValidations ();
	formValidator.addValidation('username',			'required',	'Please enter your user name');
	formValidator.addValidation('password',			'required',	'Please enter your password');
	formValidator.addValidation('email',			'required',	'Please enter your e-Mail address');
	formValidator.addValidation('email',			'email',	'Please enter a valid e-Mail address');

	if (formValidator.validate ())
	{
		israel_checkMember ();
		return false;
	}
	else
	{
		return false;
	}
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* israel_checkMember																											*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function israel_checkMember ()
{
	var oForm = document.getElementById("addBizForm");

	var xml = "<data>" +
					"<command>private.checkMember</command>"   	+
					"<username>"	+ oForm.username.value 		+ "</username>" 	+
					"<email>"		+ oForm.email.value 		+ "</email>" 		+
			  "</data>";

	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "israel_checkMember_response");
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* israel_checkMember_response																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function israel_checkMember_response (i)
{
	xmlRequest.init(commonDecode(asyncHttpObj.responseText));
						
	try
	{
		success = xmlRequest.getValue("success");
	}
	catch (e)
	{
		alert ("AJAX Error");
		return false;
	}
	
	if (success == "1")
	{
		israel_continueValidate ();
	}
	else if (success == "0")
	{
		alert ("This user name or e-Mail are already taken");
		document.getElementById("username").focus ();
		return false;
	}
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* israel_continueValidate																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function israel_continueValidate ()
{
	var formValidator = new Validator("addBizForm");
	var oForm		  = document.getElementById("addBizForm");

	var foundCat = false;

	var thePackage = oForm.package.value;

	if (thePackage == 0)
	{
		alert ("Please select one of the packages");
		oForm.package.focus ();
		return false;
	}

	var numCats = 0;
	switch (thePackage)
	{
		case "1"	: numCats	= 3;	break;
		case "2"	: numCats	= 2;	break;
		case "3"	: numCats	= 1;	break;
		case "4"	: numCats	= 1;	break;

	}

	for (var i = 1; i <= numCats; i++)
	{
		if (document.getElementById("category" + i).value != "")
		{
			foundCat = true;
			break;
		}
	}

	if (!foundCat)
	{
		alert ("Please select at least one category");
		document.getElementById("category1").focus ();
		return false;
	}

	formValidator.clearAllValidations ();
	formValidator.addValidation('name',				'required',	'Please enter your company name');
	formValidator.addValidation('contactEmail1',	'email',	'Please enter a valid e-Mail address');
	formValidator.addValidation('contactEmail2',	'email',	'Please enter a valid e-Mail address');
	formValidator.addValidation('contactEmail3',	'email',	'Please enter a valid e-Mail address');

	if (formValidator.validate ())
		oForm.submit ();
	else
		return false;
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* israel_showPackageExample																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function israel_showPackageExample ()
{
	var selectedPackage = document.getElementById("package").value;

	if (selectedPackage != 0)
	{
		window.open ("loadedFiles/" + selectedPackage + ".jpg");
	}

}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* israel_goSearch																												*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function israel_goSearch ()
{
	if (document.getElementById("bizSearchByText").value == "")
	{
		alert ("Please enter category or company name");
		return false;
	}
	return true;
}

