
function CheckMinimumLength(src,args)
{
    var val = args.Value;
    val = trim(val);

    if(val.length > 2)
    {    
        args.IsValid=true;
    }
    else
    {
        args.IsValid=false;
    }
}

// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}
     
//********* Special Toggle CHECKBOX function ********//
function togglecheck(id)
{
   var thefrm=document.getElementById("aspnetForm");
   //var thefrm=document.getElementById("form1");
   if(document.getElementById(id).checked)   
   // Checks all
       {
        if(thefrm)
            {
                for(i=0;i<thefrm.elements.length;i++)                
                {
                    if(thefrm.elements[i].type=='checkbox')
                    {
                        thefrm.elements[i].checked=true;
                    }
                }
            }
       }
    else
    // Unchecks all
        {
        if(thefrm)
            {
                for(i=0;i<thefrm.elements.length;i++)                
                {
                    if(thefrm.elements[i].type=='checkbox')
                    {
                        thefrm.elements[i].checked=false;
                    }
                }
            }
       }
    }
    
    
 function SwapImg(path, id)
    {     
        document.getElementById(id).src = path;
    }
    function RestoreImg(path,id)
    {    
        document.getElementById(id).src = path;
    }   
    
/*======== SearchResultControl.ascx =========*/    
function GrabDropDownSelectedValue(ctrl1, itemAttributes)
{

    var controlIds = document.getElementById(ctrl1).value;
    var controlIdsArray = controlIds.split(',');
    var controlValue = '';
    for(var i in controlIdsArray)
    {
        controlValue = controlValue + document.getElementById(controlIdsArray[i]).value + ",";
    }
    controlValue = controlValue.substring(0, controlValue.length - 1);
    //document.getElementById(ctrl2).value = controlValue;
    CheckCookie(controlValue,itemAttributes);
}
    
function CheckCookie(ids, itemAttribute)
{

    var data = 'ckSearchResultValues=' + ids + '$'+ itemAttribute;
    if(document.cookie['SearchResultCookie'] != null)
    {
        eraseCookie('SearchResultCookie');        
        createCookie('SearchResultCookie',data,1);
    }
    else
    {
        createCookie('SearchResultCookie',data,1);
    }
}

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=/";
}


//  Check a string for special characters
    var r={
  'special':/[\W]/g,
  'quotes':/['\''&'\"']/g,
  'notnumbers':/[^\d]/g
}

function valid(id,w){
var ctrl = document.getElementById(id); 
  ctrl.value = ctrl.value.replace(r[w],'');
}

