var Service = new CService();
function CService()
{
	this.validationMap = new Array();
	this.validationMap['emailAddress'] = Common.checkEmailAddress;
	this.validationMap['phoneNumber'] = Common.checkPhoneNumber;
}

CService.prototype.selectedOption = function(id)
{
	var opt = Common.findById(id);
	var value = opt.options[opt.options.selectedIndex].value
	var others = Common.findById('others_tr');
	if(value == "-1") {
		others.className = "show";
	}else {
		others.className = "hide";
	}
}

CService.prototype.submitServiceForm = function(formId, elemIds)
{
	var bSubmit = Common.findById('submit');
	var sHref = bSubmit.href; 
	bSubmit.href = "#headerPageStart";
	var formElem = Common.findById(formId);
	if(formElem == null)
		return;
	var elems = elemIds.split(",");
	if(elems == null || elems.length == 0)
		formElem.submit();
	else 
	{
		var bError = false;
		for(var a=0;a<elems.length;a++)
		{
			var elemId = elems[a];
			if(Common.trim(elemId).length == 0)
				continue;
			var elem = Common.findById(elemId);
			if(elem == null || elem.title.toLowerCase() == 'true')
				continue;
			Design.markErroneous(elem, false);
			var nodeName = elem.nodeName.toLowerCase();
			var nodeValue = '';
			if(nodeName == 'input')
			{
				var nodeType = elem.type.toLowerCase();
				nodeValue = Common.trim(elem.value.toLowerCase());
				if(nodeType == 'text' || nodeType == 'password')
				{
					if(elem.id == "others")
					{
						var others = Common.findById('others_tr');
						if(others.getAttribute("class") == "show" && nodeValue.length == 0)
						{
							Design.markErroneous(elem, true);
							bError = true;
							continue;
						}							
					}
					else if(nodeValue.length == 0)
					{
						Design.markErroneous(elem, true);
						bError = true;
						continue;
					}
				}
				else if(nodeType == 'checkbox')
				{
					elem.value = elem.checked;
				}
			}
			else if(nodeName == 'textarea')
			{
				nodeValue = Common.trim(elem.value.toLowerCase());
				if(elem.id == "others")
				{
					var others = Common.findById('others_tr');
					if(others.getAttribute("class") == "show" && nodeValue.length == 0)
					{
						Design.markErroneous(elem, true);
						bError = true;
						continue;
					}							
				}
				else if(nodeValue.length == 0)
				{
					Design.markErroneous(elem, true);
					bError = true;
					continue;
				}
			}
			else if (nodeName == 'select')
			{
				nodeValue = Common.trim(elem.value.toLowerCase());
				if(nodeValue.length == 0)
				{
					Design.markErroneous(elem, true);
					bError = true;
					continue;
				}
			}
			var validationFunc = this.validationMap[elemId];
			if(validationFunc != null && nodeValue != null && nodeValue.length > 0) 
			{
				if(!validationFunc(nodeValue))
				{
					Design.markErroneous(elem, true);
					bError = true;
					continue;
				}
			}
		}
		
		var si = Common.findById('si');
		if(!bError) {
			if(si.value == 3) {
				if(confirm("If address is correct then press ok else cancel and provide correct address."))
					formElem.submit();
				else
					bSubmit.href = sHref;
			} else {
				formElem.submit();
			}
		}
	}
	if(bError)
		bSubmit.href = sHref;
}
