
function preview_prod_img(obj_upload, preview_img_id, preview_div_id)
{
	var obj_preview_img = document.getElementById(preview_img_id);
	var obj_img_div =document.getElementById(preview_div_id);
	if (obj_upload.value!='')
	{
		obj_preview_img.src = obj_upload.value;
		obj_img_div.style.display='';
	}else
	{
		obj_preview_img.src = '';
		obj_img_div.style.display='none';
	}
}

function GetLeap( year ) {
	if ( year % 400 == 0 )
		return 1;
	else if ( year % 100 == 0 )
		return 0;
	else if ( year % 4 == 0 )
		return 1;
	else
		return 0;
}

function MaxDay(tmpyear,tmpmonth){
	var SolarCal=new Array(12);
	tmpmonth=tmpmonth-1;
	if (GetLeap(tmpyear)){
		SolarCal = [ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
	}else{
		SolarCal = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];        
	}
	return SolarCal[tmpmonth];
}

function IsValidDate(dt_year, dt_month, dt_day, min_year)
{
	var bReturn = false;
	if (IsAllDigital(dt_year) && IsAllDigital(dt_month) && IsAllDigital(dt_day) )
	{
		if (dt_year>=min_year)
		{
			if (dt_month>=1 && dt_month<=12)
			{
				var maxday=MaxDay(dt_year, dt_month);
				if ( dt_day <= maxday && dt_day > 0)
				{
					bReturn = true;
				}
			}
		}
	}
	return bReturn;
}

function IsBirthday(dt_year, dt_month, dt_day)
{
	var now = new Date();
	var min_birth_year = now.getFullYear()-100;
	var bReturn = false;
	if (IsValidDate(dt_year, dt_month, dt_day, min_birth_year))
	{
		bReturn = true;
	}
	return bReturn;
}

function IsPhoneNo(param_value)
{
	var bReturn = false;
	var len = param_value.length;
	if (len>7)
	{
		var idx = 0;
		for(idx = 0 ; idx < len ; idx++)
		{
			c = param_value.charAt(idx);
			if(!((c >= "A" && c <= "Z")||(c >= "a" && c <= "z")||(c >= "0" && c <= "9")||(c == "-")||(c == "_")||(c == ".")||(c == ":")||(c == "(")||(c == ")")||(c == "#")||(c == " "&& idx>0)))
			{
				bReturn = false;
				break;
			}else
			{
				bReturn = true;
			}
		}
	}

	return bReturn;
}

function IsMobileNo(param_value)
{
	var bReturn = false;
	if (param_value.length==10)
	{
		if (IsAllDigital(param_value))
			bReturn = true;
	}
	return bReturn;
}

function IsZip(param_value)
{
	var bReturn = false;
	if (param_value.length>=3 && param_value.length<=5)
	{
		if (IsAllDigital(param_value))
			bReturn = true;
	}
	return bReturn;
}

function IsEmail(em)
{
	var bReturn = false;
	var len = em.length;
	if (len > 0) {
		if( (em.indexOf(".")!=-1) && (em.indexOf(".")!=0) && (em.lastIndexOf(".")!=(len-1)) && (em.indexOf("@")!=-1) && (em.indexOf("@")!=0) && (em.indexOf("@")!=(len-1)) && (em.substring(em.indexOf("@")+1,len).indexOf("@")==-1) ) {
			bReturn = true;
			for(var i = 0; i < len; i++) {
				var c = em.charAt(i);
				if(!((c >= "A" && c <= "Z")||(c >= "a" && c <= "z")||(c >= "0" && c <= "9")||(c == "-")||(c == "_")||(c == ".")||(c == "@"))) {
					bReturn = false;
					break;
				}
			}
		}
	}
	return bReturn;
}

function checkPeriod(start_year, start_mon, start_day, end_year, end_mon, end_day)
{
	var bReturn = false;
	if ( start_year+'-'+start_mon+'-'+start_day <= end_year+'-'+end_mon+'-'+end_day )
	{
		bReturn = true;
	}
	return bReturn;
}

function checkSelect(selx,errmsg) {
    if (selx.options[selx.selectedIndex].value == 0) {
    	if (errmsg!="")
		alert(errmsg);
        return false;
    }
    return true;
}

function checkRadios(radios,errmsg) {
    var radiok=0;
    var i;
    for (i=0; i<radios.length; i++) {
	if (radios[i].checked) {
            radiok=1;
        }
    }
    if (radiok == 0) {
    	if (errmsg.length>0)
        	alert(errmsg);
	return false;
    }
    return true;
}

function checkAsc(param_value)
{
	var bReturn = false;
	var idx = 0;
	for(idx = 0 ; idx < param_value.length ; idx++)
	{
		asc = param_value.charCodeAt(idx);
		if((asc >= 0 && asc <= 47) || (asc >= 58 && asc <= 64) || (asc >= 91 && asc <= 94) || (asc == 96) || (asc >= 123 && asc <= 127))
		{
			bReturn = false;
			break;
		}else
		{
			bReturn = true;
		}
	}
	return bReturn;
}

function IsAllDigital(param_value)
{
   var bReturn = false;
   var idx = 0;
   for (idx = 0; idx < param_value.length; idx++)
   {
      charcode = param_value.charCodeAt(idx);
      if ((charcode >= 48) && (charcode <= 57))
      {
         bReturn = true;
      }
      else
      {
         bReturn = false;
         break;
      }
   }
   return bReturn;
}

function isAllLetter(str)
{
   var chk_result = true;
   for(var i=0 ; i<str.length ; i++) {
      if(str.charAt(i).toLowerCase()<"a" || str.charAt(i).toLowerCase()>"z")
     	chk_result = false;
   }
   return chk_result;
}

function IsLetterDigital(param_value)
{
   var bReturn = false;
   var idx = 0;
   for (idx = 0; idx < param_value.length; idx++)
   {
      charcode = param_value.charCodeAt(idx);
      if (((charcode >= 48) && (charcode <= 57)) || ((charcode >= 65) && (charcode <= 90)) || ((charcode >= 97) && (charcode <= 122)))
      {
         bReturn = true;
      }
      else
      {
         bReturn = false;
         break;
      }
   }
   return bReturn;
}
