﻿function ClearContent(id)
{
   var DivHardCopy=document.getElementById("ctl00_ContentMain_divHardCopy");
   var DivCourier=document.getElementById("ctl00_ContentMain_divCourier");
   var divpayment=document.getElementById("ctl00_ContentMain_PaymentServices");
   var root=document.getElementById(id);
   var el=root.getElementsByTagName("input"); 
   var el1=root.getElementsByTagName("select");
   var len=el.length;
   var len1=el1.length;
   for(var i=0;i<len1;i++)
   {
    el1[i].selectedIndex=0;
    el1[i].style.backgroundColor="#ffffff";
   }
   for(var j=0;j<len;j++)
   {
     var type=el[j].getAttribute("type");
     if(type=="text")
     {
      el[j].value="";
      el[j].style.backgroundColor="#ffffff";
     }
     if(type=="radio")
     {
        el[j].checked=false;
     }
     if(type=="checkbox")
     {
        el[j].checked=false;
     }
   }
   DivCourier.style.display="none";
   DivHardCopy.style.display="none";
   divpayment.style.display="none";
   message="";
}
function ClearContentCommon(id)
{
   var root=document.getElementById(id);
   var el=root.getElementsByTagName("input"); 
   var el1=root.getElementsByTagName("select");
   var len=el.length;
   var len1=el1.length;
   for(var i=0;i<len1;i++)
   {
    el1[i].selectedIndex=0;
   }
   for(var j=0;j<len;j++)
   {
     var type=el[j].getAttribute("type");
     if(type=="text")
     {
      el[j].value="";
     }
     if(type=="radio")
     {
        el[j].checked=false;
     }
     if(type=="checkbox")
     {
        el[j].checked=false;
     }
   }
  
}

 function printRecords(id)
{
	 var br=navigator.appVersion;
     var a = window.open ('','','left =' + (screen.width)/2 + ',top=' + screen.height + ',width=0,height=0,toolbar=0,scrollbars=0,status=0');
	 var TarEl=document.getElementById(id).innerHTML;
     if(br.indexOf("MSIE 7.0")>=0)
     {
       window.print(TarEl);
     }
     else
     {
        a.document.write(TarEl);
	    a.document.close();
	    a.focus();
	    a.print();
	    a.close();
     }
	
	 return true;
}

function CheckForm(id)
{
   var isCorrect=true;
   var message="";
   var DivCourier=document.getElementById("ctl00_ContentMain_divHardCopy");
   var cash=document.getElementById("ctl00_ContentMain_rdCash");
   var dd=document.getElementById("ctl00_ContentMain_rdDraft");
   var cc=document.getElementById("ctl00_ContentMain_rdCreditCard");
   var divService=document.getElementById("ctl00_ContentMain_PaymentServices");
   var root=document.getElementById(id);
   var el=root.getElementsByTagName("input"); 
   var el1=root.getElementsByTagName("select");
   var len=el.length;
   var len1=el1.length;
   var mail= /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
   var num=/^\d+$/;
   var dec= /^[-+]?\d{1,3}(\.\d{1,2})?$/;
  
   for(var j=0;j<len1;j++)
   {
    var title=el1[j].getAttribute("title");
    var id=el1[j].id;
    var selVal=el1[j].value;
     var blank =el1[j].getAttribute("blank");
        if(selVal.indexOf("Select")>=0 && blank=="1" )
        {   
            document.getElementById(id).style.backgroundColor="lightyellow";
            el1[j].style.backgroudColor="lightyellow";
            message+="Please select the "+title+" from the list; ";
            isCorrect=false;
        }
        else
        {
           document.getElementById(id).style.backgroundColor="#ffffff";
        }
   }
   
   for(var i=0;i<len;i++)
   {
       var type=el[i].getAttribute("type");
       var title=el[i].getAttribute("title");
        if(type=="text")
        {
         var blank =el[i].getAttribute("blank");
         var att=el[i].getAttribute("mail");
         var att1=el[i].getAttribute("num");
         var att2=el[i].getAttribute("dec");
          var id=el[i].id;
          if(blank==1 && el[i].value=="" && att==null && att1==null )
          {
             
               document.getElementById(id).style.backgroundColor="lightyellow";
               message+="Please fill the "+title+" ;";
               isCorrect=false;
          }  
          else if(att==1)
          {
             if(blank==1)
              {
                  if(el[i].value=="")
                  {
                     el[i].style.backgroundColor="lightyellow";
                     message+="Please fill the "+title+" ;";
                     isCorrect=false;
                  }
                  else if(!mail.test(el[i].value))
                  {
                     el[i].style.backgroundColor="lightyellow";
                     message+="Please enter the valid email address in "+title+" ;";
                     isCorrect=false; 
                  }
                  else
                  {
                     el[i].style.backgroundColor="#ffffff";
                  }  
              }
              else
              {
                if(!mail.test(el[i].value) && el[i].value!="")
                  {
                    
                     el[i].style.backgroundColor="lightyellow";
                     message+="Please enter the valid email address in "+title+" ;";
                     isCorrect=false;;
                  }
                  else
                  {
                    el[i].style.backgroundColor="#ffffff";
                  }  
              }
            
          }
          else if(att1==1)
          {
             if(blank==1)
              {
                  if(el[i].value=="")
                  {
                     el[i].style.backgroundColor="lightyellow";
                     message+="Please fill the "+title+" ;";
                     isCorrect=false;
                  }
                  else if(!num.test(el[i].value))
                  {
                     el[i].style.backgroundColor="lightyellow";
                     message+="Please enter the numeric value only in "+title+" ;";
                     isCorrect=false; 
                  }
                  else
                  {
                     el[i].style.backgroundColor="#ffffff";
                  }  
              }
              else
              {
                if(!num.test(el[i].value) && el[i].value!="")
                  {
                    
                     el[i].style.backgroundColor="lightyellow";
                     message+="Please enter the numeric value  only in "+title+" ;";
                     isCorrect=false;;
                  }
                  else
                  {
                     el[i].style.backgroundColor="#ffffff";
                  }  
              }
            
          }
           else if(att2==1)
          {
             if(blank==1)
              {
                  if(el[i].value=="")
                  {
                     el[i].style.backgroundColor="lightyellow";
                     message+="Please fill the "+title+" ;";
                     isCorrect=false;
                  }
                  else if(!dec.test(el[i].value))
                  {
                     el[i].style.backgroundColor="lightyellow";
                     message+="Please enter the numeric/decimal value only in "+title+" ;";
                     isCorrect=false; 
                  }
                  else
                  {
                     el[i].style.backgroundColor="#ffffff";
                  }  
              }
              else
              {
                if(!dec.test(el[i].value) && el[i].value!="")
                  {
                    
                     el[i].style.backgroundColor="lightyellow";
                     message+="Please enter the numeric/decimal value  only in "+title+" ;";
                     isCorrect=false;;
                  }
                  else
                  {
                     el[i].style.backgroundColor="#ffffff";
                  }  
              }
            
          }
          else
          {
             document.getElementById(id).style.backgroundColor="#ffffff";
          }
      }
      if(type=="checkbox")
        {
          if(el[i].checked==false)
          {
              el[i].style.backgroudColor="lightyellow";
              message+="Please accept the Terms & Conditions; ";
              isCorrect=false;
          }
        }
    }
    
   if(DivCourier.style.display=="block")
    {
      var yes=document.getElementById("ctl00_ContentMain_rdYes");
      var No=document.getElementById("ctl00_ContentMain_rdNo");
      if(yes.checked==false && No.checked==false)
      {
        message+="Please select the option of hardcopy; ";
        isCorrect=false;
      }  
    }
    if(cash.checked==false && dd.checked==false && cc.checked==false)
    {
          message+="Please select the payment option;";
          isCorrect=false;
    }
    if(divService.style.display=="block")
    {
       var ccav=document.getElementById("ctl00_ContentMain_rdCCAvenue");
       var ppl=document.getElementById("ctl00_ContentMain_rdPayPal"); 
       if(ppl.checked==false && ccav.checked==false)
       {
          message+="Please select the payment services;";
          isCorrect=false;
       }
       else
       {
          if(document.getElementById("ctl00_ContentMain_rdPayPal").checked==true)
          {
           var ddlcurrency=document.getElementById("ctl00_ContentMain_ddlCurrency");
           if(ddlcurrency.selectedIndex==0)
           {
              message+="Please select the currency type;";
              isCorrect=false;
           }
          }
       }
    }
   
   if(isCorrect==false)
   {
      alert(message);
   }
 
   return  isCorrect;
}

function CalculateCurrency(id,id1,id2)
{
    var ddl=document.getElementById(id);
    var fee=0;
    var rate=0;
    if(document.getElementById(id1).value!="")
    {
       fee=parseFloat(document.getElementById(id1).value);
    }
    if(ddl.selectedIndex>0)
    {
        rate=parseFloat(ddl.value);
        document.getElementById(id2).innerHTML=rate*fee;
    }
    else
    {
         document.getElementById(id2).innerHTML=0;
    }
    
}
function CheckCourseSelect(id)
{
   var container=document.getElementById(id);
   var list=container.getElementsByTagName('input');
   var list1=container.getElementsByTagName('select');
   var len=list.length;
   var att,count;
   var mes="";
   var num=0;
   for(var i=0;i<len;i++)
   {
   
     att=list[i].getAttribute('type');
     if(att=='checkbox')
     {
       
        if(list[i].checked==true)
        {      
                num+=1;
                var str="chkSelect";
                var strLen=str.length;
                var fulllen=list[i].id.length;
                var resLen=fulllen-strLen;
                var getid=list[i].id.substring(0,resLen)
                var resId=getid+"ddlBranch";
                var reqid=document.getElementById(resId);
                if(reqid)
                {
                    if(document.getElementById(resId).selectedIndex==0)
                    {
                       alert("Please select the location");
                       count=0;
                    }
                    else
                    {
                         count=1;
                    }
                }
                else
                {
                    count=1;
                }
        }
     }   
   }
      if(num==0)
      {
        alert("Please select the desired course");
        return false;
      }
     if(num==1)
      {
         
         if(count==0)
           {
            return false;
           
           } 
           if(count>0)
           {
             return true;
           }
      }
      else if(num>1)
      {
        alert("You can select only one course at a time");
        return false;
      }
  
}
function displayCurrency(id,id1)
{
    var idstatus=document.getElementById(id);
    if(idstatus.checked==true)
    {
   
       document.getElementById(id1).style.display="block";
    }
    else
    {
         document.getElementById(id1).style.display="none";
         document.getElementById("ctl00_ContentMain_ddlCurrency").selectedIndex=0;
         document.getElementById("ctl00_ContentMain_lblCurrencyVal").innerHTML=0;
    }
}
function DisplayServices(id,id1)
{
   if(id.indexOf("rdCreditCard")>0)
   {
     document.getElementById(id1).style.display="block";
   }
   else
   {
     document.getElementById(id1).style.display="none";
     var ele=document.getElementById(id1).getElementsByTagName("input");
   
     var len=ele.length;
     for(var i=0;i<len;i++)
     {
        var type=ele[i].getAttribute("type");
        if(type=="radio")
        {
         ele[i].checked=false;
        }
     }
   }
} 

function displayDiv(id,id1)
{
   var val=document.getElementById(id).value;
   var tardiv= document.getElementById(id1);
   if(val=="India")
   {
      tardiv.style.display="none";  
   }
   else
   {
     tardiv.style.display="block";  
   }
}
function DisplayCharges(id,id1)
{
   var tardiv= document.getElementById(id1);
   
   if(id.indexOf("rdYes")>0)
   {
     tardiv.style.display="block"; 
   }
   else
   {
      tardiv.style.display="none";  
   }  
}

function ValidateKeyPress(id)
{
    var tar=document.getElementById(id);
    var type=tar.getAttribute("type");
    var mail= /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
    var num=/^\d+$/;
    var dec= /^[-+]?\d{1,3}(\.\d{1,2})?$/;
    var att=tar.getAttribute("mail");
    var att1=tar.getAttribute("num");
    var att2=tar.getAttribute("dec");
    var blank=tar.getAttribute("blank");
    if(type=="select")
    {
        var str=tar.value.substr(1,3);
        if(str=="Sel")
        {
          tar.style.backgroundColor="lightyellow";
        }
        else
        {
            tar.style.backgroundColor="#ffffff";
        }
    }
   else if(blank==1 && att==null && att1==null && att2==null)
   {
     if(tar.value=="")
      {
        tar.style.backgroundColor="lightyellow";
      }
      else
      {
        tar.style.backgroundColor="#ffffff";
      }  
   }
   else if(att==1)
    {
      if(blank==1)
      {
          if(tar.value=="" || !mail.test(tar.value))
          {
            tar.style.backgroundColor="lightyellow";
          }
          else
          {
            tar.style.backgroundColor="#ffffff";
          }  
      }
      else
      {
        if(!mail.test(tar.value))
          {
            tar.style.backgroundColor="lightyellow";
          }
          else
          {
            tar.style.backgroundColor="#ffffff";
          }  
      }
    }
    else if(att1==1)
    {
      if(blank==1)
      {
          if(tar.value=="" || !num.test(tar.value))
          {
            tar.style.backgroundColor="lightyellow";
          }
          else
          {
            tar.style.backgroundColor="#ffffff";
          }  
      }
      else
      {
        if(!num.test(tar.value))
          {
            tar.style.backgroundColor="lightyellow";
          }
          else
          {
            tar.style.backgroundColor="#ffffff";
          }  
      }
      
    }
    else if(att2==1)
    {
      if(blank==1)
      {
          if(tar.value=="" || !dec.test(tar.value))
          {
            tar.style.backgroundColor="lightyellow";
          }
          else
          {
            tar.style.backgroundColor="#ffffff";
          }  
      }
      else
      {
        if(!dec.test(tar.value))
          {
            tar.style.backgroundColor="lightyellow";
          }
          else
          {
            tar.style.backgroundColor="#ffffff";
          }  
      }
      
    }
}

function FillAddress()
{
    var PAdd=document.getElementById('ctl00_ContentMain_txtPAdd');
    var PCountry=document.getElementById("ctl00_ContentMain_ddlPCountry");
    var PState=document.getElementById("ctl00_ContentMain_txtPState");
    var PCity=document.getElementById("ctl00_ContentMain_txtPCity");
    var PPinCode=document.getElementById("ctl00_ContentMain_txtPPin");
    var PPhone=document.getElementById("ctl00_ContentMain_txtPhone");
    var CAdd=document.getElementById("ctl00_ContentMain_txtCAdd");
    var CCountry=document.getElementById("ctl00_ContentMain_ddlCCountry");
    var CState=document.getElementById("ctl00_ContentMain_txtCState");
    var CCity=document.getElementById("ctl00_ContentMain_txtCCity");
    var CPinCode=document.getElementById("ctl00_ContentMain_txtCPin");
    var CPhone=document.getElementById("ctl00_ContentMain_txtCPhone");
    PAdd.value=CAdd.value;
    PCountry.value=CCountry.value;
    PState.value=CState.value;
    PCity.value=CCity.value;
    PPinCode.value=CPinCode.value;
    PPhone.value=CPhone.value;
}
function FindCurrentDate(id)
{
    var tar=document.getElementById(id);
    var CurrDate=new Date();
    var mm=CurrDate.getMonth()+1;
    var dd=CurrDate.getDate();
    var yy=CurrDate.getFullYear();
    var CurrentDate=mm+"/"+dd+"/"+yy;
    tar.value=CurrentDate;
}
function FindCurrentDateDD(id)
{
    var tar=document.getElementById(id);
    var CurrDate=new Date();
    var mm=CurrDate.getMonth();
    var dd=CurrDate.getDate();
    var yy=CurrDate.getFullYear();
    var CurrentDate=dd+"-"+mm+"-"+yy;
    tar.innerHTML=CurrentDate;
}
function FindCurrentDateDD1(id)
{
    var tar=document.getElementById(id);
    var CurrDate=new Date();
    var mm=CurrDate.getMonth()+1;
    var dd=CurrDate.getDate();
    var yy=CurrDate.getFullYear();
    var CurrentDate=dd+"/"+mm+"/"+yy;
    tar.value=CurrentDate;
}
function FindCurrentDateDDLong(id)
{
    var  month=new Array();
    month[0]="Janaury";
    month[1]="Febraury";
    month[2]="March";
    month[3]="April";
    month[4]="May";
    month[5]="June";
    month[6]="July";
    month[7]="August";
    month[8]="September";
    month[9]="October";
    month[10]="November";
    month[11]="December";
   
    var tar=document.getElementById(id);
    var CurrDate=new Date();
    var mm=CurrDate.getMonth();
    var dd=CurrDate.getDate();
    var yy=CurrDate.getFullYear();
    var CurrentDate=dd+"-"+month[mm]+"-"+yy;
    tar.innerHTML=CurrentDate;
}
