
// JavaScript Document
function confirmMsg(msg)
{
	if(!confirm(msg))
	{
		return false;
	} 
	else 
	{
		return true;
	}
}
function calldel(a)
{

	if(!confirm(a))
	{
		return false;
	}
	else
	return true;
}

function showprice(){
		if (document.addtemplate.tmpshowprice[1].checked){
		ap1=document.getElementById("showtempprice");
		    if(ap1){
			ap1.style.display="block";
			ap1.style.visibility="visible";
				}				
		}
		else
		{
			ap1=document.getElementById("showtempprice");
			if(ap1){
			ap1.style.display="none";
			ap1.style.visibility="hidden";
				}
		}
}

function poplinks(url)
{
	newwindow=window.open(url,'ImageDisplay','height=500,width=800,left=0,top=0,resizable=yes,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}


function login_validate()
{
	     var txtusername = document.login.txtusername.value;
		 if (txtusername == "" )
		 { 
			 alert ("Please enter Your Username");
			 document.login.txtusername.focus();
			 return false;
		 }
		 var txtpassword = document.login.txtpassword.value;
		 if (txtpassword == "" )
		 { 
			 alert ("Please enter Your Password");
			 document.login.txtpassword.focus();
			 return false;
		 }	
		 
}


function validateEmail(addr,man,db) {
	if (addr == '' && man) {
	   if (db) alert('Email address is mandatory');
	   return false;
	}
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  if (db) alert('Email address contains invalid characters');
		  return false;
	   }
	}
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  if (db) alert("Email address contains non ascii characters.");
		  return false;
	   }
	}
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   if (db) alert('Email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   if (db) alert('Email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   if (db) alert('Email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   if (db) alert('Email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   if (db) alert('period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   if (db) alert('period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	   if (db) alert('two periods must not be adjacent in email address');
	   return false;
	}
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   if (db) alert('invalid primary domain in email address');
	   return false;
	}
return true;
}

//script validation for date 
function date_valid(dateissue,dateissue2){
	var stdate=dateissue.split("/");
	var enddate=dateissue2.split("/");
	var prostdate = new Date();
	prostdate.setFullYear(stdate[2]);
	prostdate.setMonth(stdate[0]-1);
	prostdate.setDate(stdate[1]);
	
	var proenddate = new Date();
	proenddate.setFullYear(enddate[2]);
	proenddate.setMonth(enddate[0]-1);
	proenddate.setDate(enddate[1]);
	
	var startingdate = prostdate.getTime();
	var endingdate = proenddate.getTime();

	if(startingdate > endingdate)
	{
		return false;
	}
	return true;
}



function myprofile_validate()
{
   if (document.frm_myprofile.txt_contactperson.value== "" )
	{ 
			 alert ("Please enter the Person");
			 document.frm_myprofile.txt_contactperson.focus();
			 return false;
    }
	var txt_email = document.frm_myprofile.txt_email.value;
	 if (txt_email == "")
	 { 
		 alert ("Please enter the Email Address");
		 document.frm_myprofile.txt_email.focus();
		 return false;
	 }	
	if (!validateEmail(document.frm_myprofile.txt_email.value,1,1)) 
	 {
		 document.frm_myprofile.txt_email.focus();
		 return false;
	 }
	
	var txt_phone = document.frm_myprofile.txt_phone.value;
	 if (txt_phone == "")
	 { 
		 alert ("Please enter the Business Phone Number");
		 document.frm_myprofile.txt_phone.focus();
		 return false;
	 }	
	  phone = document.frm_myprofile.txt_phone;
		if (checkInternationalPhone(phone.value)==false){
			alert("Please Enter a Valid Phone Number")
			phone.value=""
			phone.focus()
			return false
			}
	   var txt_username = document.frm_myprofile.txt_username.value;
		 if (txt_username == "" )
		 { 
			 alert ("Please enter Your Username");
			 document.frm_myprofile.txt_username.focus();
			 return false;
		 }
		 var txtpassword = document.frm_myprofile.txt_password.value;
		 if (txtpassword == "" )
		 { 
			 alert ("Please enter Your Password");
			 document.frm_myprofile.txt_password.focus();
			 return false;
		 }
}



function generalsetting_validate()
{   
     if (document.frm_general.txt_website.value == "") 
		{
			alert ("Please Enter the Website URL.");
			document.frm_general.txt_website.focus();
			return false;
		}
    var txt_numrows = document.frm_general.txt_numrows.value;
	if (txt_numrows == "")
	 { 
		 alert ("Please enter the No Of Rows Displayed Per Page in Adminpanel");
		 document.frm_general.txt_numrows.focus();
		 return false;
	 }	
	 if (isNaN(document.frm_general.txt_numrows.value))
	 { 
		 alert ("No Of Rows Displayed Per Page in Adminpanel must be numeric");
		 document.frm_general.txt_numrows.focus();
		 return false;
	 }
	 var txtnumrowsfront = document.frm_general.txtnumrowsfront.value;
	 if (txtnumrowsfront == "")
	 { 
		 alert ("Please enter the No Of Rows Displayed Per Page in Frontpanel");
		 document.frm_general.txtnumrowsfront.focus();
		 return false;
	 }	
	 if (isNaN(document.frm_general.txtnumrowsfront.value))
	 { 
		 alert ("No Of Rows Displayed Per Page in Frontpanel must be numeric");
		 document.frm_general.txtnumrowsfront.focus();
		 return false;
	 }
	 var txt_admintitle = document.frm_general.txt_admintitle.value;
		 if (txt_admintitle == "" )
		 { 
			 alert ("Please enter Your Admintitle");
			 document.frm_general.txt_admintitle.focus();
			 return false;
		 }
		 var txt_hometitle = document.frm_general.txt_hometitle.value;
		 if (txt_hometitle == "" )
		 { 
			 alert ("Please enter Your Hometitle");
			 document.frm_general.txt_hometitle.focus();
			 return false;
		 }
}



function cms_validate()
{
	
    var pagetitle = document.frm_cms.pagetitle.value;
		 if (pagetitle == "" )
		 { 
			 alert ("Please enter the Page Title");
			 document.frm_cms.pagetitle.focus();
			 return false;
		 }
		    
}

function class_validate()
{
	
    var txtclassname = document.frm_class.txtclassname.value;
		 if (txtclassname == "" )
		 { 
			 alert ("Please enter the class name");
			 document.frm_class.txtclassname.focus();
			 return false;
		 }
	 var txtorder = document.frm_class.txtorder.value;
		 if (txtorder == "" )
		 { 
			 alert ("Please enter the class order");
			 document.frm_class.txtorder.focus();
			 return false;
		 }
	 if (isNaN(document.frm_class.txtorder.value))
	 { 
		 alert ("Class order must be numeric");
		 document.frm_class.txtorder.focus();
		 return false;
	 }
		   
	 var txtsession = document.frm_class.txtsession.value;
		 if (txtsession == "" )
		 { 
			 alert ("Please enter the Sessions / Classes");
			 document.frm_class.txtsession.focus();
			 return false;
		 }
		   
	 var txtages = document.frm_class.txtages.value;
		 if (txtages == "" )
		 { 
			 alert ("Please enter the Ages");
			 document.frm_class.txtages.focus();
			 return false;
		 }
		   
	 var txtcurriculum = document.frm_class.txtcurriculum.value;
		 if (txtcurriculum == "" )
		 { 
			 alert ("Please enter the curriculum");
			 document.frm_class.txtcurriculum.focus();
			 return false;
		 }
	 var txthomematerials1 = document.frm_class.txthomematerials1.value;
		 if (txthomematerials1 == "" )
		 { 
			 alert ("Please enter the home materials");
			 document.frm_class.txthomematerials1.focus();
			 return false;
		 }
	 var txtclasslength = document.frm_class.txtclasslength.value;
		 if (txtclasslength == "" )
		 { 
			 alert ("Please enter the class length");
			 document.frm_class.txtclasslength.focus();
			 return false;
		 }
	var txtsemesterfee = document.frm_class.txtsemesterfee.value;
		 if (txtsemesterfee == "" )
		 { 
			 alert ("Please enter the semester fee");
			 document.frm_class.txtsemesterfee.focus();
			 return false;
		 }
	var txtsiblingfee = document.frm_class.txtsiblingfee.value;
		 if (txtsiblingfee == "" )
		 { 
			 alert ("Please enter the sibling fee");
			 document.frm_class.txtsiblingfee.focus();
			 return false;
		 }
		    
}





//Script validation for displaying the City list in the given state
var lists = new Array();
var deliverytype = new Array();


function emptyList( box ) 
{
	while ( box.options.length ) box.options[0] = null;
}

function fillList( box, arr ) 
{
	for ( i = 0; i < arr[0].length; i++ ) 
	{
		option = new Option( arr[0][i], arr[0][i+1] );
		box.options[box.length] = option;
		i=i+1;
	}
	box.selectedIndex=0;
}


function changeList(box) 
{
	list = lists[box.options[box.selectedIndex].value];
	DeliveryTp = deliverytype[box.options[box.selectedIndex].value];
	
	if(box.options[box.selectedIndex].value != "select" && box.options[box.selectedIndex].value != "choose")
	{
		emptyList(box.form.subject);
		fillList(box.form.subject, list );
	}
/*	//alert(DeliveryTp);
	if (DeliveryTp == "Hours"){
		ap1=document.getElementById("showdelhours");
		    if(ap1){
			ap1.style.display="block";
			ap1.style.visibility="visible";
			}
			ap2=document.getElementById("showdeldays");
			if(ap2){
			ap2.style.display="none";
			ap2.style.visibility="hidden";
			}
		}
		else
		{
			ap1=document.getElementById("showdelhours");
			if(ap1){
			ap1.style.display="none";
			ap1.style.visibility="hidden";
			}
			ap2=document.getElementById("showdeldays");
			if(ap2){
			ap2.style.display="block";
			ap2.style.visibility="visible";
			}
		}
*/}
//Function phone validation Script
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
function ChangeURL(Goalcat)
{
	window.location.href = "index.php?task=viewdefaultgoal&go=goals&goalcat="+Goalcat;
}
function Changes(Coachcat)
{
	window.location.href = "index.php?task=viewcoaching&go=coaching&coachcat="+Coachcat;
}
function Change(Videocat)
{
	window.location.href = "index.php?task=view_videos&go=video&Videocat="+Videocat;
}

function change(Packcat)
{
	window.location.href = "index.php?task=viewuser&go=user&Packcat="+Packcat;
}

function changes(Articlecat)
{
	window.location.href = "index.php?task=viewarticle&go=articles&Articlecat="+Articlecat;
}
/*function news_validate()
{
currentdate= new Date();
	curmonth = currentdate.getMonth() + 1;
	var curdate =  curmonth + "/" + currentdate.getDate() + "/" + currentdate.getFullYear();		
	if (!date_valid(curdate,document.frm_class.classdate.value)) 
	{
			alert ("Choose the class date greater than the today's date in date picker.");
			document.frm_class.classdate.value == "";
			document.frm_class.classdate.focus();
			return false;
	}
	if (!date_valid(curdate,document.frm_class.classdate.value)) 
	{
			alert ("Choose the class date greater than the today's date in date picker.");
			document.frm_class.classdate.value == "";
			document.frm_class.classdate.focus();
			return false;
	}
	
}*/
//Add Image Validation
function addimg_validate(){
		if (document.addimage.filename.value == "") 
		{
				alert ("File URL is empty.Click the browse button to upload an image");
				document.addimage.filename.focus();
				return false;
		}
		
}