// JavaScript Document
function ValidateAppointment()
{
	var msg="";
	if(document.appointment.name.value=="" || document.appointment.name.value=="Enter your Name....")
	{
		msg+="- name!\n";
		document.appointment.name.value="Enter your Name....";
	}
	if(document.appointment.mobile.value=="" || document.appointment.mobile.value=="Mobile Number....")
	{
		msg+="- mobile number!\n";
		document.appointment.mobile.value="Mobile Number....";
	}
	else
	{
		if(/\D/.test(document.appointment.mobile.value))
		{
			msg="- mobile number must be numeric!";
			document.appointment.mobile.value="Mobile Number....";
		}
	}
	if(document.appointment.email.value=="" || document.appointment.email.value=="Email Address....")
	{
		msg+="- email address!\n";
		document.appointment.email.value="Email Address....";
	}
	else
	{
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var address = document.appointment.email.value;
		if(reg.test(address) == false) 
		{
			msg="- valid email address!\n";
   		}
	}
	
	
	if(document.appointment.address.value=="" || document.appointment.address.value=="Address....")
	{
		msg+="- address!\n";
		document.appointment.address.value="Address....";
	}
	if(document.appointment.postcode.value=="" || document.appointment.postcode.value=="Postal Code....")
	{
		msg+="- postcode!\n";
		document.appointment.postcode.value="Postal Code....";
	}
	if(document.appointment.datetime.value=="" || document.appointment.datetime.value=="Date/Time....")
	{
		msg+="- date!\n";
		document.appointment.datetime.value="Date/Time....";
	}
	else
	{
		if(isDate(document.appointment.datetime.value)==false)
		{
			msg+="- correct date!\n";
			document.appointment.datetime.value="";
		}
	}
	if(document.appointment.pdescription.value=="" || document.appointment.pdescription.value=="Problem Description")
	{
		msg+="- Problem Description!\n";
		document.appointment.pdescription.value="Problem Description";
	}
	if(msg!="")
	{
		alert("Please Provide Followings. \n"+msg);
		return false;
	}
	else
	{
		return true;
	}
}

function isDate(txtDate) 
{
    var objDate,  // date object initialized from the txtDate string
        mSeconds, // txtDate in milliseconds
        day,      // day
        month,    // month
        year;     // year
    // date length should be 10 characters (no more no less)
    if (txtDate.length !== 10) 
	{
        return false;
    }
    // third and sixth character should be '/'
    if (txtDate.substring(2, 3) !== '/' || txtDate.substring(5, 6) !== '/') 
	{
        return false;
    }
    // extract month, day and year from the txtDate (expected format is mm/dd/yyyy)
    // subtraction will cast variables to integer implicitly (needed
    // for !== comparing)
    month = txtDate.substring(0, 2) - 1; // because months in JS start from 0
    day = txtDate.substring(3, 5) - 0;
    year = txtDate.substring(6, 10) - 0;
    // test year range
    if (year < 1000 || year > 3000)
	{
        return false;
    }
    // convert txtDate to milliseconds
    mSeconds = (new Date(year, month, day)).getTime();
    // initialize Date() object from calculated milliseconds
    objDate = new Date();
    objDate.setTime(mSeconds);
    // compare input date and parts from Date() object
    // if difference exists then date isn't valid
    if (objDate.getFullYear() !== year || objDate.getMonth() !== month || objDate.getDate() !== day) 
	{
        return false;
    }
    // otherwise return true
    return true;
}
function ValidateEmail()
{
	var msg="";
	if(document.subscribe.newsletter.value=="" || document.subscribe.newsletter.value=="Enter your email address....")
	{
		msg="- email address!\n";
		document.subscribe.newsletter.value=="Enter your email address....";
	}
	else
	{
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var address = document.subscribe.newsletter.value;
		if(reg.test(address) == false) 
		{
			msg="- valid email address!\n";
   		}
	}
	
	if(msg!="")
	{
		alert("Please provide following.\n"+msg);
		return false;
	}
	else
	{
		return true;
	}
}

function ValidateContactUs()
{
	var msg="";
	if(document.contactus.name.value=="")
	{
		msg+="- name!\n";
	}
	if(document.contactus.email.value=="")
	{
		msg+="- email address!\n";
	}
	else
	{
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var address = document.contactus.email.value;
		if(reg.test(address) == false) 
		{
			msg="- valid email address!\n";
   		}
	}
	
	
	if(document.contactus.address.value=="")
	{
		msg+="- address!\n";
	}
	if(document.contactus.phone.value=="" )
	{
		msg+="- phone!\n";
	}
	else
	{
		if(/\D/.test(document.contactus.phone.value))
		{
			msg="- phone must be numeric!";
		}
	}
	if(document.contactus.mobile.value=="")
	{
		msg+="- mobile number!\n";
	}
	else
	{
		if(/\D/.test(document.contactus.mobile.value))
		{
			msg="- mobile number must be numeric!";
		}
	}
	if(document.contactus.problem.value=="")
	{
		msg+="- problem!\n";
	}
	if(document.contactus.description.value=="")
	{
		msg+="- description!\n";
	}
	if(msg!="")
	{
		alert("Please Provide Followings. \n"+msg);
		return false;
	}
	else
	{
		return true;
	}
}
