﻿//	written	by Proj-e
//	last updated 13 Haziran 2007
/*	
    parametreler
    required = "true" -- > input alanlarının zorunlu olması için kullanılıyor
    attribute = "mail" --> girilen mailin geçerli olup olmadığına bakılıyor.
    attribute = "percent" --> 100 girişleri için kullanılıyor. (0 ile 100 arasında olup olmadığının kontrolü)
    attribute = "numeric" --> Girilen değerin sayı olup olmadığının kontrolünde kullanılıyor.
    attribute = "date" --> girilen tarihin geçerli olup olmadığının kontrolü
    refAlertId
*/ 

var submit_fl = 0;

function formValidation(pnlName)
{
    if (pnlName==null)
    {   alert("Panel Gönderilmemiş");
        return false;
    }
    var boolForm = true;
	var strMessage = strGNL_JSMESSAGE;
	try
	{
	    if (parent.submit_flPage!=null)
	        submit_fl = parent.submit_flPage;
        
         var x = document.getElementById(pnlName).getElementsByTagName("INPUT");
         for (var i=0;i<x.length;i++)
         {
            if (x[i].getAttribute('required') && !x[i].value)
            {
                strMessage += document.getElementById((x[i].getAttribute('refAlertId')==null ? x[i].id.replace('txt','lbf'): x[i].getAttribute('refAlertId'))).innerHTML + "\n";
//                x[i].tagName.className='invalidInput';
                boolForm = false;
            }            
//            else
//                x[i].className='textbox';
           
            
            if (boolForm)
                if (x[i].getAttribute('attribute')!=null && x[i].getAttribute('attribute').indexOf('mail') > -1)
                {
                    var bln = checkEmail(document.getElementById(x[i].id).value);
		            if (!bln)
		            {
//		                x[i].className='invalidInput';
			            return false;
		            }
//		            else
//                        x[i].className='textbox';
                }
                else if (x[i].getAttribute('attribute')!=null && x[i].getAttribute('attribute').indexOf('date') > -1)
                {
                    var bln = isDate(document.getElementById(x[i].id).value);
		            if (!bln)
		            {
//		                x[i].className='invalidInput';
			            return false;
		            }
//		            else
//                        x[i].className='textbox';
                }
                else if (x[i].getAttribute('attribute')!=null && x[i].getAttribute('attribute').indexOf('numeric') > -1)
                {
                    if (document.getElementById(x[i].id).value!="")
	                {
	                    document.getElementById(x[i].id).value = document.getElementById(x[i].id).value.replaceAll( " ", "" );
		                if (isNaN(document.getElementById(x[i].id).value.replace(",",".").replace('.','').replace(' ','')))
		                {
		                    alert(strGNL_SAYIKONTROL.replace("$strDegisken$",document.getElementById((x[i].getAttribute('refAlertId')==null ? x[i].id.replace('txt','lbf'): x[i].getAttribute('refAlertId'))).innerHTML));
		                    x[i].focus();
			                return false;
		                }
//		                else
//                            x[i].className='';
	                }
                }             
                else if (x[i].getAttribute('attribute')!=null && x[i].getAttribute('attribute').indexOf('percent') > -1)
                {
                    if (document.getElementById(x[i].id).value!="")
	                {
		                if (isNaN(document.getElementById(x[i].id).value))
		                {
		                    alert(strGNL_SAYIKONTROL.replace("$strDegisken$",document.getElementById(x[i].id.replace('txt','lbf')).innerHTML));
//		                    x[i].className='invalidInput';
			                return false;
		                }
//		                else
//                            x[i].className='';
	                }
                }
         }	
         var x = document.getElementById(pnlName).getElementsByTagName("TEXTAREA");
         for (var i=0;i<x.length;i++)
         {
           if (x[i].getAttribute('required') && !x[i].value)
            {
                strMessage += document.getElementById((x[i].getAttribute('refAlertId')==null ? x[i].id.replace('txt','lbf'): x[i].getAttribute('refAlertId'))).innerHTML + "\n";
//                x[i].tagName.className='invalidInput';
                boolForm = false;
            }            
//            else
//                x[i].className='textbox';
         }
         var x = document.getElementById(pnlName).getElementsByTagName("SELECT");
         for (var i=0; i < x.length;i++)
         {
            if (x[i].getAttribute('required') && x[i].value=="0")
            {
                strMessage += document.getElementById((x[i].getAttribute('refAlertId')==null ? x[i].id.replace('drp','lbf').replace('_ID','_AD'): x[i].getAttribute('refAlertId'))).innerHTML + "\n";
                boolForm = false; 
            }         
         }
     }
     catch (ex) {alert(ex);boolForm=false;}
    				
	if (boolForm==false)
	{
		alert(strMessage);
	}
	
	if (submit_fl != 0)
	{
		return false;
	}
	
	if (boolForm)			
		submit_fl = 1;

	return boolForm;
}

// pnlName = "ctl00_dtMain_ctl00_frmMain_pnlArama"
function resetSearch(pnlName)
{
    var mylist = document.getElementById(pnlName).getElementsByTagName("INPUT") ;

     for (var i=0;i<mylist.length;i++)
     {
        if (mylist[i].type=='text')
        {
            mylist[i].value = "";
        }
        if (mylist[i].type=='hidden')
        {
            mylist[i].value = "";
        }
        else if (mylist[i].type=='checkbox')
        {
          mylist[i].checked = false;
        }        
        else if (mylist[i].type == "radio")
        {
            mylist[i].checked = false;
        }
    }    
     var mylist = document.getElementById(pnlName).getElementsByTagName('SELECT') ;
     for (var i=0;i<mylist.length;i++)
     {
         mylist[i].selectedIndex = 0;
     }    
	return false;
}
// Replaces all instances of the given substring.
String.prototype.replaceAll = function( 
strTarget, // The substring you want to replace
strSubString // The string you want to replace in.
){
var strText = this;
var intIndexOfMatch = strText.indexOf( strTarget );
 

// Keep looping while an instance of the target string
// still exists in the string.
while (intIndexOfMatch != -1){
// Relace out the current instance.
strText = strText.replace( strTarget, strSubString )
 

// Get the index of any next matching substring.
intIndexOfMatch = strText.indexOf( strTarget );
}
 

// Return the updated string with ALL the target strings
// replaced out with the new substring.
return( strText );
}
