<?php
/*
$image_field_validate_array=array(							
							array('name'=>'attachment',
								  'required'=>1,	 
								  'typeallow'=>'',
								  'hightallow'=>'',
								  'widthallow'=>'',
								  'error'=>'')
								  
								);					
*/
function validate_form_image_field($image_field_validate_array){
$proceed_flag=0;
$errormsg='';
if(count($_FILES))
foreach($_FILES as $key=>$value) 		
if(list($data,$data_array)=array_multi_search( $key, $image_field_validate_array )){
//echo print_r($value['type']);
if(!is_array($value['name'])){
		if($data_array['required']=='Y' && strlen($value['tmp_name'])<3){		
		$proceed_flag++;
		$errormsg.='<br>Upload '.$data_array['filetype'];
		}else if(strlen($data_array['typeallow'])>0){
				$extension_array=explode(",",$data_array['typeallow']);		
				$file_name=$value['name'];
				$ext=substr($file_name,strlen( $file_name )-4,strlen( $file_name ));
					if(!in_array($ext,$extension_array))
					{
					$proceed_flag++;
					$errormsg.='<br>only '.$data_array['typeallow']." are allowed";
					}
			}
			else	if(strlen($data_array['hightallow'])>0 && !$data_array['filetype']=='image' &&$value['size']> $data_array['hightallow']){		
							$proceed_flag++;
							$errormsg.='<br>Maximum size  '.$data_array['typeallow']." are allowed";
							}	
}else{
$required_flag=0;
$required_image=$data_array['required'];
$extension_array=explode(",",$data_array['typeallow']);
		for($i=0;$i<count($value['name']);$i++)
			if(strlen($value['tmp_name'][$i])>3)	
				$required_flag++;		
		
			if($required_flag<$required_image){
			$proceed_flag++;	
			$errormsg.='<br>Upload minimum '.$required_image." ".$data_array['filetype'];
			}
$flag=0;
		if($proceed_flag<1)
			for($i=0;$i<count($value['name']);$i++)
				if(strlen($value['tmp_name'][$i])>3 && strlen($data_array['typeallow'])>0)
						{				
							$file_name=$value['name'][$i];
							$ext=substr($file_name,strlen( $file_name )-4,strlen( $file_name ));
							if(!in_array($ext,$extension_array))												
							$flag=1;						
							
						}
				if($flag){					
				$proceed_flag++;
				$errormsg.='<br>only '.$data_array['typeallow']." are allowed";			
				}			
}
}
return array($proceed_flag,$errormsg);
}
function	validate_form_field($mendatry_check_array,$validate_check_array,$post_data,$edit_id=0){
$proceed_flag=0;
$errormsg='';
foreach($mendatry_check_array as $key=>$value)
	{	
		 if(!isset($post_data[$value]) || strlen($post_data[$value]) < 1)
		 {
		 $proceed_flag= $proceed_flag + 1; 	
		 }	
	}
 if($proceed_flag>0)
 		{
$errormsg='Please ensure all mandatory fields (marked with *) are filled in';
		}
else{
	
	$errormsg='';
	foreach($post_data as $key=>$value)
		{			
				if(list($data,$data_array)=array_multi_search( $key, $validate_check_array )){
				$data=substr($data,0,strlen($data)-1);
				$match_array=explode("_",$data);
				$result_matcharray = array_reverse($match_array);
						
							if($result_matcharray[0]=='unique'){
									$editcond='';
									if($edit_id>0){
									$editcond= " and ".$data_array['updateidmatch']."!=".$edit_id;							
									}							
									$query="SELECT ".$data_array['tablefield']."  FROM ".$data_array['tablename']." where ".$data_array['tablefield']."='$value' ".$editcond;	 
									$result=mysql_query($query);
									$row=mysql_num_rows($result);
									if($row > 0){
									$proceed_flag= $proceed_flag + 1; 	
									$errormsg.="<br>".$data_array['error'];
									}
							 }
						if($result_matcharray[0]=='numeric'){
							if(strlen($value)>0 && !is_numeric($value)){
							  $proceed_flag= $proceed_flag + 1; 	
							  $errormsg.="<br>".$data_array['error'];
							 }}
						 if($result_matcharray[0]=='email'){
							if(strlen($value)>0 && !check_email_validation($value)){
							  $proceed_flag= $proceed_flag + 1; 	
							  $errormsg.="<br>".$data_array['error'];
							}}
							
							 if($result_matcharray[0]=='match'){
							if(strlen($value)>0 && $post_data[$data_array['name']]!=$post_data[$data_array['name2']]){
							 unset($post_data[$data_array['name2']]);
							  $proceed_flag= $proceed_flag + 1; 	
							  $errormsg.="<br>".$data_array['error'];
							}}
				}
		}
}
return array($proceed_flag,$errormsg);
}				
function check_email_validation($email){
if (ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$',$email)) 
			return true;
			else return false;
}
function get_master_sql($masterfieldname){
if(is_numeric($masterfieldname)){
$sql=" SELECT id, name FROM  ".SINGLE_FIELD_TABLE." WHERE mastertableid='$masterfieldname' order by name";
}else{
$sql=" SELECT s.id,s.name FROM  ".SINGLE_FIELD_TABLE." s, ".MASTERTABLENAME." mt WHERE s.mastertableid=mt.id and mt.name='$masterfieldname' order by s.name";
}
 return $sql;
}
function array_multi_search( $p_needle, $p_haystack)
    {
	
	static $matchstr='';
	static $matchstr_array=array();
        if( !is_array( $p_haystack ) )
        {
            return false;
        }
		if(isset($p_haystack['name']))	
        if( $p_needle==$p_haystack['name'] )
        {
		$matchstr_array=$p_haystack;
            return true;
        }
        foreach( $p_haystack as $k=>$row )
        {
		$matchstr='';
		    if(array_multi_search( $p_needle, $row ) )
            {		
			 $matchstr.=$k."_";
                return array($matchstr,$matchstr_array);
            }
        }

        return false;
    } 
function get_single_fieldsql_script($masterfieldname){
$FROMCLOUSE='';
$WHERECLOUSE='';
$FROMCLOUSE.=SINGLE_FIELD_TABLE." s";

if(is_numeric($masterfieldname)){
$WHERECLOUSE.=" s.mastertableid='$masterfieldname' ";
}else{
$FROMCLOUSE.=", ".MASTERTABLENAME." mt";
$WHERECLOUSE.= "s.mastertableid=mt.id and mt.name='$masterfieldname' ";
}
$sql=" SELECT s.id,s.name   FROM  ".$FROMCLOUSE."  WHERE ".$WHERECLOUSE." order by s.name";
return $sql;
}
function get_double_fieldsql_script($masterfieldname){
$FROMCLOUSE='';
$WHERECLOUSE='';
$FROMCLOUSE.=SINGLE_FIELD_TABLE." s";
if(is_numeric($masterfieldname)){
$WHERECLOUSE.=" s.mastertableid='$masterfieldname' ";
}else{
$FROMCLOUSE.=", ".MASTERTABLENAME." mt";
$WHERECLOUSE.= "s.mastertableid=mt.id and mt.name='$masterfieldname' ";
}
$FROMCLOUSE.= ", ".DOUBLE_FIELS_TABLE." ds";
$WHERECLOUSE.= " and  s.id=ds.single_field_id  ";
$sql=" SELECT s.id,s.name,ds.second_fieldid    FROM  ".$FROMCLOUSE."  WHERE ".$WHERECLOUSE." order by s.name";
return $sql;
}

function draw_pull_down_mastertable($name,$selected,$masterfieldname,$double_fieldprimaryid='',$doublefield=0,$table_parameters,$parameters = '',$PULL_DOWN_DEFAULT,$multiple='n'){
$FROMCLOUSE='';
$WHERECLOUSE='';
$FROMCLOUSE.=SINGLE_FIELD_TABLE." s";
if(is_numeric($masterfieldname)){
$WHERECLOUSE.=" s.mastertableid='$masterfieldname' ";
}else{
$FROMCLOUSE.=", ".MASTERTABLENAME." mt";
$WHERECLOUSE.= "s.mastertableid=mt.id and mt.name='$masterfieldname' ";
}
if($doublefield >0){
$FROMCLOUSE.= ", ".DOUBLE_FIELS_TABLE." ds";
$WHERECLOUSE.= " and  s.id=ds.single_field_id and ds.second_fieldid='$double_fieldprimaryid' ";
}
$sql=" SELECT s.id,s.name FROM  ".$FROMCLOUSE."  WHERE ".$WHERECLOUSE." order by s.name";
return draw_dynamic_pull_down_menue_sql($name,$sql,$selected , $parameters,$PULL_DOWN_DEFAULT,$multiple);
}


function display_second_field($singlefieldid){
$pdelr = "select s.name FROM ".SINGLE_FIELD_TABLE." s, ".DOUBLE_FIELS_TABLE."  d
where s.id=d.second_fieldid and d.single_field_id= '$singlefieldid'";
$pdelq = mysql_query($pdelr);
if(mysql_num_rows($pdelq)>0){
$pdelre = mysql_fetch_object($pdelq);
return $pdelre->name;
}else  return "Not exist";
}



function get_admin_data($filedname){
$sql = "SELECT  ".$filedname." 	FROM admin  ";
			$result = mysql_query($sql); 
			$num_rows=mysql_num_rows($result);
					if($num_rows>0){
					$data=mysql_fetch_array($result);
					if($filedname=='*'){				
					return 0;
					}else{
					return $data[$filedname];
					}
					}else{
					return 0;
					}
}
function get_formate_date($date_of_birth){
$st=explode("-",$date_of_birth);
$mon=get_month_array();
$dt=$st[2]." ".$mon[$st[1]]." ".$st[0];

return $dt;
}


 function tep_draw_pull_down_menu_cat_mul($name, $values, $default , $parameters = '', $required = false) {
    $field = '<select name="' . $name . '"';

    if (tep_not_null($parameters)) $field .= ' ' . $parameters;

    $field .= ' size="6" multiple >';

   // if (empty($default) && isset($GLOBALS[$name])) $default = stripslashes($GLOBALS[$name]);

    for ($i=0, $n=sizeof($values); $i<$n; $i++) {
      $field .= '<option value="' . $values[$i]['id'] . '"';
      if (in_array($values[$i]['id'],$default)) {
        $field .= ' SELECTED';
      }

      $field .= '>' . $values[$i]['text']. '</option>';
    }
    $field .= '</select>';

    if ($required == true) $field .= TEXT_FIELD_REQUIRED;

    return $field;
  } 



function validate_date($date){

if(strlen($date)>0){
		if (ereg ("([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})", $date)) {
		 $regs=explode("/",$date);

		if(date_validation($regs[0],$regs[1],$regs[2])){
		  $valid_date=$regs[2]."-".$regs[1]."-".$regs[0];
		  //echo $valid_date;
		   return array(1,$valid_date);   //valid date
} else return array(3,"");
		} else {
		
		   return array(0,""); // invalid date formate
		}
}else return array(2,""); // empty date field formate


}
function date_validation($day,$month,$year){
return checkdate($month,$day, $year) ;
}

function check_for_quantity($max_qty,$product_qty,$products){
$error_array=array();
$error_flag=0;

		if(count($products)>0){
					for($i=0;$i<count($products);$i++){
			
				$explore=explode("_",$products[$i]);
				$j=$explore[0];				
				
							if($max_qty[$j]>$product_qty[$j])
							{

										$error_array[]=$j;
										$error_flag=1;
							}
					}
			}

return array($error_flag,$error_array);

}

function get_date_of_birth_display($id,$e_date){
$pdelr = "select 
DATE_FORMAT(".$e_date.",'%a, %b %d, %Y ') as formateddate
from 
users
where id='$id'";
//echo $pdelr ;
$pdelq = mysql_query($pdelr);
$pdelre = mysql_fetch_object($pdelq);
$numrows = $row = mysql_num_rows($pdelq);
	return $pdelre->formateddate;


}

function imageResize($width, $height, $target) 
{ 
if ($width > $height) 
{ 
	$percentage = ($target / $width); 
} 
else 
{ 
	$percentage = ($target / $height); 
} 
$width = round($width * $percentage); 
$height = round($height * $percentage); 
return "width=$width height=$height"; 
} 


function tep_image($src, $alt = '', $width = '', $height = '', $parameters = '') {
$req_width= $width;
$req_height=$height;
// alt is added to the img tag even if it is null to prevent browsers from outputting
// the image filename as default
    

    if(file_exists($src))
	{
	$image = '<img src="' . $src . '"   alt="' .$alt . '"';
      if ($image_size = @getimagesize($src)) {

			$image .= imageResize($image_size[0], $image_size[1], $req_height);
/*
	  
			  if($image_size[0]>$req_width && $image_size[1] < $req_height)
					{	   
				 	 $image .= ' width="' . $req_width . '" ';	  
				 	}
			  if($image_size[0]<$req_width && $image_size[1] > $req_height)
					{    
					$image .= ' height="' . $req_height . '" ';				  
				    }
			   if($image_size[0]>$req_width && $image_size[1] > $req_height)
					{	          
				   $image .= ' width="' .($req_width) . '" height="' . ($req_height) . '"';	  
			  		}

				*/
      
	  } 
	 
 
	 if(tep_not_null($parameters))
	  $image .= $parameters;
	$image.=' border="0"';
	 

    $image .= ' >';


    return $image;
	} else return "";
  }
function get_month_array(){
 $mon=array();
$mon=array("1"=>"January","February","March","April","May","June","July","August","September","October","November","December"); 

return $mon;
}
////
// The HTML image wrapper function
function call_display_month($month_name,$month,$default_name,$default_value,$class){
$st="";
  $mon=array();
$mon=get_month_array();
//array("1"=>"January","February","March","April","May","June","July","August","September","October","November","December"); 

$st.='<select name="'.$month_name.'" class="'.$class.'" >';
	if(strlen($default_name)>0)
	{
	$st.='<option value="'.$default_value.'">'.$default_name.'</option>';
	}   
for($i=1;$i<=12;$i++){

$st.='<option value="'.$i.'"';
if($i==$month)
{
$st.='selected';
}
$st.='>'.$mon[$i].'</option>';
}
$st.='</select>';
return $st;
}
function call_display_year($year_name,$year,$start_year,$more_year,$class='',$default_value='',$default_name='')
{
$st="";
$st.='<select name="'.$year_name.'" class="'.$class.'" >';
if(strlen($default_name)>0){
$st.='<option value="'.$default_value.'">'.$default_name.'</option>';
}   

$year_cal=date("Y");
$end=$year_cal+$more_year;
$start=$start_year;
for($i=$start;$i<=$end;$i++){
$st.='<option value="'.$i.'"';

if($i==$year)
{
$st.='selected';
}

$st.='>'.$i.'</option>';
}



$st.=' </select>';
return $st;
}
		
function get_date_field($day_name,$month_name,$year_name,$day,$month,$year,$start_year,$more_year,$class='',$default_value='',$default_name=''){
$st="";	

$st.='<select name="'.$day_name.'" class="'.$class.'" >';
if(strlen($default_name)>0){
$st.='<option value="'.$default_value.'">'.$default_name.'</option>';
}                                  
for($i=1;$i<=31;$i++){
$st.='<option value="'.$i.'"';
if($i==$day)
{
$st.='selected';
}
$st.=' >';
if($i<10) 
$st.='0'.$i;
else 
$st.=$i;
$st.='</option>';
}
$st.='</select>';

$st.=call_display_month($month_name,$month,$default_name,$default_value,$class);
$st.=call_display_year($year_name,$year,$start_year,$more_year,$class='',$default_value='',$default_name='');

//$st.='DD/MM/YYYY ';
return $st;


}
function get_time_field($time_name,$time_value,$default_value='',$default_name='',$class=''){
if(strlen($time_value)>0){
$hour_min=explode("-",$time_value);
$hour_value=$hour_min[0];
$min_value=$hour_min[1];
}else{
$hour_value="";
$min_value="";
}
if(strlen($time_name)>0){
$hour_min=explode("-",$time_name);
$hour_name=$hour_min[0];
$min_name=$hour_min[1];
}



$st="";	

$st.='<select name="'.$hour_name.'" class="'.$class.'" >';
if(strlen($default_name)>0){
$st.='<option value="'.$default_value.'">'.$default_name.'</option>';
}                                  
for($i=0;$i<=23;$i++){
$st.='<option value="'.$i.'"';
if($i==$hour_value)
{
$st.='selected';
}
$st.=' >';
if($i<10) 
$st.='0'.$i;
else 
$st.=$i;
$st.='</option>';
}
$st.='</select>';


$st.='<select name="'.$min_name.'" class="'.$class.'" >';
if(strlen($default_name)>0){
$st.='<option value="'.$default_value.'">'.$default_name.'</option>';
}                                  
for($i=0;$i<=59;$i++){
$st.='<option value="'.$i.'"';
if($i==$min_value)
{
$st.='selected';
}
$st.=' >';
if($i<10) 
$st.='0'.$i;
else 
$st.=$i;
$st.='</option>';
}
$st.='</select>';




//$st.='DD/MM/YYYY ';
return $st;


}
			
function display_time($time_value){

if(strlen($time_value)>0){
$hour_min=explode("_",$time_value);
$hour_value=$hour_min[0];
$min_value=$hour_min[1];
if($min_value<10)
$min_value ="0".$min_value;
}else{
$hour_value="";
$min_value="";
}
$st="";
			if($hour_value>12) 
			{
			$st .=($hour_value-12);
			$st .=".".$min_value."pm";
			}else{
			$st .=$hour_value;
			$st .=".".$min_value."am";
			}			
				
				return $st;
				}
function get_all_field_value($sql){
$results = array();
//talk to the db
$result = mysql_query($sql) or die(mysql_error());

//count the rows and fields
$totalRows = mysql_num_rows($result);
$totalFields = mysql_num_fields($result);

//start the loop
for ( $i = 0; $i < $totalRows; ++$i ) {
  $results[$i] = mysql_fetch_array($result); 
}
return  array($results);
}
	
	function isnumeric($fld){	
	if(strlen($fld)>0 && !is_numeric($fld))
	return 1;
	else return 0;
	}

function file_coppy($folder,$file_name,$newID){
				$img_file=$_FILES[$file_name]['tmp_name'];
				
				if(strlen($img_file)>4)
				{
				$photofile1 = $folder."/" .$newID . $_FILES[$file_name]['name'];
				copy($img_file, $photofile1); 
				unlink($img_file); 
				$file = $newID . $_FILES[$file_name]['name'];
				// $type1=$_FILES[$file_name]['type'];  
				//create_image($file,$type1);

				}
				else
				{
				$file = "";
				}
				
				
				
				return $file;
		}

function image_coppy($folder,$file_name,$newID){
				$img_file=$_FILES[$file_name]['tmp_name'];
				
				if(strlen($img_file)>4)
				{
				$photofile1 = $folder."/" .$newID . $_FILES[$file_name]['name'];
				copy($img_file, $photofile1); 
				unlink($img_file); 
				$file = $newID . $_FILES[$file_name]['name'];
				 $type1=$_FILES[$file_name]['type'];  
				//create_image($file,$type1);

				}
				else
				{
				$file = "";
				}
				
				
				
				return $file;
		}
		function image_coppy_update($folder,$file_name,$newID,$file_old){
				$f_old=$file_old;
				
				$img_file=$_FILES[$file_name]['tmp_name'];
				if(strlen($img_file)>4)
				{
				$photofile1 = $folder."/" . $newID . $_FILES[$file_name]['name'];
				
				copy($img_file, $photofile1); 
				
				unlink($img_file);
				if(strlen($f_old)>0){ 
							if(file_exists($folder."/" .$f_old))
								unlink( $folder."/" .$f_old); 
							
				}

				$file = $newID . $_FILES[$file_name]['name'];
 				$type1=$_FILES[$file_name]['type'];  
				//create_image($file,$type1);
				}
				else
				{
				$file =$f_old;
				}		
				
				
				return $file;
		}
				
				





function get_image_simple_display($image,$wt,$ht)
{

if(file_exists($image)){
$st=tep_image($image, $alt = '',$wt, $ht, $parameters = '');
}else $st="";
return $st;
}

function get_image_display($folder,$image,$wt,$ht)
{
$image_path=$folder.'/'.$image;

if(file_exists($folder.'/'.$image) && strlen($image)>3){
$st='<a href="'.$folder.'/'.$image.'" target="_blank" >'.tep_image($image_path, $alt = '',$wt, $ht, $parameters = '').'</a>';

}else $st="";
return $st;
}

function del_product_image($folder="product_image",$image){

					if(strlen($image)>4)
						{
						  if(file_exists($folder."/".$image) && strlen($image) > 2) 
							{
							unlink($folder."/".$image); 
						   }
				
				  }				
				
				}



function get_single_field($tablename,$returnfieldname,$condfield,$condvalue){

					$sqln = "SELECT ".$returnfieldname." 
					FROM ".$tablename." where ".$condfield."='$condvalue'";
					$resultn = mysql_query($sqln); 
					if(mysql_num_rows($resultn)>0){
						$row=mysql_fetch_object($resultn);
						return $row->$returnfieldname;
						}else return "";
		}
		
		
		function get_single_field_date($tablename,$returnfieldname,$condfield,$condvalue){

					$sqln = "SELECT 
					DATE_FORMAT(".$returnfieldname.",'%a, %b %d, %Y ') as ".$returnfieldname."
					
					FROM ".$tablename." where ".$condfield."='$condvalue'";
					$resultn = mysql_query($sqln); 
					if(mysql_num_rows($resultn)>0){
						$row=mysql_fetch_object($resultn);
						return $row->$returnfieldname;
						}else return "";
		}
		
			
						
function create_image($image_name,$type=''){

$main_dir="product_image/";
$small_image=$main_dir."60_";
$middle_image=$main_dir."120_";
$small_width=60;
$small_height=60;
$middle_width=120;
$middle_height=120;



if(strlen($image_name)>0){
			
if(strlen($type)<3)
				$type1="image/".substr($image_name,strlen($image_name)-3,3);
			else $type1=$type;



			$thName1=$small_image.$image_name;
			$thName2=$middle_image.$image_name;
			$main_image=$main_dir.$image_name;

 			$thumbnail1 = new thumbnailcreater;
			 $thumbnail2 = new thumbnailcreater;			
			 
			 $thumbnail1 -> creat($thName1,$small_width,$small_height,$main_image,$type1);
			 $thumbnail2 -> creat($thName2,$middle_width,$middle_height,$main_image,$type1);
	 	    

}
}

class thumbnailcreater
{
	function creat($thname,$thumbnailwidth,$thumbnailheight,$image,$type)
	{

		if($type == 'image/gif')
		{
		$mainimage = imagecreatefromgif($image);
		}
		else
		{
		$mainimage = imagecreatefromjpeg($image);
		}
		//get the width and height of main image	
		$mainwidth = imagesx($mainimage);
		$mainheight = imagesy($mainimage);
if($mainwidth<$thumbnailwidth && $mainheight<$thumbnailheight){
	$thumbnailwidth=$mainwidth;
	$thumbnailheight=$mainheight;
}
if($mainwidth>$thumbnailwidth && $mainheight<$thumbnailheight){
	$thumbnailheight=$mainheight;
	
}
if($mainwidth<$thumbnailwidth && $mainheight>$thumbnailheight){
	$thumbnailwidth=$mainwidth;
	
}

		$mythumbnail = imagecreatetruecolor($thumbnailwidth,$thumbnailheight);
		$white = imagecolorallocate($mythumbnail, 255, 255, 255);
		imagefill($mythumbnail,0,0,$white);
		imagecopyresampled($mythumbnail,$mainimage,0,0,0,0,$thumbnailwidth,$thumbnailheight,$mainwidth,$mainheight);
		
if($type == 'image/gif')
		{
		ImageGIF($mythumbnail,$thname,95);
		}
		else
		{
		ImageJPEG($mythumbnail,$thname,95);
		}
	   imagedestroy($mythumbnail);
	   imagedestroy($mainimage);
	 }
 } 
 
 function mysql_is_table($tbl) 
{ 
   $tables = ''; 
   $flag=false;
   
    $q = @mysql_query("SHOW TABLES"); 
    while ($r = @mysql_fetch_array($q))
	 {
	  $tables = $r[0];
	   if (($tbl==$tables))
	   {
	    $flag=true;
		break;
	   }	 
	  } 
    @mysql_free_result($q);   
	 if ($flag)	return TRUE; 
   	 else  return FALSE; 
   
}  


function page_records($page,$pagecount,$recordstart,$perpage,$urlstr){ 




$urlstr_array=explode("&",$urlstr);


$urlstr='';
for($k=0;$k<count($urlstr_array);$k++)
if(strlen($urlstr_array[$k])>0){
$str=explode("=",$urlstr_array[$k]);
if(!($str[0]=='perpage' || $str[0]=='page'))
$urlstr.="&".$urlstr_array[$k];

}



$str='<form name="pagescounter" id="gotopage">  
          <select name="site" class="'.PAGERECORDDROPSELECTIONCLASS.'" onChange="javascript:pageHandler(this.value)">
           ';  
for ($i=1; $i <= $pagecount;$i++){ 
if($i != $page){ 
$str.=' <option value="';
$str.=$_SERVER['PHP_SELF'].'?page='.$i.'&perpage='.$perpage.''.$urlstr;
$str.='">';
$str.= $i; 
$str.='</option>';
} 
else 
{ 
$str.='<option value='.$i.' selected>'.$i;
$str.='</option>';

} 
}//end for 
$str.='
        </select>  
</form>';
return $str;
}//end function 

function display_error_msg($msg){
$st='';
if(strlen($msg)>0)
{
$st='
<table width="100%"  border="0" cellpadding="0"  class="errborder">
  <tr>
    <td>
<table width="100%"  border="0" cellpadding="2" cellspacing="0">
  <tr>
    <td width="9%" align="center">&nbsp;</td>
    <td width="91%" class="errFont">'.$msg.'</td>
  </tr>
</table>
</td>
  </tr>
</table>';
}
return $st;
}
?> 