// JavaScript Document

//Array defined by lakshman on June 20, 2009 to hold the country list
var countryList = new Array("Afghanistan","Albania","Algeria","American Samoa","Andorra","Angola","Anguilla","Antarctica","Antigua and Barbuda","Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bermuda","Bhutan","Bolivia","Bosnia and Herzegowina","Botswana","Bouvet Island","Brazil","British Indian Ocean Territory","Brunei Darussalam","Bulgaria","Burkina Faso","Burundi","Cambodia","Cameroon","Canada","Cape Verde","Cayman Islands","Central African Republic","Chad","Chile","China","Christmas Island","Cocos (Keeling) Islands","Colombia","Comoros","Congo","Cook Islands","Costa Rica","Cote D'Ivoire","Croatia","Cuba","Cyprus","Czech Republic","Denmark","Djibouti","Dominica","Dominican Republic","East Timor","Ecuador","Egypt","El Salvador","Equatorial Guinea","Eritrea","Estonia","Ethiopia","Falkland Islands (Malvinas)","Faroe Islands","Fiji","Finland","France","France"," Metropolitan","French Guiana","French Polynesia","French Southern Territories","Gabon","Gambia","Georgia","Germany","Ghana","Gibraltar","Greece","Greenland","Grenada","Guadeloupe","Guam","Guatemala","Guinea","Guinea-bissau","Guyana","Haiti","Heard and Mc Donald Islands","Honduras","Hong Kong","Hungary","Iceland","India","Indonesia","Iran","Iraq","Ireland","Israel","Italy","Jamaica","Japan","Jordan","Kazakhstan","Kenya","Kiribati","Korea"," Republic of Kuwait","Kyrgyzstan","Lao People's Democratic Republic","Latvia","Lebanon","Lesotho","Liberia","Libyan Arab Jamahiriya","Liechtenstein","Lithuania","Luxembourg","Macau","Macedonia","Malawi","Malaysia","Maldives","Mali","Malta","Marshall Islands","Martinique","Mauritania","Mauritius","Mayotte","Mexico","Micronesia"," Federated States of Moldova"," Republic of Monaco","Mongolia","Montserrat","Morocco","Mozambique","Myanmar","Namibia","Nauru","Nepal","Netherlands","Netherlands Antilles","New Caledonia","New Zealand","Nicaragua","Niger","Nigeria","Niue","Norfolk Island","Northern Mariana Islands","Norway","Oman","Pakistan","Palau","Panama","Papua New Guinea","Paraguay","Peru","Philippines","Pitcairn","Poland","Portugal","Puerto Rico","Qatar","Reunion","Romania","Russian Federation","Rwanda","Saint Kitts and Nevis","Saint Lucia","Saint Vincent and the Grenadines","Samoa","San Marino","Sao Tome and Principe","Saudi Arabia","Senegal","Seychelles","Sierra Leone","Singapore","Slovakia (Slovak Republic)","Slovenia","Solomon Islands","Somalia","South Africa","Spain","Sri Lanka","St. Helena","St. Pierre and Miquelon","Sudan","Suriname","Svalbard and Jan Mayen Islands","Swaziland","Sweden","Switzerland Syrian Arab Republic","Taiwan","Tajikistan","Tanzania"," United Republic of Thailand","Togo","Tokelau","Tonga","Trinidad and Tobago","Tunisia","Turkey","Turkmenistan","Turks and Caicos Islands","Tuvalu","Uganda","Ukraine","United Arab Emirates","United Kingdom","United States","Uruguay","Uzbekistan","Vanuatu","Vatican City State (Holy See)","Venezuela","Viet Nam","Virgin Islands (British)","Virgin Islands (U.S.)","Wallis and Futuna Islands","Western Sahara","Yemen","Yugoslavia","Zaire","Zambia","Zimbabwe");
//End of countryList Array

// Function added by Sarada to popup new window
function popupMail() 
{
		window.open("invite_friends.php","Window1","menubar=no,width=490,height=220,toolbar=no");
}
// End of function

// Function added by Sarada to Doctors pop-up window
function popUpDoctorWindow(fName,winNumber)
{
	window.open(fName,winNumber,"menubar=no,width=650,height=350,toolbar=no,top=230,left=250,scrollbars=yes");
}
// End of function

// Function added by Sarada to popup new window
function popuppage1() 
{
		window.open("erica_reid.php","Window1","menubar=no,width=590,height=320,toolbar=no,scrollbars=yes");
}
// End of function

//Function added by lakshman on June 18, 2009 to display popup window (can be called anywhere by passing the parameters as filename and window number)
function popupWindow(fName,winNumber)
{
	window.open(fName,winNumber,"menubar=no,width=490,height=220,toolbar=no");
}
// End of function

//Function added by sarada to enter only numbers
function ValidateOnlyNumberFields ( keyboardEvent )
{
	var key;

    if (navigator.appName == 'Microsoft Internet Explorer')
        key = keyboardEvent.keyCode;
    else
        key = keyboardEvent.which;

	if (key == 35 || key == 16 || key == 13 || key == 8 || key == 9 || key == 46 || key == 37 || key == 39 || (key > 47 && key < 58) || (key > 95 && key < 106)) 
	{
		return true; 
	}	
	else 
	{
		return false;
	}
};
//End of function for number validation
// Function added by sarada to stop typing
function StopTyping ( keyboardEvent )
{

    if (navigator.appName == 'Microsoft Internet Explorer')
        key = keyboardEvent.keyCode;
    else
        key = keyboardEvent.which;

    return false;
}
//end of function

//Function added by sarada on to validate phone number

function validatePhone(fld) {
    var error = "";
    var stripped = fld.replace(/[\(\)\.\-\ ]/g, ''); 

if (fld == "") {
        alert("You didn't enter a phone number.\n");
		return false;
    }
	if (isNaN(parseInt(stripped))) {
        alert("The phone number contains illegal characters.\n");
		return false;
    } 
	if (!(stripped.length == 10)) {
        alert("Please enter a valid phone number\n");
		return false;
    }
    return true;
}

//End of function

//Function added by sarada to check for proper e-mail validation
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

//Function added by lakshman on June 19, 2009 to compare current date with input date to check whether greate or lesser
function dateCompare(inputDate, opValue) {
var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
//alert(month + "/" + day + "/" + year)
if(opValue == ">=")
{
	if( (Date.parse(inputDate)) >= (Date.parse(month + "/" + day + "/" + year)) ) 
	{
		return false;
	} 
}
if(opValue == "<")
{
	if( (Date.parse(inputDate)) < (Date.parse(month + "/" + day + "/" + year)) ) 
	{
		return false;
	} 
}

}
//End of function dateCompare


function echeck1(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

//End of function

// Function added by sarada on June17, 2009 to validate mail report myeMail address
function checkMail() {
 	if(echeck(document.getElementById('myeMail').value) == false) {
		document.getElementById('myeMail').value == "";
		document.getElementById('myeMail').focus();
		return false
	}
	return true;
}

function fcheckMail() {
 	if(echeck1(document.getElementById('feMail').value) == false) {
		document.getElementById('feMail').value == "";
		document.getElementById('feMail').focus();
		return false
	}
	return true;
}
// End of checkMail function

function checkMandatory(frm) {
	if(document.frmMail.myname.value == '') {
		alert('Please enter your Name');
		document.frmMail.myname.focus();
		return false;
	}
	if(document.frmMail.myeMail.value == '') {
		alert('Please enter your e-mail addresss');
		document.frmMail.myeMail.focus();
		return false;
	}
	if(echeck(document.frmMail.myeMail.value) == false) {
		document.frmMail.myeMail.value = "";
		document.frmMail.myeMail.focus();
		return false;
	}
	if(document.frmMail.fname.value == '') {
		alert('Please enter your Friends name');
		document.frmMail.fname.focus();
		return false;
	}
	if(document.frmMail.feMail.value == '') {
		alert('Please enter your friends e-mail addresss');
		document.frmMail.feMail.focus();
		return false;
	}
	if(echeck1(document.frmMail.feMail.value) == false) {
		document.frmMail.feMail.value = "";
		document.frmMail.feMail.focus();
		return false;
	}
	return true;
}

/* Function added by sarada on June17th to bookmark a page */

function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}
//End of function

//function added by lakshman on June 18, 2009 to validate add question fields
function validateQuestion() {
	if(document.getElementById('askQuestion').value == '') {
		alert('Please enter your query');
		return false;
	}
	if(document.getElementById('uName').value == '') {
		alert('Please enter your name');
		return false;
	}
	if(document.getElementById('eMail').value == '') {
		alert('Please enter your e-mail');
		return false;
	}
	if(echeck1(document.getElementById('eMail').value) == false) {
		document.getElementById('eMail').value = "";
		document.getElementById('eMail').focus();
		return false;
	}
	return true;
}
//end of function added by lakshman 

//function added by lakshman on June 18, 2009 to validate add newsletter fields
function validateNewsletter() {
	if(document.getElementById('uName').value == '') {
		alert('Please enter your name');
		return false;
	}
	if(document.getElementById('eMail').value == '') {
		alert('Please enter your e-mail');
		return false;
	}
	if(echeck1(document.getElementById('eMail').value) == false) {
		document.getElementById('eMail').value = "";
		document.getElementById('eMail').focus();
		return false;
	}
	return true;
}
//end of function added by lakshman 

//Function added by lakshman on June 19, 2009 to validate Treatment Appointment form fields
function validateAppointment(frm)
{
	
	if(document.getElementById('firstName').value == '') {
		alert('Please enter your name');
		document.getElementById('firstName').focus();
		document.frmAppoint.firstName.focus();
		return false;
	}
	
	if(document.getElementById('birth_date').value == '') {
		alert('Please enter your birth date');
		document.frmAppoint.birth_date.focus();
		return false;
	}
	if(dateCompare(document.getElementById('birth_date').value,">=") == false) {
		alert('Birthdate cannot be greater than or equal to current date');
		document.getElementById('birth_date').value = "";
		document.frmAppoint.birth_date.focus();
		return false;
	}
	
	if(document.getElementById('patientAddress1').value == '') {
		alert('Please specify address');
		document.frmAppoint.patientAddress1.focus();
		return false;
	}
	
	if(document.getElementById('patientCity').value == '') {
		alert('Please enter city');
		document.getElementById('patientCity').focus();
		document.frmAppoint.patientCity.focus();
		return false;
	}
	
	if(document.getElementById('patientState').value == '') {
		alert('Please enter state');
		document.frmAppoint.patientState.focus();
		return false;
	}
	
	if(document.getElementById('patientCountry').value == 'select') {
		alert('Please select country');
		document.frmAppoint.patientCountry.focus();
		return false;
	}
	
	if(document.getElementById('patientZip').value == '') {
		alert('Please enter zip code');
		document.frmAppoint.patientZip.focus();
		return false;
	}
	
	if(document.getElementById('patientPhone').value == '') {
		alert('Please enter phone number');
		document.frmAppoint.patientPhone.focus();
		return false;
	}
	if(validatePhone(document.getElementById('patientPhone').value) == false) {
		document.getElementById('patientPhone').value = "";
		document.frmAppoint.patientPhone.focus();
		return false;
	}

	if(document.getElementById('eMail').value == '') {
		alert('Please enter your e-mail');
		document.getElementById('eMail').focus();
		document.frmAppoint.eMail.focus();
		return false;
	}
	if(echeck1(document.getElementById('eMail').value) == false) {
		document.getElementById('eMail').value = "";
		document.frmAppoint.eMail.focus();
		return false;
	}
	if(document.getElementById('appointDate').value == '') {
		alert('Please enter your appointment date');
		document.frmAppoint.appointDate.focus();
		return false;
	}
	if(dateCompare(document.getElementById('appointDate').value,"<") == false) {
		alert('Request date cannot be less than current date');
		document.getElementById('appointDate').value = "";
		document.frmAppoint.appointDate.focus();
		return false;
	}
	if(document.getElementById('appointTime').value == '') {
		alert('Please enter your appointment time');
		document.frmAppoint.appointDate.focus();
		return false;
	}
	return true;
}
//End of function validateAppointment


//Function added by lakshman on June 20, 2009 to validate patinet insurance form fields
function validateInsurance()
{
homePhone = document.getElementById('homephone1').value + document.getElementById('homephone2').value + document.getElementById('homephone3').value ;

workPhone = document.getElementById('work_phone1').value + document.getElementById('work_phone2').value + document.getElementById('work_phone3').value ;

	if(document.getElementById('initial_visit').value == '') {
		alert('You must enter the date of your initial visit');
		document.getElementById('initial_visit').focus();
		return false;
	}

	if(document.getElementById('firstname').value == '') {
		alert('You must enter your first name');
		document.getElementById('firstname').focus();
		return false;
	}
	
	if(document.getElementById('lastname').value == '') {
		alert('You must enter your last name');
		document.getElementById('lastname').focus();
		return false;
	}
	
	if(document.getElementById('street_address').value == '') {
		alert('You must enter your street address');
		document.getElementById('street_address').focus();
		return false;
	}
	
	if(document.getElementById('state').value == '') {
		alert('You must enter your state');
		document.getElementById('state').focus();
		return false;
	}
	
	if(document.getElementById('city').value == '') {
		alert('You must enter your city');
		document.getElementById('city').focus();
		return false;
	}
	
	if(document.getElementById('zip1').value == '') {
		alert('You must enter your zip code');
		document.getElementById('zip1').focus();
		return false;
	}
	
	if( (document.getElementById('homephone1').value == '') || (document.getElementById('homephone2').value == '') 
		|| (document.getElementById('homephone3').value == '') ) {
		alert('You must enter your home phone number');
		document.getElementById('homephone1').focus();
		return false;
	}
	if(validatePhone(homePhone) == false) {
		document.getElementById('homephone1').value = "";
		document.getElementById('homephone2').value = "";
		document.getElementById('homephone3').value = "";
		document.getElementById('homephone1').focus();
		return false;
	}
	
	if(document.getElementById('social_security_number').value == '') {
		alert('You must enter your social security number');
		document.getElementById('social_security_number').focus();
		return false;
	}

	if(document.getElementById('occupation').value == '') {
		alert('You must enter your occupation');
		document.getElementById('occupation').focus();
		return false;
	}
	
	if(document.getElementById('employer_name').value == '') {
		alert('You must enter your employer name');
		document.getElementById('employer_name').focus();
		return false;
	}
	
	if(document.getElementById('employer_address').value == '') {
		alert('You must enter your employer address');
		document.getElementById('employer_address').focus();
		return false;
	}
	
		if(document.getElementById('employer_state').value == '') {
		alert('You must enter your employer state');
		document.getElementById('employer_state').focus();
		return false;
	}

	if(document.getElementById('employer_city').value == '') {
		alert('You must enter your employer city');
		document.getElementById('employer_city').focus();
		return false;
	}
	
	if(document.getElementById('employer_zip').value == '') {
		alert('You must enter your employer zip');
		document.getElementById('employer_zip').focus();
		return false;
	}
	
	if(document.getElementById('feMail').value == '') {
		alert('You must enter your email');
		document.getElementById('feMail').focus();
		return false;
	}
	if(echeck1(document.getElementById('feMail').value) == false) {
		document.getElementById('feMail').value = "";
		document.getElementById('feMail').focus();
		return false;
	}

	if( (document.getElementById('work_phone1').value == '') || (document.getElementById('work_phone2').value == '') 
		|| (document.getElementById('work_phone3').value == '') ) {
		alert('You must enter your work phone number');
		document.getElementById('work_phone1').focus();
		return false;
	}
	if(validatePhone(workPhone) == false) {
		document.getElementById('work_phone1').value = "";
		document.getElementById('work_phone2').value = "";
		document.getElementById('work_phone3').value = "";
		document.getElementById('work_phone1').focus();
		return false;
	}

	if(document.getElementById('referred_by').value == '') {
		alert('You must enter the name of your referral');
		document.getElementById('referred_by').focus();
		return false;
	}
	
	if(document.getElementById('howlong').value == '') {
		alert('You must enter your how long time since start of complaint');
		document.getElementById('howlong').focus();
		return false;
	}

	if(document.getElementById('complaint').value == '') {
		alert('You must enter your complaint');
		document.getElementById('complaint').focus();
		return false;
	}
	return true;
}
//End of function validateInsurance

//Date validation function added by sarada
function isValidDate(dateStr) {
// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
// Also separates date into month, day, and year variables
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
// To require a 4 digit year entry, use this line instead:
// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert("Date is not in a valid format.")
return false;
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn't have 31 days!")
return false
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("February " + year + " doesn't have " + day + " days!");
return false;
}
}
return true;  // date is valid
}
//End of date validation code

