﻿// JavaScript Document
// this.document.write("Amin");



// Submit form
function ew_SubmitForm(form_object) {
	if (typeof ew_UpdateTextArea == 'function')
		ew_UpdateTextArea();
	if (ew_ValidateForm(form_object))
		form_object.submit();
}

// Remove spaces
function ew_RemoveSpaces(value) {
	str = value.replace(/^\s*|\s*$/g, "");
	str = str.toLowerCase();
	if (str == "<p />" || str == "<p/>" || str == "<p>" ||
		str == "<br />" || str == "<br/>" || str == "<br>" ||
		str == "&nbsp;" || str == "<p>&nbsp;</p>")
		return ""
	else
		return value;
}

// Check if hidden text area
function ew_IsHiddenTextArea(input_object) {
	return (input_object && input_object.type && input_object.type == "textarea" &&
		input_object.style && input_object.style.display &&
		input_object.style.display == "none");
}

// Set focus
function ew_SetFocus(input_object) {
	if (!input_object || ew_IsHiddenTextArea(input_object))
		return;
	input_object = (!input_object.type && input_object[0]) ? input_object[0] : input_object;
	var type = input_object.type;
	if (type != "hidden")
		input_object.focus();
	if (type == "text" || type == "password" || type == "textarea" || type == "file")
		input_object.select();
}

// Process validate error
function ew_OnError(input_object, error_message) {
	alert(error_message);
	if (typeof ew_GotoPageByElement != 'undefined') // check if multi-page
		ew_GotoPageByElement(input_object);
	ew_SetFocus(input_object);
	return false;
}

// Check if object has value
function ew_HasValue(obj) {
	if (!obj)
		return true;
	var type = (!obj.type && obj[0]) ? obj[0].type : obj.type;
	if (type == "text" || type == "password" || type == "textarea" ||
		type == "file" || type == "hidden") {
		return (obj.value.length != 0);
	} else if (type == "select-one") {
		return (obj.selectedIndex > 0);
	} else if (type == "select-multiple") {
		return (obj.selectedIndex > -1);
	} else if (type == "checkbox") {
		if (obj[0]) {
			for (var i=0; i < obj.length; i++) {
				if (obj[i].checked)
				return true;
			}
			return false;
		}
	} else if (type == "radio") {
		if (obj[0]) {
			for (var i=0; i < obj.length; i++) {
				if (obj[i].checked)
				return true;
			}
			return false;
		} else {
			return obj.checked;
		}
	}
	return true;
}


function ew_ValidateForm1(fobj) {
	if (!ew_HasValue(fobj.username)) {
		if  (!ew_OnError(fobj.username, "نام کاربری را وارد کنید"))
			return false;
	}
	if (!ew_HasValue(fobj.password)) {
		if (!ew_OnError(fobj.password, "رمز عبور را وارد کنید"))
			return false;
	}
	return true;
}

