﻿//This function is used to retrieve the cookie value by Name
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
//This fucntion is used to check the login status, if user is not logged in, it will wake up the loginPanel in the MasterPage
function checkLoginStatus() {
    if (readCookie('Account')) 
    {
        return true;
    }
    //$find('ctl00_ContentPlaceHolder_MemberArea1_userLoginModalPopupExtender').show();
    location.href='SecureLogin.aspx';
    return false;
}

//This function is used to check string which could use letters, numbers, underscores 
function checkAccountLetter(source, arguments){
	var isErr;
	isErr=false;
    //3~14個字元
	if (arguments.Value.length<3 || arguments.Value.length>14)
	{
	    isErr=true;
	}
	//英文字母起首
	idx=0;
	if( !( ( arguments.Value.charAt(idx)>= 'A' && arguments.Value.charAt(idx) <= 'Z' ) || ( arguments.Value.charAt(idx)>= 'a' && arguments.Value.charAt(idx) <= 'z' ) ) ){
			isErr=true;
	}
//	var reg=/[\u4e00-\u9fa5]/; 
//	for( idx = 0 ; idx <arguments.Value.length ; idx++){
//	    if (reg.test(this.charAt(i))
//	    {
//	        isErr=true;
//			break;
//	    }
//	}
	//僅允許A-Z,a-z,0-9,_
	for( idx = 0 ; idx <arguments.Value.length ; idx++){
		if( !( ( arguments.Value.charAt(idx)>= 'A' && arguments.Value.charAt(idx) <= 'Z' ) || ( arguments.Value.charAt(idx)>= 'a' && arguments.Value.charAt(idx) <= 'z' ) || ( arguments.Value.charAt(idx)>= '0' && arguments.Value.charAt(idx) <= '9' ) || ( arguments.Value.charAt(idx) == '_' ) ) ){
			isErr=true;
			break;
		}
	}
	if(isErr){
		arguments.IsValid=false;
	}else{
		arguments.IsValid=true;
	}
}
function checkPasswordLetter(source, arguments){
	var isErr;
	isErr=false;
    //6個字元以上
	if (arguments.Value.length<6)
	{
	    isErr=true;
	}
	//僅允許A-Z,a-z,0-9,_
	for( idx = 0 ; idx <arguments.Value.length ; idx++){
		if( !( ( arguments.Value.charAt(idx)>= 'A' && arguments.Value.charAt(idx) <= 'Z' ) || ( arguments.Value.charAt(idx)>= 'a' && arguments.Value.charAt(idx) <= 'z' ) || ( arguments.Value.charAt(idx)>= '0' && arguments.Value.charAt(idx) <= '9' ) || ( arguments.Value.charAt(idx) == '_' ) ) ){
			isErr=true;
			break;
		}
	}
	if(isErr){
		arguments.IsValid=false;
	}else{
		arguments.IsValid=true;
	}
}
function openUrlPromotePage(urlPromote,urlTitle, generatedLinkID){
    var url = "http://promote.pushba.com/Default.aspx";
    if (urlPromote!="")
        url = url + "?url=" + (urlPromote);
    if (urlTitle!="")
        url = url + "&title=" + (urlTitle);
    if (generatedLinkID!="")
        url = url + "&gid=" + (generatedLinkID);  
    var urlPromote=window.open(url,"UrlPromote","width=487,height=198,menubar=no,status=yes,scrollbars=no,resizable=no");
    if (!urlPromote)
        {
        var msg = 'If you have a pop-up blocker installed, you will need to deactivate it!\n\n若是您有安裝阻擋Pop-up視窗的工具程式，請將其暫時關閉，以免影響網頁的正常瀏覽';
        alert(msg);
        }
}

function confirmcheck(msg){
	if(confirm(msg)){
		return true;
	}else{
		return false;
	}
}