﻿function showewsDetail(artid,catid,opennew){
    if (opennew==0){
        document.location.href = '?ins=det&cat='+catid+'&artid='+artid;

    }else{
        window.open('?ins=det&cat='+catid+'&artid='+artid,'','','resizable,scrollbars');
    }
}
function showProdetail(artid,catid,opennew){
}
function checkNumber(st){
		if (!checkNumber_real(st)){
			alert("Invalid number!");
			return false;
		}
		return true;
	}




function checkDate(valueDate) {
	ok = true;

	if (valueDate.toString().length > 0)
	{
		if (isNaN(Date.parse(valueDate))) 
		{
			ok = false;
		}
		else {
			pos = valueDate.toString().lastIndexOf("/");			
			year = valueDate.toString().substr(pos + 1);
			
			if (year.toString().length != 4) {
				ok = false;
			}
			else {
				if (isNaN(year.toString())) {
					ok = false;
				}
			}
		}		
	}	
	
	return ok;
}


//************************************************************************************************		

function checkZip(valueZip) {
	ok = true;
	
	if ((valueZip.toString().length > 0) && (valueZip.toString() != "-")) {
		zip1 = valueZip.toString().substr(0,5);
		zip2 = valueZip.toString().substr(5,1);
		zip3 = valueZip.toString().substr(6,4);
		
		if (valueZip.toString().length == 10) { 	
			if ((isNaN(zip1)) || (zip2 != "-") || (isNaN(zip3))) {
				ok = false;
			}
		}	
		else if (valueZip.toString().length == 5) { 	
			if (isNaN(zip1)) {
				ok = false;
			}	
		}	
		else {
			ok = false;
		}
	}
	
	return ok;
}

//************************************************************************************************		

function checkPhone(valuePhone) {
	ok = true;	
	
	if (valuePhone.toString().length > 0) {
		phone1 = valuePhone.toString().substr(0, 1);
		phone2 = valuePhone.toString().substr(1, 3);
		phone3 = valuePhone.toString().substr(4, 1);
		phone4 = valuePhone.toString().substr(5, 3);
		phone5 = valuePhone.toString().substr(8, 1);	
		phone6 = valuePhone.toString().substr(9, 4);		
		phone7 = valuePhone.toString().substr(13, 1);		
		phone8 = valuePhone.toString().substr(14, 6);			
	
		if (valuePhone.toString().length == 20) { 	
			if ((phone1 != "(") || (isNaN(phone2)) || (phone3 != ")") || (isNaN(phone4)) || (phone5 != "-") || (isNaN(phone6)) || (phone7 != "-") || (isNaN(phone8))) {
				ok = false;
			}
		}	
		else if (valuePhone.toString().length == 13) {
			if ((phone1 != "(") || (isNaN(phone2)) || (phone3 != ")") || (isNaN(phone4)) || (phone5 != "-") || (isNaN(phone6))) {
				ok = false;
			}
		}	
		else {
			ok = false;
		}	
	}
	
	return ok;
}
//************************************************************************************************

function checkInteger_negative(valueInteger) {
	ok = true;	

	if (valueInteger.toString().indexOf(",") != -1) {
		valueInteger = valueInteger.toString().replace(",", "")
	}

	if (valueInteger.toString().length > 0) {
		if (isNaN(valueInteger) || (valueInteger.toString().indexOf(".") != -1))
		{
			ok = false;
		}
	}
	
	return ok;
}
//************************************************************************************************

function checkInteger(valueInteger) {
	ok = true;	

	if (valueInteger.toString().indexOf(",") != -1) {
		valueInteger = valueInteger.toString().replace(",", "")
	}

	if (valueInteger.toString().length > 0) {
		if (isNaN(valueInteger) || (valueInteger < 0) || (valueInteger.toString().indexOf(".") != -1))
		{
			ok = false;
		}
	}
	
	return ok;
}
//************************************************************************************************
function checkInteger_div(valueInteger) {
	ok = true;	
	var pos;
	pos = valueInteger.toString().indexOf(",");
	while (pos != -1) {
		valueInteger = valueInteger.toString().replace(",", "")
		pos = valueInteger.toString().indexOf(",");
	}

	if (valueInteger.toString().indexOf(".00") != -1) {
		valueInteger = valueInteger.toString().replace(".00", "");
	}

	if (valueInteger.toString().length > 0) {
		if (isNaN(valueInteger) || (valueInteger < 0) || (valueInteger.toString().indexOf(".") != -1))
		{
			ok = false;
		}
	}
	
	return ok;
}
//************************************************************************************************
function return_Integer(valueInteger) {
	var pos;
	pos = valueInteger.toString().indexOf(",");
	while (pos != -1) {
		valueInteger = valueInteger.toString().replace(",", "")
		pos = valueInteger.toString().indexOf(",");
	}

	if (valueInteger.toString().indexOf(".00") != -1) {
		valueInteger = valueInteger.toString().replace(".00", "");
	}

	
	return valueInteger;
}
//************************************************************************************************

function checkNumberzero(valueInteger) {
	ok = true;

	if (valueInteger.toString().length > 0) {
		if (isNaN(valueInteger) || (valueInteger < 0))
		{
			ok = false;
		}
	}
	
	return ok;
}
//************************************************************************************************

function checkNumber_real(valueInteger) {
	ok = true;

	if (valueInteger.toString().length > 0) {
		if (isNaN(valueInteger))
		{
			ok = false;
		}
	}
	
	return ok;
}

//************************************************************************************************

function checkNum(valueNumber) {
	ok = true;
	countCham = 0;
	
	if (valueNumber.toString().length > 0) {
		if (valueNumber.toString().indexOf("%") == valueNumber.toString().length - 1) {
			valueNumber = valueNumber.toString().replace("%", "");
		}
		pos = valueNumber.toString().indexOf(",");
		while (pos != -1) {
		//if (valueNumber.toString().indexOf(",") != -1) {
			valueNumber = valueNumber.toString().replace(",", "");
			pos = valueNumber.toString().indexOf(",");
		}
			
		if (isNaN(valueNumber) || (valueNumber < 0)) {
			ok = false;
		}
	}

	return ok;
}

// Original JavaScript code by Duncan Crombie: dcrombie@chirp.com.au
// Please acknowledge use of this code by including this header.

// CONSTANTS
var separator = ",";  // use comma as 000's separator
var decpoint = ".";  // use period as decimal point
var percent = "%";
var currency = "$";  // use dollar sign for currency

					function formatNumber(number, format, print) {  // use: formatNumber(number, "format")
	if (print) document.write("formatNumber(" + number + ", \"" + format + "\")<br>");

	if (number - 0 != number) return null;  // if number is NaN return null
	var useSeparator = format.indexOf(separator) != -1;  // use separators in number
	var usePercent = format.indexOf(percent) != -1;  // convert output to percentage
	var useCurrency = format.indexOf(currency) != -1;  // use currency format
	var isNegative = (number < 0);
	number = Math.abs (number);
	if (usePercent) number *= 100;
	format = strip(format, separator + percent + currency);  // remove key characters
	number = "" + number;  // convert number input to string

	 // split input value into LHS and RHS using decpoint as divider
	var dec = number.indexOf(decpoint) != -1;
	var nleftEnd = (dec) ? number.substring(0, number.indexOf(".")) : number;
	var nrightEnd = (dec) ? number.substring(number.indexOf(".") + 1) : "";

	 // split format string into LHS and RHS using decpoint as divider
	dec = format.indexOf(decpoint) != -1;
	var sleftEnd = (dec) ? format.substring(0, format.indexOf(".")) : format;
	var srightEnd = (dec) ? format.substring(format.indexOf(".") + 1) : "";

	 // adjust decimal places by cropping or adding zeros to LHS of number
	if (srightEnd.length < nrightEnd.length) {
	  var nextChar = nrightEnd.charAt(srightEnd.length) - 0;
	  nrightEnd = nrightEnd.substring(0, srightEnd.length);
	  if (nextChar >= 5) nrightEnd = "" + ((nrightEnd - 0) + 1);  // round up

	// patch provided by Patti Marcoux 1999/08/06
	  while (srightEnd.length > nrightEnd.length) {
	    nrightEnd = "0" + nrightEnd;
	  }

	  if (srightEnd.length < nrightEnd.length) {
	    nrightEnd = nrightEnd.substring(1);
	    nleftEnd = (nleftEnd - 0) + 1;
	  }
	} else {
	  for (var i=nrightEnd.length; srightEnd.length > nrightEnd.length; i++) {
	    if (srightEnd.charAt(i) == "0") nrightEnd += "0";  // append zero to RHS of number
	    else break;
	  }
	}

	 // adjust leading zeros
	sleftEnd = strip(sleftEnd, "#");  // remove hashes from LHS of format
	while (sleftEnd.length > nleftEnd.length) {
	  nleftEnd = "0" + nleftEnd;  // prepend zero to LHS of number
	}

	if (useSeparator) nleftEnd = separate(nleftEnd, separator);  // add separator
	var output = nleftEnd + ((nrightEnd != "") ? "." + nrightEnd : "");  // combine parts
	output = ((useCurrency) ? currency : "") + output + ((usePercent) ? percent : "");
	if (isNegative) {
	  // patch suggested by Tom Denn 25/4/2001
	  output = (useCurrency) ? "(" + output + ")" : "-" + output;
	}
	return output;
}
function strip(input, chars) {  // strip all characters in 'chars' from input
	var output = "";  // initialise output string
	for (var i=0; i < input.length; i++)
	  if (chars.indexOf(input.charAt(i)) == -1)
	    output += input.charAt(i);
	return output;
}
function separate(input, separator) {  // format input using 'separator' to mark 000's
	input = "" + input;
	var output = "";  // initialise output string
	for (var i=0; i < input.length; i++) {
	  if (i != 0 && (input.length - i) % 3 == 0) output += separator;
	  output += input.charAt(i);
	}
	return output;
}
function isValidEmail(strEmail){
	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	strEmail = strEmail.value;

	if (strEmail.search(validRegExp) == -1){
		return false;
	}
	return true; 
	}
function checkEmail(strEmail) {	    
		if (!isValidEmail(strEmail)){
			alert("Xin kiểm tra lại địa chỉ Email!");
			return false;
		}
		return true;
}

function SelectedCb(form_name, val) {    $(form_name).select('option').each(function(item) { if (item.value == val) { item.selected = true; } });    }
function SelectedCbChange(form_name, textname) {$(form_name).observe('change', function() { $(textname).value = $F(form_name) });}
function checkRq(form_name, id) {    
    var ok = true;
    $(form_name).getElements().findAll(function(item) { return (item.name).include('xfb_item') && (item.value == "") }).each(function(item) { ok = false; item.focus() })        
if (!ok) {
    alert("Xin điền đầy đủ thông tin cần thiết");    
} else {
$(form_name).action = '/admin/webs.aspx';
$(form_name).request({
    method: 'post',
    parameters: { f: 'sentmail', fbid: id },
    onFailure: function(transport) { $("thank").update(transport.responseText); },
    onComplete: function(transport) { $("thank").update(transport.responseText); }
})


                };
return false
	}
	function checkusr() {
	    new Ajax.Request('/admin/webs.aspx', {
	        method: 'post',
	        parameters: { f: "checkusr",
	            usrok: $("usrok").innerHTML
	        }
                        , onFailure: function(transport) { $("usr").innerHTML = transport.responseText; }
                        , onSuccess: function(transport) {
                            if (transport.responseText == "false") {
                                $("usr").innerHTML = $("usrfalse").innerHTML;
                            } else {
                                $("usr").innerHTML = transport.responseText;
                            }
                        }
	    });
	}
	function logout() {
	    new Ajax.Request('/admin/webs.aspx', {
	        method: 'post',
	        parameters: { f: "Logout"
	        }
                        , onFailure: function(transport) { }
                        , onSuccess: function(transport) {
                            if (transport.responseText == "true") { document.location.href = document.location.href; }
                        }
	    });
	}
	function logmein() {
	    new Ajax.Request('/admin/webs.aspx', {
	        method: 'post',
	        parameters: { f: "Logmein",
	            usrName: $("usrName").value,
	            UsrPassword: $("pwd").value
	        }
                        , onFailure: function(transport) { }
                        , onSuccess: function(transport) {
                            if (transport.responseText == "false") {
                                $("usrMess").innerHTML = "T&#234;n ho&#7863;c m&#7853;t kh&#7849;u sai !";
                            } else {
                                document.location.href = document.location.href;
                            }
                        }
	    });
	}
	function loading() { $("ajax-loader-light").setStyle({ position: 'absolute', top: '44%', left: '44%', visibility: 'visible' }); }
	function loaded() { $("ajax-loader-light").style.visibility = "hidden"; }
	function CloseDetail() {
	    if (cfok("Đóng lại ?")) $("itemdetail").innerHTML = "";
	}
	function cfok(mes) {
	    var tmp;
	    if ($("confirmaction").checked) {
	        if (confirm(mes)) { tmp = true } else { tmp = false }
	    } else { tmp = true }
	    return tmp;
	}
	function GetSelectValues(CONTROL) {
	    var strTemp = "";
	    for (var i = 0; i < CONTROL.length; i++) {
	        if (CONTROL.options[i].selected == true) { strTemp += CONTROL.options[i].value + ","; }
	        //	else{strTemp += "0,";}
	    }
	    return strTemp;
	}
	function doSort(types) {
	    Oname = false;
	    DateCre = false;
	    DateUp = false;
	    switch (types) {
	        case 0: Oname = true; break;
	        case 1: DateCre = true; break;
	        case 2: DateUp = true; break;
	    }
	    f5listitem();
	}

	function getdetail(artid) {
	    loading();
	    new Ajax.Request('func.aspx', {
	        method: 'post',
	        parameters: { f: "getitemdetail",
	            artid: artid
	        }
                        , onFailure: function(transport) { new_window(350, 70, 600, 500, transport.responseText, 'ssss', 'asas', false) }
                        , onSuccess: function(transport) { $("itemdetail").innerHTML = transport.responseText; windowonload(); loaded(); }
	    });
	}


	function GetChangePassWin() {
	    new Ajax.Request('func.aspx', {
	        method: 'post',
	        parameters: { f: "GetChangePassWin" }
                            , onFailure: function(transport) { new_window(350, 70, 600, 500, transport.responseText, 'ssss', 'asas', false) }
                            , onSuccess: function(transport) { new_window(280, 120, 325, 50, transport.responseText, 'ChangePassWin') }
	    });
	}
	function DoChangePass() {
	    loading();
	    new Ajax.Request('func.aspx', {
	        method: 'post',
	        parameters: { f: "DoChangePassWin",
	            password1: $("password1").value,
	            password2: $("password2").value,
	            password3: $("password3").value
	        }
                            , onFailure: function(transport) { new_window(350, 70, 600, 500, transport.responseText, 'ssss', 'asas', false) }
                            , onSuccess: function(transport) {
                                if (transport.responseText != "OK") {
                                    $("changestatus").innerHTML = transport.responseText;
                                } else {
                                    close_win('ChangePassWin');
                                }
                            }
	    }); loaded();
	}
	function GetProWin() {
	    new Ajax.Request('func.aspx', {
	        method: 'post',
	        parameters: { f: "GetUserWin" }
                            , onFailure: function(transport) { new_window(350, 70, 600, 500, transport.responseText, 'ssss', 'asas', false) }
                            , onSuccess: function(transport) { new_window(102, 50, 450, 50, transport.responseText, 'ProWin'); Usrf5(1) }
	    });
	}
	var currUsrPage = 1
	function Usrf5(page) {
	    currUsrPage = page;
	    new Ajax.Request('func.aspx', {
	        method: 'post',
	        parameters: { f: "Usrf5",
	            page: page
	        }
                        , onFailure: function(transport) { $("userlst").innerHTML = transport.responseText }
                        , onSuccess: function(transport) { $("userlst").innerHTML = transport.responseText }
	    });
	}
	function getusrdetail(usrid) {
	    new Ajax.Request('func.aspx', {
	        method: 'post',
	        parameters: { f: "getusrdetail",
	            usrid: usrid
	        }
                        , onFailure: function(transport) { new_window(350, 70, 600, 500, transport.responseText, 'ssss', 'asas', false) }
                        , onSuccess: function(transport) { $("userdetail").innerHTML = transport.responseText; }
	    });
	}
	function SaveUserDetail(usrid) {
	    if ((($("usrUserName").value).strip().length != 0) && (($("usrName").value).strip().length != 0)) {
	    new Ajax.Request('func.aspx', {
	        method: 'post',
	        parameters: { f: "saveuser",
	            usrUserName: $("usrUserName").value,
	            usrName: $("usrName").value,
	            UsrPassword: $("UsrPassword").value,
	            UsrTel: $("UsrTel").value,
	            UsrEmail: $("UsrEmail").value,
	            UsrNote: $("UsrNote").value,
	            usrplever: $("usrplever").selectedIndex,
	            usrid: usrid
	        }
                            , onFailure: function(transport) { new_window(350, 70, 600, 500, transport.responseText, 'ssss', 'asas', false) }
                            , onSuccess: function(transport) { $("userdetail").innerHTML = transport.responseText; Usrf5(currUsrPage); }
	    });
	} else { alert("Nhập tên người dùng !"); }
	}
	function deleteuser(usrid) {
	    if (cfok("Xóa người dùng này ?")) {
	        new Ajax.Request('func.aspx', {
	            method: 'post',
	            parameters: { f: "deleteuser",
	                usrid: usrid
	            }
                                    , onFailure: function(transport) { new_window(350, 70, 600, 500, transport.responseText, 'ssss', 'asas', false) }
                                    , onSuccess: function(transport) { $("userdetail").innerHTML = transport.responseText; Usrf5(currUsrPage); }
	        });
	    }
	}
	