function popUp(URL,width,height){day=new Date();id=day.getTime();eval("page"+id+"=window.open(URL,'"+id+"', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width="+width+",height="+height+",left=126,top= 0');");}function popUpforuploader(URL,id,width,height){eval("page"+id+"=window.open(URL,'"+id+"', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=550,height=800,left = 126,top = 0');");}
function showdivs(divid){var element=document.getElementById(divid).style.display;if(element=='block')document.getElementById(divid).style.display='none';else document.getElementById(divid).style.display='block';}function taketootherpage(page){document.location=page;}function createCookie(name,value,days){if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires=";expires="+date.toGMTString();}else var expires="";document.cookie=name+"="+value+expires+";path=/";}function readCookie(name){var nameEQ=name+"=";var ca=document.cookie.split(';');
for(var i=0;i<ca.length;i++){var c = ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0) return c.substring(nameEQ.length,c.length);}return null;}function eraseCookie(name){createCookie(name,"",-1);}
function IsNumeric(sText){var ValidChars = "0123456789.";var IsNumber=true;var Char;for(i=0;i<sText.length&&IsNumber== true;i++){Char=sText.charAt(i);if(ValidChars.indexOf(Char)==-1){IsNumber=false;}}return IsNumber;}function trimAll( strValue){var objRegExp=/^(\s*)$/;if(objRegExp.test(strValue)){strValue=strValue.replace(objRegExp,'');if( strValue.length==0)return strValue;}objRegExp=/^(\s*)([\W\w]*)(\b\s*$)/;if(objRegExp.test(strValue)){strValue=strValue.replace(objRegExp,'$2');}return strValue;}function validateNotEmpty(strValue){var strTemp=strValue;strTemp=trimAll(strTemp);if(strTemp.length>0){return true;}return false;}function get_cookie(Name){var search=Name+"=";var returnvalue="";if(document.cookie.length>0){offset=document.cookie.indexOf(search);if(offset!=-1){offset+=search.length;end=document.cookie.indexOf(";", offset);if(end==-1)end=document.cookie.length;returnvalue=unescape(document.cookie.substring(offset,end))}}return returnvalue;}function pad_with_zeros(rounded_value,decimal_places){var value_string=rounded_value.toString();var decimal_location = value_string.indexOf(".");if(decimal_location==-1){decimal_part_length=0;value_string+=decimal_places >0?".":"";}else{decimal_part_length=value_string.length-decimal_location-1;}var pad_total=decimal_places- decimal_part_length;if(pad_total>0){for(var counter=1;counter<=pad_total;counter++) value_string += "0";}return value_string;}function round_decimals(original_number,decimals){var result1=original_number*Math.pow(10,decimals);
var result2=Math.round(result1);var result3=result2/Math.pow(10,decimals);return pad_with_zeros(result3,decimals);}
function showblocks(mydiv){document.getElementById('accountinfo').style.display='none';document.getElementById('shipnbill').style.display='none';document.getElementById('ordhistory').style.display='none';document.getElementById('mywishlist').style.display='none';document.getElementById(mydiv).style.display='block';}function showdescorreview(nam){document.getElementById('mydesc').style.display='none';document.getElementById('myreview').style.display='none';document.getElementById(nam).style.display='block';}function emptybox(name){document.getElementById(name).innerHTML='';}function cleanup(){document.getElementById('search-box-style').value="";}function showup(){var val=trimAll(document.getElementById('search-box-style').value);if(val==''){document.getElementById('search-box-style').value="Search";}}function checkifdeliveryopt(){if(document.getElementById('cost').value==''){alert("Select Delivery Option");return false;}}
function showdeliverycost(){if(document.getElementById('costopt').style.display=='none')document.getElementById('costopt').style.display='block';else if  (document.getElementById('costopt').style.display=='block'){document.getElementById('costopt').style.display='none';}}function showshowaddress(){document.getElementById('showaddress').style.display='block';}

function validatebillingddress(frm){

	var ischecked=false;if(document.getElementById('radiobuttonsame').checked==true)  {
checkputvalue(frm);
	ischecked=true;
}
else if(document.getElementById('radiobuttondiff').checked==true)ischecked=true;if(ischecked==false){alert("Select Billing Option");return false;}else return true;}
function popUpforuploader(URL,id,width,height){eval("page"+id+"=window.open(URL,'"+id+"', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=550,height=800,left = 126,top = 0');");}
function showopts(){
document.getElementById('subsopts').style.display='block';
}
function hideopts(){
document.getElementById('subsopts').style.display='none';
}

function showwhichinput(){
	
}

function showpupilinput(){
document.getElementById('pupilinput').style.display='block';
document.getElementById('tutorinput').style.display='none';
}
function showtutorinput(){
	document.getElementById('pupilinput').style.display='none';
document.getElementById('tutorinput').style.display='block';
}
/*function resetcost(){
 	document.getElementById("costid").value='';
	document.getElementById("cost").value='';
	document.getElementById("cost").value='';
	document.getElementById('resettext').style.display='none';
	document.getElementById('radio').checked=false;
 }*/
 

function WordCountDesc(fld) {
      var msgStr = "The maximum amount of words of 50 has been reached";
      var words = fld.value.split (/[\s{1,}]/);
      document.getElementById('wordcntdesc').innerHTML = 'Count of words ' + words.length;
      if (words.length >= 50) { alert (msgStr); }
}
function WordCountKey(fld) {
      var msgStr = "The maximum amount of words of 50 has been reached";
      var words = fld.value.split (/[\s{1,}]/);
      document.getElementById('wordcntkey').innerHTML = 'Count of words ' + words.length;
      if (words.length >= 50) { alert (msgStr); }
}
    function CharactercountCount(fld) {
               var msgStr = "The maximum amount of characters of 255 has been reached";
               var letters = fld.value;
			    document.getElementById('titlecntchar').innerHTML = 'Count of characters ' + letters.length;
               if (letters.length == 255) { alert (msgStr); }
}

function DisplayFormValues(formname)
{

var str = '';

var elem = document.getElementById(formname).elements;

	for(var i = 0; i < elem.length; i++)
	{
		//var formname='form1';
		var elemname=elem[i];
		var thisvalue=elem[i].value
		if (thisvalue!=''){
			forminput=myfunc(thisvalue);
			if (forminput==false)
			return forminput;
		}
	}
	return forminput;
}
function strtolower( str ) {


var returnvar=str.toLowerCase();

    return returnvar;
	
}

function myfunc(myval)
{
	var iChars = "%#^&+=[]\';/{}\":<>?";
	var scriptcarstart="<script>";
	var scriptcar="</script>";
	var objectcarstart="<object>";
	var objectcarend="</object>";
	var embedstart="<embed>";
	var embedend="</embed>";
	var alertvar="alert";


    for (var i = 0; i < myval.length; i++) {
  		if (iChars.indexOf(myval.charAt(i)) != -1) 
  		{
  			alert("Containts special characters. \n These are not allowed.\n Please remove them and try again.");
			 inputstate=false;
			 return false;
  		}
	 }	
	 var lowermyval=strtolower( myval );

	 if (lowermyval.indexOf(scriptcar) != -1) 
  		{
  			alert("Wrong Type input");
			 inputstate=false;
			 return false;
  		}
	 if (lowermyval.indexOf(scriptcar) != -1) 
  		{
  			alert("Wrong Type input");
			 inputstate=false;
			 return false;
  		}
	 if (lowermyval.indexOf(objectcarstart)  != -1) 
  		{
  			alert("Wrong Type input");
			 inputstate=false;
			 return false;
  		}
	 if (lowermyval.indexOf(objectcarend) != -1) 
  		{
  			alert("Wrong Type input");
			 inputstate=false;
			 return false;
  		}
		
	 if (lowermyval.indexOf(embedstart) != -1) 
  		{
  			alert("Wrong Type input");
			 inputstate=false;
			 return false;
  		}
	 if (lowermyval.indexOf(embedend) != -1) 
  		{
  			alert("Wrong Type input");
			 inputstate=false;
			 return false;
  		}

/*var aPosition = lowermyval.indexOf(alertvar);
alert(aPosition);*/

	 if (lowermyval.indexOf(alertvar) != -1) 
  		{
  			alert("Wrong Type input");
			 inputstate=false;
			 return false;
  		}
	 return true;
 }
function qryHowOld(todaydateinput, birthdateinput)
   {

		var asofdtarr=todaydateinput.split("-");
		var birthdatearr=birthdateinput.split("-");
		
		varAsOfDate=Date.UTC(asofdtarr[0],asofdtarr[1],asofdtarr[2],0,0,0);
		varBirthDate=Date.UTC(birthdatearr[0],birthdatearr[1],birthdatearr[2],0,0,0);
		//varAsOfDate=Date.UTC(2009,06,13,0,0,0);
		//varBirthDate=Date.UTC(1983,08,11,0,0,0);
   var dtAsOfDate;
   var dtBirth;
   var dtAnniversary;
   var intSpan;
   var intYears;
   var intMonths;
   var intWeeks;
   var intDays;
   var intHours;
   var intMinutes;
   var intSeconds;
   var strHowOld;

   // get born date
   dtBirth = new Date(varBirthDate);
   
   // get as of date
   dtAsOfDate = new Date(varAsOfDate);

   // if as of date is on or after born date
   if ( dtAsOfDate >= dtBirth )
      {

      // get time span between as of time and birth time
      intSpan = ( dtAsOfDate.getUTCHours() * 3600000 +
                  dtAsOfDate.getUTCMinutes() * 60000 +
                  dtAsOfDate.getUTCSeconds() * 1000    ) -
                ( dtBirth.getUTCHours() * 3600000 +
                  dtBirth.getUTCMinutes() * 60000 +
                  dtBirth.getUTCSeconds() * 1000       )

      // start at as of date and look backwards for anniversary 

      // if as of day (date) is after birth day (date) or
      //    as of day (date) is birth day (date) and
      //    as of time is on or after birth time
      if ( dtAsOfDate.getUTCDate() > dtBirth.getUTCDate() ||
           ( dtAsOfDate.getUTCDate() == dtBirth.getUTCDate() && intSpan >= 0 ) )
         {

         // most recent day (date) anniversary is in as of month
         dtAnniversary = 
            new Date( Date.UTC( dtAsOfDate.getUTCFullYear(),
                                dtAsOfDate.getUTCMonth(),
                                dtBirth.getUTCDate(),
                                dtBirth.getUTCHours(),
                                dtBirth.getUTCMinutes(),
                                dtBirth.getUTCSeconds() ) );

         }

      // if as of day (date) is before birth day (date) or
      //    as of day (date) is birth day (date) and
      //    as of time is before birth time
      else
         {

         // most recent day (date) anniversary is in month before as of month
         dtAnniversary = 
            new Date( Date.UTC( dtAsOfDate.getUTCFullYear(),
                                dtAsOfDate.getUTCMonth() - 1,
                                dtBirth.getUTCDate(),
                                dtBirth.getUTCHours(),
                                dtBirth.getUTCMinutes(),
                                dtBirth.getUTCSeconds() ) );

         // get previous month
         intMonths = dtAsOfDate.getUTCMonth() - 1;
         if ( intMonths == -1 )
            intMonths = 11;

         // while month is not what it is supposed to be (it will be higher)
         while ( dtAnniversary.getUTCMonth() != intMonths )

            // move back one day
            dtAnniversary.setUTCDate( dtAnniversary.getUTCDate() - 1 );

         }

      // if anniversary month is on or after birth month
      if ( dtAnniversary.getUTCMonth() >= dtBirth.getUTCMonth() )
         {

         // months elapsed is anniversary month - birth month
         intMonths = dtAnniversary.getUTCMonth() - dtBirth.getUTCMonth();

         // years elapsed is anniversary year - birth year
         intYears = dtAnniversary.getUTCFullYear() - dtBirth.getUTCFullYear();

         }

      // if birth month is after anniversary month
      else
         {

         // months elapsed is months left in birth year + anniversary month
         intMonths = (11 - dtBirth.getUTCMonth()) + dtAnniversary.getUTCMonth() + 1;

         // years elapsed is year before anniversary year - birth year
         intYears = (dtAnniversary.getUTCFullYear() - 1) - dtBirth.getUTCFullYear();

         }

      // to calculate weeks, days, hours, minutes and seconds
      // we can take the difference from anniversary date and as of date

      // get time span between two dates in milliseconds
      intSpan = dtAsOfDate - dtAnniversary;

      // get number of weeks
      intWeeks = Math.floor(intSpan / 604800000);

      // subtract weeks from time span
      intSpan = intSpan - (intWeeks * 604800000);
      
      // get number of days
      intDays = Math.floor(intSpan / 86400000);

      // subtract days from time span
      intSpan = intSpan - (intDays * 86400000);

      // get number of hours
      intHours = Math.floor(intSpan / 3600000);
    
      // subtract hours from time span
      intSpan = intSpan - (intHours * 3600000);

      // get number of minutes
      intMinutes = Math.floor(intSpan / 60000);

      // subtract minutes from time span
      intSpan = intSpan - (intMinutes * 60000);

      // get number of seconds
      intSeconds = Math.floor(intSpan / 1000);

      // create output string     
      if ( intYears > 0 )
         if ( intYears > 1 )
            strHowOld = intYears.toString() + ' Years';
         else
            strHowOld = intYears.toString() + ' Year';
      else
         strHowOld = '';

      if ( intMonths > 0 )
         if ( intMonths > 1 )
            strHowOld = strHowOld + ' ' + intMonths.toString() + ' Months';
         else
            strHowOld = strHowOld + ' ' + intMonths.toString() + ' Month';
           
      if ( intWeeks > 0 )
         if ( intWeeks > 1 )
            strHowOld = strHowOld + ' ' + intWeeks.toString() + ' Weeks';
         else
            strHowOld = strHowOld + ' ' + intWeeks.toString() + ' Week';

      if ( intDays > 0 )
         if ( intDays > 1 )
            strHowOld = strHowOld + ' ' + intDays.toString() + ' Days';
         else
            strHowOld = strHowOld + ' ' + intDays.toString() + ' Day';

      if ( intHours > 0 )
         if ( intHours > 1 )
            strHowOld = strHowOld + ' ' + intHours.toString() + ' Hours';
         else
            strHowOld = strHowOld + ' ' + intHours.toString() + ' Hour';
 
      if ( intMinutes > 0 )
         if ( intMinutes > 1 )
            strHowOld = strHowOld + ' ' + intMinutes.toString() + ' Minutes';
         else
            strHowOld = strHowOld + ' ' + intMinutes.toString() + ' Minute';

      if ( intSeconds > 0 )
         if ( intSeconds > 1 )
            strHowOld = strHowOld + ' ' + intSeconds.toString() + ' Seconds';
         else
            strHowOld = strHowOld + ' ' + intSeconds.toString() + ' Second';

      }
   else
      strHowOld = 'Not Born Yet'

   // return string representation
   return strHowOld
   }   

