﻿// JScript File//
/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
//----------------------------- Email Checking -----------------------------
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 ValidateForm(txtID,imgID)
{
	var emailID=document.getElementById(GetClientId(txtID))
	
	if ((emailID.value==null)||(emailID.value=="")){
		//alert("Please Enter your Email ID")
		emailID.focus()
		document.getElementById(GetClientId(imgID)).src='../image/Overlay-cancel.gif';   
		FinalValidation(3);
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		document.getElementById(GetClientId(imgID)).src='../image/Overlay-cancel.gif';
		FinalValidation(3);
		return false
	}
	document.getElementById(GetClientId(imgID)).src='../image/Overlay-ok.gif';   
	return true
 }



//---------------------- FileUpload Validation --------------------------
function Trim(input)
  {
    var lre = /^\s*/; 
    var rre = /\s*$/; 
    input = input.replace(lre, ""); 
    input = input.replace(rre, ""); 
    return input; 
   }
 
   // filter the files before Uploading for text file only  
   function CheckForTestFile() 
   {
        var file = document.getElementById(GetClientId('FileUpload1'));
        var fileName=file.value;        
        //Checking for file browsed or not 
//        if (Trim(fileName) =='' )
//        {
//            //alert("Please select a file to upload!!!");
//            file.focus();
//            document.getElementById(GetClientId('img2')).src='../image/Overlay-cancel.gif'; 
//            return false;
//        }
// 
       //Setting the extension array for diff. type of text files 
    var extArray = new Array(".pdf",".zip",".rar",".doc",".docx");    
 
       //getting the file name
       while (fileName.indexOf("\\") != -1)
         fileName = fileName.slice(fileName.indexOf("\\") + 1);
 
       //Getting the file extension                     
       var ext = fileName.slice(fileName.indexOf(".")).toLowerCase();
 
       //matching extension with our given extensions.
       for (var i = 0; i < extArray.length; i++) 
       {
         if (extArray[i] == ext) 
         { 
        //   document.getElementById(GetClientId('img2')).src='../image/Overlay-ok.gif';    
           return true;
         }
       }  
         alert( "*"+ (extArray.join("  ")) + " :الرجاء ارفاق السيرة الذاتية من امتداد " );
           file.focus();
         //  document.getElementById(GetClientId('img2')).src='../image/Overlay-cancel.gif'; 
           return false;                
   }    
//----------------- the end ------------------------------------------------

//----------------------------- Normal textbox validation ------------------

function Validatetxt(txtID,imgID)
{
	var txt=document.getElementById(GetClientId(txtID))
	
	if ((txt.value==null)||(txt.value==""))
	{
		//alert("Please Enter your Email ID")
		txt.focus();
		document.getElementById(GetClientId(imgID)).src='../image/Overlay-cancel.gif'; 
		FinalValidation(3);  
		return false;
	}
	document.getElementById(GetClientId(imgID)).src='../image/Overlay-ok.gif';   
	return true;
 }
 //------------------------------------------------------------------------------
 
//-------------------------- Numeric textbox validation -------------------------
function IsNumeric(txtID,imgID)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
	
   var txt=document.getElementById(GetClientId(txtID))
   var sText=document.getElementById(GetClientId(txtID)).value
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         
        txt.value=""
		txt.focus()
		IsNumber = false;
         }
      }
      if (IsNumber==false)
      { 
        document.getElementById(GetClientId(imgID)).src='../image/Overlay-cancel.gif'; 
        FinalValidation(3);
          
        return IsNumber;
       }
       {
        document.getElementById(GetClientId(imgID)).src='../image/Overlay-ok.gif';   
        return IsNumber;
        }
   
   
   }

//---------------------------------------------------------------------------------

//-------------------------- DropDown list Driver ID validation -------------------

function DDValidation(lang)
{
    var dropdown =document.getElementById(GetClientId('DDdID'));
    var index=dropdown.selectedIndex;

           var index=dropdown.selectedIndex;
                if (index ==0  || index ==3)
                    {
                        document.getElementById(GetClientId('txtdlID')).readOnly=true;
                        document.getElementById(GetClientId('img9')).src='../image/emptyD.gif';   
                        if (lang==1)
                        {
                            document.getElementById(GetClientId('txtdlID')).value='لايوجد';
                            return false;
                        }
                        if (lang==2)
                        {
                            document.getElementById(GetClientId('txtdlID')).value='None'
                            return false;
                        }       
                     }
                 if (index ==1 || index ==2)
                     {
                        document.getElementById(GetClientId('img9')).src='../image/empty.GIF';   
                        document.getElementById(GetClientId('txtdlID')).readOnly=false;
                        document.getElementById(GetClientId('txtdlID')).value=''
                        return false;
                     }
}

//-------------------------------- Form Validation ---------------------------------

function FinalValidation(lang)

{
   var ckeck=document.getElementById(GetClientId('CheckBox'));
   var imgbut=document.getElementById(GetClientId('Ibtn'));
   var j=0;
   var state=document.getElementById(GetClientId('checksatet'));
   if(state.value=='true')
   {
        imgbut.src='../image/Mail-send-of.gif';
        imgbut.disabled=true;
        ckeck.checked=false;
        imgbut.className="NIMG";
        state.value='false';
      return true;
   }
   {
    for (var img = 1; img <=9 ; img++) 
    {
        var imgv=document.getElementById(GetClientId('img' + img))
        if (imgv.src=='http://localhost:2855/almadarwebsite128.1.2009/image/Overlay-cancel.gif'  || imgv.src=='http://localhost:2855/almadarwebsite128.1.2009/image/empty.GIF')
            {
              imgv.src='../image/Overlay-cancel.gif'
              j=j+1
            }
    }
      
          if (j==0)
            {
                imgbut.src='../image/Mail-send.gif';
                imgbut.disabled=false;
                imgbut.className="IMG";
                state.value='true';
               var txtID=document.getElementById(GetClientId('txtdlID'));
               var txtresultID=document.getElementById(GetClientId('LicenceID'));
               txtresultID.value=txtID.value;
               return true;
            }
            
            {
              imgbut.src='../image/Mail-send-of.gif';
              imgbut.disabled=true;
              ckeck.checked=false;
              imgbut.className="NIMG";
              state.value='false';
                            
              if(lang==1)
              { 
                
                alert('الرجاء تعبئة جمبيع الخانات');
                return true;
              }
                if(lang==2)
              {
                
                alert('Please full all the fields');
                return true;
              }
              {
               return true;
              }
              
             
            }
    
   }  
}

//function FinalValidationnew(lang)

//{
// var j=0
//  for (var img = 1; img <=10 ; img++) 
//  {
//        var imgv=document.getElementById(GetClientId('img' + img))
//        if (imgv.src=='../image/Overlay-cancel.gif'  )
//            {
//              j=j+1
//            }

//          if (j==0)
//            {
//                var imgbut=document.getElementById(GetClientId('Ibtn'))
//                imgbut.src='../image/Mail-send-of.gif';
//                imgbut.disabled=true;
//                imgbut.className="NIMG";
//                return true;
//            }
//            {
//                var ckeck=document.getElementById(GetClientId('CheckBox'))
//              if(ckeck.checked==true)
//              var imgbut=document.getElementById(GetClientId('Ibtn'))
//              imgbut.src='../image/Mail-send-of.gif';
//              imgbut.disabled=true;
//              ckeck.checked==false;
//              imgbut.className="NIMG";
//              return false;
//            }
//    
//  }
//}

//if(document.getElementById(GetClientId('CheckBox')).checked==true)
//{

// var imgbut=document.getElementById(GetClientId('Ibtn'))
// imgbut.src='../image/Mail-send.gif';
//  imgbut.disabled=false;
//  imgbut.className="IMG";
//return true;
//}
//{
//var imgbut=document.getElementById(GetClientId('Ibtn'))
// imgbut.src='../image/Mail-send-of.gif';
// imgbut.disabled=true;
// imgbut.className="NIMG";
//return true;
//}


//---------------------------------------------------------------------------------

function test()
{
var test=document.getElementById(GetClientId('HFsession'))
alert(test.value);
ticker_start(test.value);
return false;
}

