//*************************************************************************************************
//		KaonCart Script copyright Kaon Softwares ( http://www.kaonsoftwares.com )
//=================================================================================================
//		NOTICE: Do NOT remove the copyright and/or license information from this file.
//				doing so will automatically terminate your rights to use this program.
//-------------------------------------------------------------------------------------------------
//		You may modify the source code but this copyright notice MUST remain at all times
//*************************************************************************************************

function validateForm(f)
{
	for (var i=0; i<f.elements.length; i++)
	{
		if (f.elements[i].alt=="blank" && f.elements[i].value=="")
		{
			alert("Please provide "+f.elements[i].name);
			f.elements[i].focus();
			return false;
		}
		if (f.elements[i].alt=="numeric" && (f.elements[i].value=="" || isNaN(f.elements[i].value)))
		{
			alert("Please provide "+f.elements[i].name);
			f.elements[i].focus();
			return false;
		}
		if (f.elements[i].alt!="" && f.elements[i].alt!=null)
		{
			if (f.elements[i].alt.substr(0, 7)=="equalto")
			{
				if ((f.elements[i].value!=f[f.elements[i].alt.substr(8)].value))
				{
					alert(f.elements[i].name+" should be same as "+f[f.elements[i].alt.substr(8)].name);
					f.elements[i].focus();
					return false;
				}
			}
		}
	}

	return true;
}

function buildPOST(f)
{
    var qs = '';
   for (var i=0; i<f.elements.length; i++)
	{
		// Check if its a richeditor field
		if ( f.elements[i].type == 'hidden' )
		{
			try
			{
				oEditor = FCKeditorAPI.GetInstance(f.elements[i].name);
				f.elements[i].value = oEditor.GetXHTML(true);
			}
			catch (e) {}
		}

        if ( f.elements[i].name != '' )
		{
            var name = f.elements[i].name;
			
			if ( ( f.elements[i].type == 'checkbox' || f.elements[i].type == 'radio' ) && !f.elements[i].checked )
				continue;

			if ( f.elements[i].type == 'select-multiple' )
			{
				for (var j=0; j<f.elements[i].options.length; j++)
				{
					if ( f.elements[i].options[j].selected )
					{
			            qs += (qs == '') ? '' : '&';
			            qs += name + '=' + escape(f.elements[i].options[j].value);
					}
				}
	
				continue;
			}

            qs += (qs == '') ? '' : '&';
            qs += name + '=' + escape(f.elements[i].value);
        }
    }
    qs += "\n";

    return qs;
}
