//////////////////////////////////////////////////////////////////////////////////////
// Filename : funclib.js
// Writer : Andrew(ratsbomb@gmail.com)
// Create Date : 2005-11-07
// Description : Information Site's javascript in common
// Last Update 
// 02-15-2006
// 12-12-2005 : resizing for Sign Up, added Language Arrays
// +02-15-2006 : added Search Box Form Functions...
// +02-22-2006 : added SelBoxSortyByUserRank function
// +02-24-2006 : modified SelBoxSortyByUserRank function(it called from insert_selCurreny())
//////////////////////////////////////////////////////////////////////////////////////

// Array for Language List
var arrLanguage = new Array();
arrLanguage[1] = new Option('ENGLISH','1');
arrLanguage[2] = new Option('KOREAN','2');
arrLanguage[3] = new Option('JAPANESE','3');
arrLanguage[4] = new Option('CHINESE','4');

// Function Name : insert_selLanguage
// Description : Insert Language List to select box
// Paramter : objForm = form object
// Return : nothing

function insert_selLanguage(objForm)
{ 
	
	var i;
	var objLanguageList = objForm.elements['selLanguage'];			// Select Box Name
	var nCountTotalLanguage;										// number of total Language

	nCountTotalLanguage = arrLanguage.length - 1;

	for (i = 0; i < nCountTotalLanguage; i++) 
	{ 
		objLanguageList.options[i] = arrLanguage[i + 1]; 
	}
} 

// Function Name : insert_selCurrency
// Description : Insert Currency List to select box
// Paramter : objForm = form object
// Return : nothing
function insert_selCurrency(objElement)
{ 
	var i;
	var objCurrencyList;
	var nCountTotalCurrency;										// number of total Currency

	if (objElement == undefined)
		objCurrencyList = document.forms["frmSearchBox"].elements['curr'];			// Select Box Name
	else
		objCurrencyList = objElement;

	nCountTotalCurrency = arrCurrency.length - 1;

	for (i = 0; i < nCountTotalCurrency; i++)
	{ 
		objCurrencyList.options[i] = arrCurrency[i + 1]; 
	}

	// User Rank : Currency's Value List that should be top ranked.
	var arrCurrencyRank = new Array;
	arrCurrencyRank[0] = 'United States Dollars'
	arrCurrencyRank[1] = 'Euro';
	arrCurrencyRank[2] = 'Japan Yen';
	arrCurrencyRank[3] = 'South Korea Won';
	arrCurrencyRank[4] = 'China Yuan Renminbi';
	arrCurrencyRank[5] = 'United Kingdom Pounds';
	arrCurrencyRank[6] = 'Australia Dollars';
	arrCurrencyRank[7] = 'Canada Dollars';
	SelBoxSortByUserRank(objCurrencyList, arrCurrencyRank);
}

// Function Name : insert_selCountry
// Description : Insert Country List to select box
// Paramter : objForm = form object
// Return : nothing
function insert_selCountry(objElement)
{ 
	var i;
	var nCountIdx;
	var objCountryList;

	if (objElement == undefined)
		objCountryList = document.forms["frmSearchBox"].elements["country"];
	else
		objCountryList = objElement;

	var nCountTotalCountry;				// number of total country(source from country.js)

	nCountTotalCountry = arrCountry.length;

	nCountIdx = 1;
	for (i = 1; i < nCountTotalCountry; i++) 
	{
		objCountryList.options[nCountIdx] = arrCountry[i]; 
		nCountIdx = nCountIdx + 1;
	}

	SelBoxSort(objCountryList);
}

// Function Name : fillNextByCountry
// Description : When onChange Country List.
// Paramter : idx = selected country's index's value(countrycode), SelBoxName = select box name(string)
// Return : nothing
function fillNextByCountry(idx)
{
    var objForm = document.forms["frmSearchBox"];
    var objSelect2 = objForm.elements["city"];

    if (idx == "" || idx == "Choose a Country")
    {
        initSelectBox(objSelect2);

    } else
    {
        insert_selCity(idx);
    }
}

// Function Name : insert_selCity
// Description : Insert CityList to select box
// Paramter : nCountryIdx = Country Index Value, arrNotAvailCity =
// Return : nothing
function insert_selCity(nCountryIdx)
{ 
	var i;
	var nCountIdx;

	var objCityList = document.forms["frmSearchBox"].elements["city"];

	// Initializing Select Box
	initSelectBox(objCityList);

	nCountIdx = 0;
	for (i in arrCity[nCountryIdx])
	{
		objCityList.options[nCountIdx] = new Option(arrCity[nCountryIdx][i].text, arrCity[nCountryIdx][i].value); 
		nCountIdx = nCountIdx + 1;
	}

	SelBoxSort(objCityList);
}

// Function Name : initSelectBox
// Description : Initializing Select Box
// Paramter : objElement = Form's Element Object(select box), msg = string that default select message
// Return : nothing
function initSelectBox(objElement, msg)
{
	var i;
	var nLastIndex = objElement.options.length - 1;

	for(i = nLastIndex; i > 0; i--)
	{
		objElement.options[i] = null;
	}

	if (msg == null)
		msg = "Choose a Country First...";

	objElement.options[0] = new Option(msg, ''); 
}

// Function Name : SelBoxSort
// Description : Sorting Select Box
// Paramter : boxIdObj = select box Object(select box), isValuesort = sort by value(default is false, sort by text)
// Return : nothing
function SelBoxSort(boxIdObj, isValuesort) 
{ 
    var obj, sArr, oArr, idx, op; 
    
    if (typeof boxIdObj == 'string') obj = document.getElementById(boxIdObj); 
    else obj = boxIdObj; 

    if (obj.tagName.toLowerCase() != 'select') return false; 
    if (typeof isValuesort == 'undefined') isValuesort = false; 

    sArr = new Array(obj.options.length); 
    oArr = new Array; 

    for (idx = 1; idx < obj.options.length; idx++) 
    { 
        if (isValuesort) sArr[idx] = obj.options[idx].value; 
        else
		{
			sArr[idx] = obj.options[idx].text.toUpperCase(); 
		}
        oArr[sArr[idx]] = obj.options[idx]; 
    } 
    sArr.sort(); 

	var i;
    for (i = 0; i < sArr.length - 1; i++)
	{
		obj.appendChild(oArr[sArr[i]]); 
	}
}

// Function Name : checkSearchForm
// Description : when onClick Search Button, Check out Form Values in Search Box.(in Hostel Booking)
// Paramter : SelBoxName = select box name(string), BookStartDate = Server's Book Enable Date
// Return : nothing
function checkSearchForm(BookStartDate)
{
    var objForm = document.forms["frmSearchBox"];
    var objSelect2 = objForm.elements["city"];
    var UserSelectValue = objSelect2.options[objSelect2.selectedIndex].value;
	var objCurrency = objForm.elements["selCurrency"];

    // Get Server's Date
    var sBookDate = BookStartDate.split("/");
    var sYear = sBookDate[2];
    var sMonth = sBookDate[0];
    var sDay = sBookDate[1];
    var xSec=1000;
    var xMin=1000*60;
    var xHour=xMin*60;
    var xDate=xHour*24;

    // Get User's Date
    var userGetDate = objForm.elements["start"].value;
    var userDate = userGetDate.split("/");
	var userYear = userDate[2];
    var userMonth = userDate[0];
    var userDay = userDate[1];
    //var userYear = objForm.elements["ArrvYear"].value;
    //var userMonth = objForm.elements["ArrvMonth"].value;
	//userMonth = userMonth.substring(0, 2);
	//userMonth = parseInt(userMonth, 10);
    //var userDay = objForm.elements["ArrvDay"].value;
    
    var sTime = Date.UTC(sYear, sMonth, sDay);
    var uTime = Date.UTC(userYear, userMonth, userDay);

    var gap = Math.round((uTime - sTime)/xDate);

    if (UserSelectValue == "" || UserSelectValue == "Choose a Country First")
    {
        alert("You should select country first...");
        // Need Line highlighting
        objForm.elements["country"].focus();
        return false;
    }

    if (gap < 0)
    {
        alert("You can not search such a day, change a date...");
        // Need Line highlighting
        return false;
    }

	// added 6 lines by Andrew, 02-24-2006
	if (objCurrency.value == "")
	{
		alert("You must select your currency");
		objCurrency.focus();
		return false;
	}

	objForm.target = "_blank";
	objForm.submit();
    return false;
}

// Add to Favorite
function AddtoFavorite(favoriteUrl, favoriteTitle)
{
	if (document.all)
	{
		window.external.AddFavorite(favoriteUrl,favoriteTitle);
	}
}

//--------------------------- Inbox Account -------------------------//
//validate web address
function notWebAddress(field, fieldName, msg) {

	var webaddress = trim(field.value)

	if (webaddress == "") return false

	var http = false
	var dot = false

	if (webaddress.match("http://"))
	{
		if (webaddress.length == 7)
			return false;
		http = true
		for (var i=0; i<webaddress.length; i++)
		{
			if (webaddress.charAt(i) == ".") dot = true
		}
	}

	if (!(http && dot && webaddress.length > 10)) {
		if (msg == null)
			msg = "The " + fieldName + " you entered is not a valid web address."

		alert(msg)
		field.focus()
		field.select()
		return true
	}

	//check for invalid characters
	if (invalidChars(field, "Web Address", '@#$^*()+={}[]`%,;|" <>\\')) return true

	return false
}

// Function Name : SelBoxSortByUserRank
// Description : Sorting Select Box, By User Rank(value)
// Paramter : boxIdObj = select box Object(select box), isValuesort = sort by value(default is false, sort by text)
// Return : nothing
function SelBoxSortByUserRank(boxIdObj, arrUserRank) 
{ 
    var obj, sArr, oArr, idx, op;
	var i;
	var nUserRankCount;						// User Rank's Number(Array Length)
	var nSortedTextLength;
	var strSeparatorChar = '-----------------------------';

	nUserRankCount = arrUserRank.length;

    if (typeof boxIdObj == 'string') obj = document.getElementById(boxIdObj); 
    else obj = boxIdObj; 

    if (obj.tagName.toLowerCase() != 'select') return false; 

    sArr = new Array(obj.options.length); 
	oArr = new Array; 

	// Sort By Text Value(Alphabetic)
    for (idx = 0; idx < obj.options.length; idx++) 
    { 
		sArr[idx] = obj.options[idx].text.toUpperCase(); 
        oArr[sArr[idx]] = obj.options[idx];
    } 
	oArr[strSeparatorChar] = new Option(strSeparatorChar, '');
    sArr.sort(); 

	// Sort By User Rank
	var arrNewRank = new Array;
	var IsRank = false;
	/*
	for (i = 0; i < sArr.length; i++)
	{
		for (j = 0; j < nUserRankCount; j++)
		{
			if (oArr[sArr[i]].value == arrUserRank[j])
			{
				IsRank = true;
			}
		}

		if (IsRank != true)
		{
			arrNewRank.push(sArr[i]);				// add bottom of array
		} else
		{
			arrNewRank.unshift(sArr[i]);			// add top of array
			IsRank = false;
		}
	}
	*/
	for (i = 0; i < nUserRankCount; i++)
	{
		for (j = 0; j < sArr.length; j++)
		{
			if (arrUserRank[i].toUpperCase() == sArr[j])
			{
				arrNewRank.push(sArr[j]);
				//alert(sArr[j] + " value = " + oArr[sArr[j]].value + " / value : " + arrUserRank[i]);
			}
		}
	}

	arrNewRank.push(strSeparatorChar);

	for (i = 0; i < sArr.length; i++)
	{
		for (j = 0; j < nUserRankCount; j++)
		{
			if (sArr[i] == arrNewRank[j])
			{
				IsRank = true;
				break;
			}
		}

		if (IsRank != true)
		{
			arrNewRank.push(sArr[i]);
		} else
		{
			IsRank = false;
		}
	}

    for (i = 0; i < arrNewRank.length; i++)
	{
		obj.appendChild(oArr[arrNewRank[i]]); 
	}

	obj.options[0].selected = true;
}
//--------------------------- Admin Account -------------------------//
// Window Position  Setting to Center in Monitor
// Body Onload Event
function set_window_pos()
{
	var scrWidth = window.screen.width;
	var scrHeight = window.screen.height;
	var left = (scrWidth - 290) / 2;
	var top = (scrHeight - 165) / 2;

	this.resizeTo(290, 165);
	this.moveTo(left, top);
}
// Form(select, radio, checkbox) initialize by value
function select_input(input_name,input_value) {
    for ( i = 0 ; i < document.forms.length; i ++ ) {
        for ( j = 0 ; j < document.forms[i].elements.length; j++) {
            with(document.forms[i].elements[j]) {
                if(name == input_name) {
                    if( value == input_value) { checked=true; }
                        else if(type!='radio' && type != 'checkbox') { value=input_value; }
                }
            }
        }
    }
}

// Form(select, radio, checkbox) initialize by value
// Same upper, form_name added
function select_input2(form_name,input_name,input_value) {
    form_name = eval("document."+form_name);
    for ( j = 0 ; j < form_name.elements.length; j++) {
        with(form_name.elements[j]) {
            if(name == input_name) {
                if( value == input_value) { checked=true; }
                    else if(type!='radio' && type != 'checkbox') { value=input_value; }
            }
        }
    }
}

// Select Tag Initialize by value.
// obj : select name, value : option value
function setSelect(obj,value)
{
	if(value)
	{
		var tgtObj = document.getElementById(obj);
		tgtObj.value = value;
	}
}

// Edit Selected Affiliate Information
function edit_select()
{
	var s = get_sequence_string();
	if ( s == "" )
	{
		alert( "There are no selected affiliates..." );
		return;
	}
	var dm = "";
	if ( dm != "" || confirm( "Are  you sure that selected affiliate to edit??" ) )
	{
		//location = '/AUTH/mail.cgi?c=d&fm=&rnd=437b7cd117ff5145&m=SU5CT1g@&dm='+dm+'&n='+s+'&sk=&st=&so=0msgno&nc=l&r=0';
		alert(s);
	}
}

function approve_select()
{
	var s = get_sequence_string();
	if ( s == "" )
	{
		alert( "There are no selected affiliates..." );
		return;
	}
	var dm = "";
	if ( dm != "" || confirm( "Are  you sure that selected affiliate to approve??" ) )
	{
		//location = '/AUTH/mail.cgi?c=d&fm=&rnd=437b7cd117ff5145&m=SU5CT1g@&dm='+dm+'&n='+s+'&sk=&st=&so=0msgno&nc=l&r=0';
		alert(s);
	}
}

// Get Checkbox Number String.(delimiter ",")
function get_sequence_string(form_name)
{
	var s = "";
	//var o = document.frmAccount.chkbox;
	var o = eval("document." + form_name + ".chkbox");
	if ( o != null )
	{
		var lenobj = eval(o.length);
		if(lenobj != null)
		{	
			for ( var i = 0 ; i < o.length ; i++ )
			{
				if ( o[i].checked )
					s += (( s.length > 0 ? "," : "" ) + o[i].value );
			}
		}
		else {
			if ( o.checked )
				s += (( s.length > 0 ? "," : "" ) + o.value );
		}
	}
	return s;
}

// Change Table Row Color 
function display_row(cnt, form_name)
{
	var tcolor='#F5FBF2';
	var fcolor='ffffff';
	var val;
	var o;
		
   // var o=document.frmAccount.chkbox;
	o = eval("document." + form_name + ".chkbox");
    if ( o.length != null ){
        clr = ( o[cnt-1].checked == true ) ? tcolor: fcolor; 
	}
	else
	{
		clr = ( o.checked == true ) ? tcolor: fcolor; 
	}
    val = "tr_" + cnt; 	

	eval(val).style.backgroundColor= clr;
}

var __select_mode = 0;

// SELECT/UNSELECT ALL CHECKBOX
function select_message(form_name)
{
	var value;
	var clr;
	var o = document.all['allsel'];

	if ( __select_mode == 0 )
	{
		value = true;
		__select_mode = 1;
		o.innerHTML = "UNSELECT ALL";
		clr = '#F5FBF2';	
	}
	else
	{
		value = false;
		__select_mode = 0;
		o.innerHTML = "SELECT ALL";
		clr = '#FFFFFF';	
	}
	//o = document.frmAccount.chkbox;
	//o = document.frmMember.chkbox;
	o = eval("document." + form_name + ".chkbox");

	if ( o != null )
	{
		if ( o.length != null ) 
		{
			for ( var i = 0 ; i < o.length ; i++ )
			{
				o[i].checked = value;
				display_row(i+1, form_name);
			}
		}
		else 
		{
			o.checked = value;
			display_row(1, form_name);
		}
	} 
}

// Close Window in Time
function startTime(){ 
        var time= new Date(); 
        hours= time.getHours(); 
        mins= time.getMinutes(); 
        secs= time.getSeconds(); 
        closeTime=hours*3600+mins*60+secs; 
        closeTime+=5;  // This number is how long the window stays open 
        Timer(); 
} 

function Timer(){ 
        var time= new Date(); 
        hours= time.getHours(); 
        mins= time.getMinutes(); 
        secs= time.getSeconds(); 
        curTime=hours*3600+mins*60+secs 
        if (curTime>=closeTime){ 
                self.close();} 
        else{ 
                window.setTimeout("Timer()",1000)} 
} 

// Change Cell Color in Table HTML Tag
function mouse_over(src, m_over){ 
  if (!src.contains(event.fromElement)) { 
   src.bgColor = m_over; 
  }
}

function mouse_out(src,m_out) { 
  if (!src.contains(event.toElement)) { 
   src.style.cursor = 'default'; 
   src.bgColor = m_out; 
  }
}

// Confirm Delete Command
function confirmDel(form, idx)
{
	if (confirm("Are you sure this deletion?\n it will be deleted!!!"))
	{
		form.idx.value = idx;
		form.submit();
	} 
	return true;
}

//open new window
function openWnd(url, name, height, width, directories, location, menubar, resizable, scrollbars, status, toolbar) {
	wnd = window.open(url, name, "alwaysRaised=1,height=" + height + ",width=" + width + ",directories=" + directories + ",locaton=" + location + ",menubar=" + menubar + ",resizable=" + resizable + ",scrollbars=" + scrollbars + ",status=" + status + ",toolbar=" + toolbar)
	wnd.focus()

}

//check whether text-box is empty
function isEmpty(field, fieldName, msg) {
	if (trim(field.value) == "") {
		if (msg == null)
			msg = "You Did Not Provide A Value For " + fieldName + ".\n\nPlease Provide One."

		alert(msg)
		field.focus()
		return true
	}

	return false
}


//
// This function is to check if the length of the value of a form is satisfied with a length restriction.
// "field" is the name of the field.
// "fieldName" that is used for alert is the display name of the field.
// "max" is the maximum length
// "min" is the minimum length
function chkLength(field,fieldName,max,min,msg)
{
	var tField=trim(field.value);
	if((tField.length > 0 && tField.length < min) || tField.length > max)
	{
		if(msg==null)
		{
			alert(msg);
		}else{
			alert(fieldName+" should be either longter than "+ min +" characters or shorter than "+max+" characters.");
		}
		field.focus();
		return false;
	}else{
		return true;
	}
}

//trim string
function trim(stringToTrim) {
	var i, j

	//left trim
	for(i=0; i<stringToTrim.length; i++) {
		if (stringToTrim.charAt(i) != " ") break
	}

	//right trim
	for(j=stringToTrim.length-1; j>=i; j--) {
		if (stringToTrim.charAt(j) != " ") break
	}

	return stringToTrim.substring(i, j + 1)
}

//validate email address
function notEmail(field, fieldName, msg) {
	var email = trim(field.value)

	if (email == "") return false

	var at = false;
	var at_cnt=0;
	var dot = false;

	for (var i=0; i<email.length; i++) {
		if (email.charAt(i) == "@"){
			at = true;
			at_cnt=at_cnt+1;
		}
		if (email.charAt(i) == "." && at) dot = true
	}

	if (!(at && at_cnt<2 && dot && email.length > 5)) {
		if (msg == null)
			msg = "The " + fieldName + " you entered is not a valid e-mail address."

		alert(msg)
		field.focus()
		field.select()
		return true
	}

	//check for invalid characters
	if (invalidChars(field, "E-mail", '!#$%^&*(),;:|"\\ \'?[]{}<>\\/')) return true

	return false
}

//check whether passed validated control contains any of passes invalid characters (case insensitive)
function invalidChars(validatedControl, validatedName, charString, msg) {
	var validatedString = trim(validatedControl.value).toLowerCase()
	charString = charString.toLowerCase()

	for (var i=0; i<validatedString.length; i++) {
		for (var j=0; j<charString.length; j++) {
			if (validatedString.charAt(i) == charString.charAt(j)) {

				if (typeof (Common_Scripts_FuncLib_Space) == "undefined")
					Common_Scripts_FuncLib_Space = "space"

				var alertString = charString.split("").join("  ")
				alertString = alertString.split("     ").join("  " + Common_Scripts_FuncLib_Space + "  ")

				if (msg == null)
					msg = validatedName + " cannot contain any of the following illegal characters:\n\n " + alertString

				msg = msg.replace(/\[IllegalCharacters\]/, alertString)
				alert(msg)
				validatedControl.focus()
				return true
			}
		}
	}

	return false
}


// when click the input box, input box area cleared.
function clearText(thefield){
	if (thefield.defaultValue==thefield.value)
		thefield.value = ""
} 

// select all textarea's contents
function selectAll(element) {
  var tval = eval("document.selForm." + element)
  tval.focus()
  tval.select()
}

// toggle div area show & hide
function toggleDiv(element) {
	if (element.style.display == "none")
		{ element.style.display = ""; }
	else 	{ element.style.display = "none";
	}
}





//'===========================================================================================================
//' Addtional Functions were added by sooyong Kim
//'===========================================================================================================

//
function CheckIDOK(field)
{

	//var loginid = document.frmSignUp.txLoginID.value;
	var loginid = field.value;
	//var format = /^\[ \t]+$/;
	if (loginid == "")
	{
		alert("Please Enter Login ID...");
		//document.frmSignUp.txLoginID.focus();
		field.focus();
		return;
	}
	
	for (i = 0 ; i < loginid.length ; i++) {
		chkId = loginid.charAt(i);
		if ((chkId < '0' || chkId > '9')&&(chkId < 'a' || chkId > 'z')&&(chkId < 'A' || chkId > 'Z')) {
			alert("You can only use numeric or alphabetical characters.\n\n Neither are spcial characters such as %,#,and @ nor spaces allowed to use");
			loginid = "";
			//document.frmSignUp.txLoginID.focus();
			field.focus();
			return;
		}
	}

	if(loginid.charAt(0)>0 || loginid.charAt(0)<9)
	{
		alert("You can't have your ID starting with a numeric character.");
		//document.frmSignUp.txLoginID.focus();
		field.focus();
		return;
	}

	if(loginid.length < 4 || loginid.length >16){
		alert("The length of your ID should be either \n\nlonger that 4 characters or shorter than 16 characters.");
		//document.frmSignUp.txLoginID.focus();
		field.focus();
		return;
	}
	openWnd('mdCheckIDOK.asp?loginid=' + loginid,'CHECKID',200,300,0,0,0,1,1,0,0);
	flagCheckID = true;
}


// This function calls a pop-up window where a user should check the ID
function CheckID()
{
	var loginid = document.frmSignUp.txLoginID.value;
	alert("You provided "+loginid+". \n\n Please check your ID if it's validate");
}

function confirmPwd(field1,field2)
{
	var fstPwd=field1.value;
	var sndPwd=field2.value;

	if (fstPwd != sndPwd)
	{
		alert(msgSIGNUP_PWDNOMATCH);
		fstPwd = "";
		sndPwd = "";
		field1.focus();
		return false;
	}
	return true;
}

// Check Number Or Dash Character
function checkNumDash(field,fieldName)
{

	if(field.value=="")
	{
		return true;
	}else{
		var regNumDash = /^[0-9 ]+([0-9 ]|[\- ]{1})+$/; 

		pattern = regNumDash;

		if(!pattern.test(field.value))
		{ 
			alert("The "+fieldName+" that you provided is Invalid Type.\nYou Should Provide Numbers or - (dash) For "+fieldName+".\n"); 
			field.focus(); 
			return false; 
		}
		field.value=trim(field.value);
		return true; 
	}
}

// Check PostelCode
function checkPostelCode(field,fieldName)
{

	if(field.value=="")
	{
		return true;
	}else{
		var regNumDash = /^([a-zA-Z ]|[0-9])+([a-zA-Z ]|[0-9 ]|[\- ]{1})+$/; 

		pattern = regNumDash;

		if(!pattern.test(field.value))
		{ 
			alert("The "+fieldName+" that you provided is Invalid Type.\nYou Should Provide Alphabet or Numbers or - (dash) For "+fieldName+".\n"); 
			field.focus(); 
			return false; 
		}
		field.value=trim(field.value);
		return true; 
	}
}

// type==1 the name of a company
// type==2 a person's name


function checkNameType(field,fieldName,types){
	

	if(field.value=="")
	{
		
		return true;
	}else{
		
		
		if(types=='1'){
			
			var regNameType=/^([a-zA-Z ]|[0-9])+(([0-9]|[a-zA-Z])|[\'\., ])+([0-9]|[a-zA-Z \.,]{1})+$/;
			var msg="The "+fieldName+" that you provided is Invalid Type.\nYou Should Provide Alphabets,Numbers or '(single quote) For "+fieldName+".\n";
			
		}else if(types=='2'){
			var regNameType=/^[a-zA-Z ]+([a-zA-Z]|[\. ])+([a-zA-Z\. ]{1})+$/;
			var msg="The "+fieldName+" that you provided is Invalid Type.\nYou Should Provide Alphabets or .(dot) For "+fieldName+".\n";
		}
		pattern=regNameType;
		
		if(!pattern.test(field.value))
		{
			alert(msg); 
			field.focus(); 
			return false; 
		}else{
			field.value=trim(field.value);
			return true; 
		}
		
	}

}


// type 1 : for numbers
// type 2 : for characters
// type 3 : for characters and comma
function checkOneType(field,fieldName,types){
	if(field.value=="")
	{
		return true;
	}else{
		if(types=='1'){
			var regOneType=/^[0-9 ]+$/;
			var msg="You should use ONLY NUMBERS for "+fieldName;
		}else if(types=='2'){
			var regOneType=/^[a-zA-Z ]+$/;
			var msg="You should use only Alphabets for "+fieldName;
		}else if(types=='3'){
			var regOneType=/^[a-zA-Z ,]+$/;
			var msg="You should use Alphabets and , (comma) for "+fieldName;
		}
		pattern=regOneType;

		if(!pattern.test(field.value)){
			alert(msg);
			field.focus();
			return false;
		}else{
			field.value=trim(field.value);
			return true;
		}
	}
}

function checkEmail(field,fieldName,msg)
{
	
	if(field.value=="")
	{
		return true;
	}else{
		var msg=null;
		var retn_value=notEmail(field, fieldName, msg);
		return retn_value;
	}
}

function checkDateType(field,fieldName){
	if(field.value==""){
		return true;
	}else{
		var regDate=/^([0-9]|[0-9][0-9]){1}\-([0-9]|[0-9][0-9]){1}\-([0-9]{2}|[0-9]{4}){1}$/
		var msg="The Date,"+field.value+", you provided is invalid type\n\nPlease check it again.\n\nex) 11-19-2005(month-day-year)";

		pattern=regDate;
		if(!pattern.test(field.value)){
			alert(msg);
			field.focus();
			return false;
		}else{

			return true;
		}
	}
}

function checkAddress(field,fieldName){
	if(field.value==""){
		return true;
	}else{
		var regAddr=/^([0-9#@ ]|[a-zA-Z@# ])+[\w\.\s\-@&,]*([0-9\. ]|[a-zA-Z\. ])$/
		var msg="The Address, "+field.value+", That You Provide \nIs Invalid Type.Please Check It Again.";

		pattern=regAddr;
		if(!pattern.test(field.value)){
			alert(msg);
			field.focus();
			return false;
		}else{

			return true;
		}
	}
}

