function trim(st)
{
	if(st.length > 0)
	{
		re = / +$/g; 
		newval = st.replace(re,"");
		re = /^ +/g;
		newvala = newval.replace(re,"");
		return newvala;
	}
	return "";
}
function IsDate(mMonth, mDay, mYear)
{
	mMonth = parseInt(mMonth);
	mDay = parseInt(mDay);
	mYear = parseInt(mYear);
	var mLeap = false;
	if ( mYear%4 == 0 )
		mLeap = true;
	if ( mMonth == 1 )
	{
		if ( mDay < 1 || mDay > 31 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 2 )
	{
		if ( mLeap )
		{
			if ( mDay < 1 || mDay > 29 )
				return false;
			else
				return true;
		}
		else
		{
			if ( mDay < 1 || mDay > 28 )
				return false;
			else
				return true;
		}
	}
	else if ( mMonth == 3 )
	{
		if ( mDay < 1 || mDay > 31 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 4 )
	{
		if ( mDay < 1 || mDay > 30 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 5 )
	{
		if ( mDay < 1 || mDay > 31 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 6 )
	{
		if ( mDay < 1 || mDay > 30 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 7 )
	{
		if ( mDay < 1 || mDay > 31 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 8 )
	{
		if ( mDay < 1 || mDay > 31 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 9 )
	{
		if ( mDay < 1 || mDay > 30 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 10 )
	{
		if ( mDay < 1 || mDay > 31 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 11 )
	{
		if ( mDay < 1 || mDay > 30 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 12 )
	{
		if ( mDay < 1 || mDay > 31 )
			return false;
		else
			return true;
	}
	else
	{
		return false;
	}
}
// this function opens the popoup window
function WinOpenS(winname,w,h,leftcor,topcor,pname)
{
	window.open( pname , winname, "scrollbars=1,statusbar=no,menubar=no,toolbar=no,resize=null,top=" + topcor + ",left=" + leftcor + ",width=" + w + ",height="+h ).focus();
}

// this function opens the popoup window - resiable windfow
function WinOpenS_new(winname,w,h,leftcor,topcor,pname)
{
	window.open( pname , winname, "scrollbars=1,statusbar=no,menubar=no,toolbar=no,resizable=yes,top=" + topcor + ",left=" + leftcor + ",width=" + w + ",height="+h ).focus();
}
//swapping images
function swap_image(img2,pic_id)
{
	temp = document.getElementById("big_img").src;
	document.getElementById("big_img").src = img2.src + "&nwd=277&nht=277";
	img2.src = temp + "&nwd=127&nht=127";
	show_elg_img('n',pic_id);
}
//openning enlarged image
function show_elg_img(is_open,id) {
	if (is_open == "n") { 
		show_id = id;
	} else {
		pname = "image_popup.php?pid=" + show_id;
		WinOpenS_new('ELWIN','400','400','100','100',pname);
	}
}

function IsEmailValid(email)
{
	email = trim(email);
	valid_chars_for_email = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_@.";
	if ( email == "" )			// pending Email validation
	{
		return false;
	}
	for ( i=0; i < email.length; i++ )
	{
		ch =  "" + email.charAt(i);
		num = valid_chars_for_email.indexOf(ch);
		if ( num == -1 )
		{
			return false;
		}
	}
	if ( email.indexOf('@') == -1 )
	{
		return false;
	}
	if ( email.indexOf('.') == -1 )
	{
		return false;
	}
	return true;
}

function CompareDate(day1, month1, year1, day2, month2, year2)
{
	day1 = day1 * 1;
	month1 = month1 * 1;
	year1 = year1 * 1;
	day2 = day2 * 1;
	month2 = month2 * 1;
	year2 = year2 * 1;
	if ( (year2 == year1) && (month2 == month1) && (day2 == day1) )
	{
		return 0;			// Equal
	}
	else if ( ((year2 > year1)) || ( (year2 == year1) && (month2 > month1) ) || ( (year2 == year1) && (month2 == month1) && (day2 > day1) ) )
	{
		return 2;			//  The second date is greater
	}
	else
	{
		return 1;			// The First Date is greater
	}
}

function ValidateNumeric( ctrl )
{
	var mVal = ctrl.value;
	mVal = trim(mVal);
	if ( isNaN(mVal) || mVal == "" )
	{
		alert (ctrl.title + " should be a numeric value.");
		ctrl.focus();
		return false;
	}
	else 
	{
		return true;
	}
}

function ValidateEmpty( ctrl )
{
	var mVal = ctrl.value;
	mVal = trim(mVal);
	if ( mVal == "" )
	{
		alert (ctrl.title + " can not be blank.");
		ctrl.focus();
		return false;
	}
	else 
	{
		return true;
	}
}
function ValidateImage(ctrl)
{
	if (ctrl.value.length)
	{
		var iPos = ctrl.value.lastIndexOf(".")
		var sExt = ctrl.value.substring(iPos);
		if((sExt.toUpperCase()=='.JPEG') || (sExt.toUpperCase()=='.JPG') || (sExt.toUpperCase()=='.GIF') || (sExt.toUpperCase()=='.BMP') || (sExt.toUpperCase()=='.PNG') )
		{
			return true;
		}
		else
		{
			alert("Please enter valid image.");
			ctrl.focus();
			ctrl.select();
			return false;
		}                       
	}
	else
	{
		alert("Please select the file to be uploaded");
		ctrl.focus();
		ctrl.select();
		return false;
	}
}

// This function checks the validity of the video/clip file

function ValidateVideo(vd_ctrl)
{
	if (vd_ctrl.value.length)
	{
		var st_pos = vd_ctrl.value.lastIndexOf(".")
		var my_str = vd_ctrl.value.substring(st_pos);
		if((my_str.toUpperCase()=='.ASF') || (my_str.toUpperCase()=='.WMV') || (my_str.toUpperCase()=='.WM') || (my_str.toUpperCase()=='.ASX') || (my_str.toUpperCase()=='.WAX') || (my_str.toUpperCase()=='.WVX') || (my_str.toUpperCase()=='.WPL') || (my_str.toUpperCase()=='.WMX') || (my_str.toUpperCase()=='.DVR-MS') || (my_str.toUpperCase()=='.WMD') || (my_str.toUpperCase()=='.AVI') || (my_str.toUpperCase()=='.MPG') || (my_str.toUpperCase()=='.MPEG') || (my_str.toUpperCase()=='.M1V') || (my_str.toUpperCase()=='.MPV2') || (my_str.toUpperCase()=='.MID') || (my_str.toUpperCase()=='.MIDI') || (my_str.toUpperCase()=='.IVF') )
		{
			return true;
		}
		else
		{
			alert("Please enter valid Video.");
			vd_ctrl.focus();
			vd_ctrl.select();
			return false;
		}                       
	}
	else
	{
		alert("Please select the file to be uploaded");
		vd_ctrl.focus();
		vd_ctrl.select();
		return false;
	}
}

	//   This function moves selected Item from List to Another
function MoveSelectedItem ( lstSource, lstTarget )
{
	if (lstSource.selectedIndex != -1)
	{
		var value = lstSource.options[lstSource.selectedIndex].value;
		var text =  lstSource.options[lstSource.selectedIndex].text;
		lstSource.options[lstSource.selectedIndex] = null;
		lstTarget.options[lstTarget.options.length] = new Option(text, value, null ,null );
	}
	else
	{
		alert("First select an Item");
	}
}

		//  This function moves all the items from a list to another
function MoveAllItems ( lstSource, lstTarget )
{
	var Slen = lstSource.options.length;
	var Tlen = lstTarget.options.length;
	if ( Slen )
	{
		for ( i=0; i < Slen; i++ )
		{
			var value = lstSource.options[0].value;
			var text =  lstSource.options[0].text;
			lstSource.options[0] = null;
			lstTarget.options[Tlen + i] = new Option(text, value, null ,null );
		}
	}
	else
	{
		alert("Source List doesnt have any Item");
	}
}

function GetListValues( lstctrl  )
{
   var len = lstctrl.options.length;
   var str = "";
   for( i=0; i < len; i++ )
   {
      str = str + lstctrl.options[i].value + ",";
   }
   return str;
}

function GetListSelectedValues( lstctrl  )
{
   var len = lstctrl.options.length;
   var str = "";
   for( i=0; i < len; i++ )
   {
 		if (lstctrl.options[i].selected)
	     str = str + lstctrl.options[i].value + ",";
   }
   return str;
}
function ValidateCreditCardNo( ctrl )
{
	var mVal = ctrl.value;
	mVal = trim(mVal);
	if ( isNaN(mVal) || mVal == "" )
	{
		alert (ctrl.title + " should be a numeric value.");
		ctrl.focus();
		return false;
	}
	else if(ctrl.value.length!=16)
	{
		alert (ctrl.title + " should be of 16 Digits.");
		ctrl.focus();
		return false;		
	}
	else 
	{
		return true;
	}
}

function ValidateCSV( ctrl )
{
	var mVal = ctrl.value;
	mVal = trim(mVal);
	if ( isNaN(mVal) || mVal == "" )
	{
		alert (ctrl.title + " should be a numeric value.");
		ctrl.focus();
		return false;
	}
	else if(ctrl.value.length!=3)
	{
		alert (ctrl.title + " should be of 3 Digits.");
		ctrl.focus();
		return false;		
	}
	else 
	{
		return true;
	}
}
function ValidateExpiryDate( ctrl_m, ctrl_y )
{
	var md = new Date(); 
	var cur_year = md.getFullYear();
	var cur_month = md.getMonth()+1;			// function gives months from 0-11		for jan-dec
	if(ctrl_y.value<cur_year)
	{
			alert ("Expiry Date not Valid.");
			ctrl_m.focus();
			return false;
	}
	else if(ctrl_y.value==cur_year)
	{
		if(ctrl_m.value<=cur_month)
		{
			alert ("Expiry Date not Valid.");
			ctrl_m.focus();
			return false;
		}
		else
			return true;
	}
	else
		return true;
}

function GetListValues( lstctrl  )
{
   var len = lstctrl.options.length;
   var str = "";
   for( i=0; i < len; i++ )
   {
      str = str + lstctrl.options[i].value + ",";
   }
   return str;
}
function confirm_delete()
{
	var ans = confirm("Do you want to delete Item(s)?");
	return ans;
}


function validateFiledocExtensionemp(fvalue)
 {
     if(fvalue!="")
     { 
         if(!/(\.jpg|\.JPG\.Jpg)$/i.test(fvalue) && !/(\.JPEG|\.Jpeg\.jpeg)$/i.test(fvalue) && !/(\.png|\.PNG\.Png)$/i.test(fvalue) && !/(\.gif|\.gif\.gif)$/i.test(fvalue))
         {
        alert("Please select a jpg/gif/png extension image");
        return false;
        } else{
        return true;
         }
         return false;
     }else{
         return true;
     }
}