cid=$1 assigns the value you pass as argument1 to cid which is later searched for in else if ($0~/'$cid'/) .
cidname=$2 is the filename that you want to search data in
Logic is something like this,
If the line read contains only one field, assign that value to hdrvar (if (NF==1) hdrvar=$0).
Else
Check to see if the line contains the string mentioned in variable cid, then print value in hdrvar and the matched line. (else if ($0~/'$cid'/) print hdrvar,"\n",$0)
So, it prints the line matching the given string and the last one preceeding it having one field only.
FS=/n redefines the field separator to be the newline character. So each line is a field.
RS="" in some magic way tells awk (or nawk or gawk) that a blank line is the record separator.
So we are setting things up to process multi-line records.
First line BEGIN {...}
This line is executed only once. Before awk looks at the first line of the file.
As mentioned above, the FS and RS variables are set so that each block of data, separated by a empty line (""), is seen as a record. Each record is made of fields separated by the new line character (\n). ORS (Output Record Separator) does exactly that. It sets the output separator.
/pattern/ {action}
Starting here awk will scan the input file $cidname, one record at the time. If it finds a record (bloc of several lines, remember?) that contains the /pattern/, awk prints that record.