
function returnObject(arg, formObj) {
	var myObj = null;
	if (formObj != null) {
		myObj = formObj.elements[arg];
	} else if (typeof arg == 'string') {
		myObj = document.getElementById(arg);
	} else if (typeof arg == 'object') {
		myObj = arg;
	}

	return myObj;
}

// simple function to show a container
function show(arg) {
	var myObj = returnObject(arg);
	if (myObj != null) {
		myObj.style.display = "block";
	}
}

// simple function to hide a container
function hide(arg) {
	var myObj = returnObject(arg);
	if (myObj != null) {
		myObj.style.display = "none";
	}
}

//hide Multiple hideM(field1,field2,...)
function hideM() {
	for (var i = 0; i < arguments.length; i++) {
		hide(arguments[i]);
	}
}
//show Multiple showM(field1,field2,...)
function showM() {
	for (var i = 0; i < arguments.length; i++) {
		show(arguments[i]);
	}
}

function clearInputsWithValue(form, myValue, inputType) {
	// if inputType is not specified, then use 'input' as default
	var type = (inputType == null) ? 'input' : inputType;

	var formObj = returnObject(form);

	var inputs = formObj.getElementsByTagName(type);

	// lets remove the specified value from our input values
	for ( i = 0; i < inputs.length; i++ ) {
		if(inputs[i].value.toLowerCase() == myValue) {
			inputs[i].value = '';
		}
	}
}

function scrollToTop() {
	if (document.body.scrollTop) {
		document.body.scrollTop = 0;
	} else if(document.body.scrollTo) {
		document.body.scrollTo(0,0);
	} else {
		location.href = "#top";
	}
}

//Delay function after a few seconds delay("alert('sample!')",1000);
function delay(functionToCall,delayMill){
	if(functionToCall && delayMill != null){
		window.setTimeout(functionToCall,delayMill);
	}
}


$().ready(function() {

	//This line is for getting & displaying the copyright year in the footer
	$("#year").text((new Date).getFullYear());

	//method to check if the fields are using default values
	jQuery.validator.addMethod("defaultInvalid", function(value, element){
		if (element.value == element.defaultValue){
			return false;
		}
		return true;
	});

	function clearInputs(fieldId,defaultValue){
		var origValue = "";	
		$(fieldId).click(function(){
			origValue = $(this).val();
			if($(fieldId).val() == defaultValue){
				$(this).val("");
			}
		});

		$(fieldId).blur(function(){
			if($(fieldId).val() == ""){
				$(fieldId).val(origValue);
			}
		});
	}

	clearInputs("#full_name","Full Name");
	clearInputs("#email","Email");
	clearInputs("#phone","Phone");


	// validate signup form on keyup and submit
	$("#startForm").validate({
		errorContainer: $("#msgs-error"),

		rules: {
			full_name: "defaultInvalid",
			phone: {
				required: "defaultInvalid",
				minlength: 13
			},
			email: {
				required: "defaultInvalid",
				email: true
			}
		}
	});

});


