// JavaScript Document
function blood_form_check(blood_form) {
	if(blood_form.name.value == '') {
		alert("Please Write Your Name");
		blood_form.name.focus();
		return false;
	}
	if(blood_form.blood_group.value == 'All') {
		alert("Please Select Blood Group");
		blood_form.blood_group.focus();
		return false;
	}
	if(blood_form.address.value == '') {
		alert("Please Write Your Address");
		blood_form.address.focus();
		return false;
	}
	if(blood_form.district.value == "") {
		alert("Please Select District");
		blood_form.district.focus();
		return false;
	}
	if(blood_form.contactno.value == '') {
		alert("Please Write Your Contact Number");
		blood_form.contactno.focus();
		return false;
	}
	if(blood_form.user_id.value == "") {
		alert("Please Write Your User ID");
		blood_form.user_id.focus();
		return false;
	} else if (blood_form.user_id.value != "") {
		var valRegMail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if(!valRegMail.test(blood_form.user_id.value)) {
			alert("Must Write Your Correct Mail Address...");
			blood_form.user_id.focus();
			return false;
		}
	}
	if(blood_form.pwd.value == '') {
		alert("Please Write Your Password");
		blood_form.pwd.focus();
		return false;
	}
	if(blood_form.pwd.value != blood_form.confirm_pwd.value) {
		alert("Password Mathing Failed. Please Write Correct Password");
		blood_form.confirm_pwd.focus();
		return false;
	}
	return true;
}


function bloodUpdateFormCheck(blood_form) {
	if(blood_form.name.value == '') {
		alert("Please Write Your Name");
		blood_form.name.focus();
		return false;
	}
	//alert(blood_form.blood_group.value);
	if(blood_form.blood_group.value == "All") {
		alert("Please Select Blood Group");
		blood_form.blood_group.focus();
		return false;
	}
	if(blood_form.address.value == '') {
		alert("Please Write Your Address");
		blood_form.address.focus();
		return false;
	}
	if(blood_form.district.value == "") {
		alert("Please Select District");
		blood_form.district.focus();
		return false;
	}
	if(blood_form.contactno.value == '') {
		alert("Please Write Your Contact Number");
		blood_form.contactno.focus();
		return false;
	}
	if(blood_form.pwd.value == '') {
		alert("Please Write Your Password");
		blood_form.pwd.focus();
		return false;
	}
	if(blood_form.pwd.value != blood_form.confirm_pwd.value) {
		alert("Password Mathing Failed. Please Write Correct Password");
		blood_form.confirm_pwd.focus();
		return false;
	}
	return true;
}


function others_form_check(the_form) {
	if(the_form.name.value == '') {
		alert("Please Write Your Name");
		the_form.name.focus();
		return false;
	}
	if(the_form.services.value == '') {
		alert("Please Write Services");
		the_form.services.focus();
		return false;
	}
	if(the_form.address.value == '') {
		alert("Please Write Your Address");
		the_form.address.focus();
		return false;
	}
	if(the_form.district.value == 0) {
		alert("Please Select District");
		the_form.district.focus();
		return false;
	}
	if(the_form.contactno.value == '') {
		alert("Please Write Your Contact Number");
		the_form.contactno.focus();
		return false;
	}
	
	if(the_form.user_id.value == '') {
		alert("Please Write Your User ID");
		the_form.user_id.focus();
		return false;
	} else if (the_form.user_id.value != "") {
		var valRegMail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if(!valRegMail.test(the_form.user_id.value)) {
			alert("Must Write Your Correct Mail Address...");
			the_form.user_id.focus();
			return false;
		}
	}
	if(the_form.pwd.value == '') {
		alert("Please Write Your Password");
		the_form.pwd.focus();
		return false;
	}
	if(the_form.pwd.value != the_form.confirm_pwd.value) {
		alert("Password Mathing Failed. Please Write Correct Password");
		the_form.confirm_pwd.focus();
		return false;
	}
	return true;
}

//Online Consultancy Form Validation
function formOnlineConsultancy(theForm) {
	if(theForm.name.value=="") {
		alert("Must Write Your Name...");
		theForm.name.focus();
		return false;
	}
	if(theForm.age.value=="") {
		alert("Must Write Your Age...");
		theForm.age.focus();
		return false;
	}
	if(theForm.sex.value=="") {
		alert("Must Select Your Sex...");
		theForm.sex.focus();
		return false;
	}
	if(theForm.email.value == "") {
		alert("Must Write Your Mail Address...");
		theForm.email.focus();
		return false;
	} else if(theForm.email.value) {
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!(filter.test(theForm.email.value))) { 
			alert("Must Write Correct Mail Address...");
			theForm.email.focus();
			return false;
		}
	}
	if(theForm.message.value=="") {
		alert("Must Write Your Problem In Message Field...");
		theForm.message.focus();
		return false;
	}
	return true;
}

//Feedback Form Validation
function formFeedback(theForm) {
	if(theForm.name.value=="") {
		alert("Must Write Your Name...");
		theForm.name.focus();
		return false;
	}
	if(theForm.email.value == "") {
		alert("Must Write Your Mail Address...");
		theForm.email.focus();
		return false;
	} else if(theForm.email.value) {
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!(filter.test(theForm.email.value))) { 
			alert("Must Write Correct Mail Address...");
			theForm.email.focus();
			return false;
		}
	}
	if(theForm.subject.value=="") {
		alert("Must Write Subject...");
		theForm.subject.focus();
		return false;
	}
	if(theForm.message.value=="") {
		alert("Must Write Your Problem In Message Field...");
		theForm.message.focus();
		return false;
	}
	return true;
}

//Kidney Bank Form Validation
function formKidneyBank(theForm) {
	if(theForm.name.value=="") {
		alert("Must Write Your Name...");
		theForm.name.focus();
		return false;
	}
	if(theForm.age.value=="") {
		alert("Must Write Your Age...");
		theForm.age.focus();
		return false;
	}
	if(theForm.sex.value=="") {
		alert("Must Select Your Sex...");
		theForm.sex.focus();
		return false;
	}
	if(theForm.contact_no.value=="") {
		alert("Must Write Contact Number...");
		theForm.contact_no.focus();
		return false;
	}
	if(theForm.blood_group.value=="") {
		alert("Must Write Blood Group...");
		theForm.blood_group.focus();
		return false;
	}
	if(theForm.email.value == "") {
		alert("Must Write Your Mail Address...");
		theForm.email.focus();
		return false;
	} else if(theForm.email.value) {
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!(filter.test(theForm.email.value))) { 
			alert("Must Write Correct Mail Address...");
			theForm.email.focus();
			return false;
		}
	}
	if(theForm.address.value=="") {
		alert("Must Write Your Address...");
		theForm.address.focus();
		return false;
	}
	if(theForm.condition.value=="") {
		alert("Must Write Your Problem In Message Field...");
		theForm.condition.focus();
		return false;
	}
	return true;
}

function checkDoctorsReg(theform) {
	//Personal Info
	if(theform.name.value == ""){
		alert('Must Write Your Name');
		theform.name.focus();
		return false;
	}
	if(theform.fname.value == ""){
		alert('Must Write Your Fathers Name');
		theform.fname.focus();
		return false;
	}
	if(theform.presAddress.value == ""){
		alert('Must Write Your Present Address');
		theform.presAddress.focus();
		return false;
	}
	if(theform.district.value == ""){
		alert('Must Select Your District');
		theform.district.focus();
		return false;
	}
	if(theform.sex.value == ""){
		alert('Must Select Sex');
		theform.sex.focus();
		return false;
	}
	if(theform.cellphone.value == ""){
		alert('Must Write Your Cellphone Number');
		theform.cellphone.focus();
		return false;
	}
	if(theform.religion.value == ""){
		alert('Must Write Your Religion');
		theform.religion.focus();
		return false;
	}
	if(theform.speciality.value == 0){
		alert('Must Write Your Speciality');
		theform.speciality.focus();
		return false;
	}
	if(theform.education.value == ""){
		alert('Must Write Your Education');
		theform.education.focus();
		return false;
	}
	
	//User Checking
	if(theform.userID.value == ""){
		alert('Must Write Your User ID');
		theform.userID.focus();
		return false;
	} else if(theform.userID.value != ""){
		var valReg = /^[a-zA-Z0-9_]+$/;
		var valUserID = theform.userID.value;
		if(valUserID.length > 15) {
			alert('Must Write Within 15 Character');
			theform.userID.focus();
			return false;
		} else if(!valReg.test(theform.userID.value)) {
			alert('Must Write Correct User ID');
			theform.userID.focus();
			return false;
		}
	}
	
	if(theform.pwd.value == "" || theform.conPwd.value == ""){		
		alert('Must Write Your Password');
		theform.pwd.focus();
		return false;
	} else if(theform.pwd.value != theform.conPwd.value){		
		alert('Your Password Not Matches');
		theform.pwd.focus();
		return false;
	} 
/*
	if(theform.email.value == ""){
		alert('Must Write Your Email');
		theform.email.focus();
		return false;
	} else if(theform.email.value != ""){
		var valRegMail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if(!valRegMail.test(theform.email.value)) {
			alert("Must Write Your Correct Mail Address...");
			theform.email.focus();
			return false;
		}
	}
	if(theform.uploadPhoto.value == ""){
		alert('Must Upload Your Photo');
		theform.uploadPhoto.focus();
		return false;
	}
*/
	if(!theform.agree.checked){
		alert('Must Select Terms and Condition Checkbox');
		theform.agree.focus();
		return false;
	}
	
	return true;
}


function checkUpDoctorsReg(theform) {
	//Personal Info
	if(theform.name.value == ""){
		alert('Must Write Your Name');
		theform.name.focus();
		return false;
	}
	if(theform.fname.value == ""){
		alert('Must Write Your Fathers Name');
		theform.fname.focus();
		return false;
	}
	if(theform.presAddress.value == ""){
		alert('Must Write Your Present Address');
		theform.presAddress.focus();
		return false;
	}
	if(theform.district.value == ""){
		alert('Must Select Your District');
		theform.district.focus();
		return false;
	}
	if(theform.sex.value == ""){
		alert('Must Select Sex');
		theform.sex.focus();
		return false;
	}
	if(theform.cellphone.value == ""){
		alert('Must Write Your Cellphone Number');
		theform.cellphone.focus();
		return false;
	}
	if(theform.religion.value == ""){
		alert('Must Write Your Religion');
		theform.religion.focus();
		return false;
	}
	if(theform.speciality.value == 0){
		alert('Must Write Your Speciality');
		theform.speciality.focus();
		return false;
	}
	if(theform.education.value == ""){
		alert('Must Write Your Education');
		theform.education.focus();
		return false;
	}	
	
	if(theform.pwd.value == "" || theform.conPwd.value == ""){		
		alert('Must Write Your Password');
		theform.pwd.focus();
		return false;
	} else if(theform.pwd.value != theform.conPwd.value){		
		alert('Your Password Not Matches');
		theform.pwd.focus();
		return false;
	} 
/*
	if(theform.email.value == ""){
		alert('Must Write Your Email');
		theform.email.focus();
		return false;
	} else if(theform.email.value != ""){
		var valRegMail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if(!valRegMail.test(theform.email.value)) {
			alert("Must Write Your Correct Mail Address...");
			theform.email.focus();
			return false;
		}
	}
	if(theform.hidePhoto.value == ""){
		alert('Must Upload Your Photo');
		theform.uploadPhoto.focus();
		return false;
	}
*/
	if(!theform.agree.checked){
		alert('Must Select Terms and Condition Checkbox');
		theform.agree.focus();
		return false;
	}
	
	return true;
}

function checkDrRegForm (theform) {
	//Personal Info
	if(theform.name.value == ""){
		alert('Must Write Your Name');
		theform.name.focus();
		return false;
	}
	if(theform.address.value == ""){
		alert('Must Write Your Address');
		theform.address.focus();
		return false;
	}
	if(theform.contactno.value == ""){
		alert('Must Your Contact No');
		theform.contactno.focus();
		return false;
	}
	if(theform.profile.value == ""){
		alert('Must Upload Your Profile File');
		theform.profile.focus();
		return false;
	}
	if(!theform.agree.checked){
		alert('Must Checked Terms and Condition Checkbox');
		theform.agree.focus();
		return false;
	}
	
	return true;
}

function showCllID(callID){
	if (document.getElementById(callID).style.display == 'none')
		document.getElementById(callID).style.display = 'block';
	else
		document.getElementById(callID).style.display = 'none';
}



function addRowTraining(varIDClass) {
    // Declare variables 
    var elements, templateRow, rowCount, row, className, newRow, element, s, t;
    var BsIE = false;
    // Get and count all "tr" elements with class="row".  The last one will be
     // serve as a template. 
    if (!document.getElementsByTagName)
      return false; // DOM not supported 
    elements = document.getElementsByName(varIDClass);
    templateRow = null;
    rowCount = 0;
	//	alert(elements.length);
    for (i = 0; i < elements.length; i++) {
      row = elements.item(i);
      
      // Get the "class" attribute of the row. 
      className = null;
      if (row.getAttribute)
        className = row.getAttribute('class');
      if (className == null && row.attributes) {
        // getAttribute('class') always returns null on MSIE, and
         // row.attributes doesn't work on Firefox 1.0.  Go figure. 
        className = row.attributes['class'];
		BsIE=true;
      }
      
      // This is not one of the rows we're looking for.  Move along. 
      if (!BsIE && (className != varIDClass))
        continue;
	  else if (BsIE && (className.value != varIDClass))
        continue;
      
      // This *is* a row we're looking for. 
      templateRow = row;
      rowCount++;
    }
    if (templateRow == null)
      return false; // Couldn't find a template row. 
    
    // Make a copy of the template row 
    newRow = templateRow.cloneNode(true);

    // Change the form variables e.g. price[x] -> price[rowCount] 
    elements = newRow.getElementsByTagName("input");
    for (i = 0; i < elements.length; i++) {
      element = elements.item(i);
      s = null;
      s = element.getAttribute("name");
      if (s == null)
        continue;
      t = s.split("[");
      if (t.length < 2)
        continue;
      s = t[0] + "[" + rowCount.toString() + "]";
      element.setAttribute("name", s);
	  element.setAttribute("value", "");
    }
	elements = newRow.getElementsByTagName("select");
    for (i =0; i < elements.length; i++) {
      element = elements.item(i);
	  s = null;
      s = element.getAttribute("name");
	  //s = element.getAttribute("value");
	// alert (s);
      if (s == null)
        continue;
      t = s.split("[");
      if (t.length < 2)
        continue;
      s = t[0] + "[" + rowCount.toString() + "]";
     //element.setAttribute("name", "");
	  element.setAttribute("name", s);
	  element.setAttribute("value", "");
	//alert(s);
	  
    }
    
    // Add the newly-created row to the table 
    templateRow.parentNode.appendChild(newRow);
    return true;
}
