﻿function setmain(id ,Slide_type ,Store_id) {
//alert ('save_setmain/?id=' + id + 'Slide_type=' + Slide_type + "&Store_id=" + Store_id)
window.open('save_setmain/?id=' + id + '&Slide_type=' + Slide_type + "&Store_id=" + Store_id,'SaveForm')
}
function delete_slide(id ,Slide_type, Store_id) {
window.open('delete_slide/?id=' + id + '&Slide_type=' + Slide_type + "&Store_id=" + Store_id,'SaveForm')
}

function CheckLoginForm(form) {
}
function view_product_img(ImageName ,ProductID ,objname) {
document.getElementById(objname).src = "/Product_img/?product_id=" + ProductID + "&imagename=" + ImageName + "&width=320&height=320"
}
function post_photo(img_url) {
 if (opener) {
   if (opener.document.getElementById("acontent")) {
     AddText_parent('[img]' + img_url + '[/img]');
   }
    }
}
function Post_Entrepreneur_Chk(form) {
         if (form.store_name.value == '') {
             alert('請輸入店家名稱!')
             form.store_name.focus()
             return false
         }
         
         //********************************************************
         if (form.store_phone_number1_area.value.trim() == '') {
             alert('請輸入店家主要聯絡電話區域號碼! Ex:02')
             form.store_phone_number1_area.focus()
             return false
         }    

         if (form.store_phone_number1.value.trim() == '') {
             alert('請輸入店家主要聯絡電話!')
             form.store_phone_number1.focus()
             return false
         }
               
         re = /^\d+$/;   

         //******************************************************** 
         if (!re.test(form.store_phone_number1_area.value)) {
             alert('電話號碼(區碼)僅能輸入數字!  Ex:02')
             form.store_phone_number1_area.focus()
             return false
         }
         if (!re.test(form.store_phone_number1.value)) {
             alert('電話號碼僅能輸入數字!')
             form.store_phone_number1_area.focus()
             return false
         }
         //********************************************************
          if (!(form.store_phone_number2_area.value.trim() == '')) {
           re = /^\d+$/;    
           if (!re.test(form.store_phone_number2_area.value)) {
               alert('電話號碼(2)區碼僅能輸入數字!  Ex:02')
               form.store_phone_number2_area.focus()
               return false
           }         
         }        
         if (!(form.store_phone_number2.value.trim() == '')) {
           re = /^\d+$/;    
           if (!re.test(form.store_phone_number2.value)) {
               alert('電話號碼(2)僅能輸入數字!')
               form.store_phone_number2.focus()
               return false
           }         
         }
         
         //********************************************************
         if (!(form.fax_number_area.value.trim() == '')) {
           re = /^\d+$/;    
           if (!re.test(form.fax_number_area.value)) {
               alert('傳真號碼[區碼]僅能輸入數字! Ex:02')
               form.fax_number_area.focus()
               return false
           }         
         }  
                
         if (!(form.fax_number.value.trim() == '')) {
           re = /^\d+$/;    
           if (!re.test(form.fax_number.value)) {
               alert('傳真號碼僅能輸入數字!')
               form.fax_number.focus()
               return false
           }         
         }
         //********************************************************
         
         if (!(form.mobile_number_area.value.trim() == '')) {
           re = /^\d+$/;    
           if (!re.test(form.mobile_number_area.value)) {
               alert('行動電話號碼業者識別碼僅能輸入數字! Ex:0910')
               form.mobile_number_area.focus()
               return false
           }         
         }
         if (!(form.mobile_number.value.trim() == '')) {
           re = /^\d+$/;    
           if (!re.test(form.mobile_number.value)) {
               alert('行動電話號碼僅能輸入數字!')
               form.mobile_number.focus()
               return false
           }         
         }

         
         if (form.city.value == '0') {
             alert('請選擇店家所在的縣市!')
             form.city.focus()
             return false
         
         }

         if (form.towns.value == '0') {
             alert('請選擇店家所在的鄉鎮區域!')
             form.towns.focus()
             return false
         
         }

         if (form.address.value.trim()  == '') {
             alert('請填寫店家詳細道路地址!')
             form.address.focus()
             return false
         
         }

         if (form.mail.value.trim()  == '') {
             alert('請填寫電子郵件!')
             form.mail.value = ''
             form.mail.focus()
             return false
         
         }

         if (!(CheckMail(form.mail))) {
             alert('請填寫正確的電子郵件!')
             form.mail.focus()
             return false             
         }

         if (form.occupation.value == '0') {
             alert('請選擇行業別!')
             form.occupation.focus()
             return false
         
         }

         if (form.travel_class.value == '0') {
             alert('請選擇行業性質!')
             form.travel_class.focus()
             return false
         
         } 
         
         if (form.sub_domain.value.trim() == '') {
             alert('請填寫一個子網域名稱!')
             form.sub_domain.focus()
             return false
         
         }
         
         if (form.recorder_name.value.trim() == '') {
             alert('請填寫登入者(申請者)姓名!')
             form.recorder_name.focus()
             return false
         }
         
         if (form.recorder_phonenumber.value.trim() == '') {
             alert('請填寫登入者(申請者)聯絡電話!')
             form.recorder_phonenumber.focus()
             return false
         }
         
         re = /^\d+$/;    
         if (!re.test(form.recorder_phonenumber.value)) {
             alert('聯絡電話號碼僅能輸入數字!')
             form.recorder_phonenumber.focus()
             return false
         } 
         
                
         if (!form.reg_type[0].checked && !form.reg_type[1].checked && !form.reg_type[2].checked ) {
             alert('請選擇登入者(申請者)身分!')
             form.reg_type[0].focus()
             return false
         }   
         //if (!form.Issue_type[0].checked && !form.Issue_type[1].checked && !form.Issue_type[2].checked ) {
         //    alert('請選擇登入類型!')
         //    form.Issue_type[0].focus()
         //    return false
         //}    
         
         //alert(form.travel_class.value)
         //alert(form.towns.value)
         //form.tmp_travel_class.value = form.travel_class.value
         //form.tmp_towns.value = form.towns.value
         return true
             
}



function addCookie(c_href ,c_title){ // 加入收藏夾 
    if (document.all){ 
        window.external.addFavorite(c_href, c_title); 
    }else if (window.sidebar){ 
        window.sidebar.addPanel(c_title, c_href, ""); 
    } 
} 
 
 


function setHomepage(url){ // 設置首頁 
    if (document.all){ 
        document.body.style.behavior = 'url(#default#homepage)'; 
        document.body.setHomePage(url);
     }else if (window.sidebar){ 
        if (window.netscape){ 
            try { 
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
            }catch (e) { 
                alert("該操作被瀏覽器拒絕，如果想啟用該功能，請在地址欄內輸入 about:config,然後將項 signed.applets.codebase_principal_support 值該為true"); 
            } 
        } 
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch); 
        prefs.setCharPref('browser.startup.homepage', url);
     } 
} 


function Check_SubDomain(DomainNameObj ,buttonObj)
 {
 var DomainName = DomainNameObj.value;
 var xmlHttp;
 
 if (DomainNameObj.value.trim() == '') {
    alert('請輸入子網域名稱！')
    DomainNameObj.focus()
    return false;
 }
 DomainNameObj.readonly = true
 buttonObj.disabled = true
 
 try
    {
   // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
        }
 catch (e)
    {
 
  // Internet Explorer
   try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            }
   catch (e)
      {
 
      try
         {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                  }
      catch (e)
         {
         alert("您的瀏覽器不支援AJAX！");
         return false;
         }
      }
    }
//return xmlHttp;
    xmlHttp.onreadystatechange = function(){byphp(xmlHttp ,DomainNameObj ,buttonObj)}
    xmlHttp.open("GET","/check_subdomain/index.asp?sub_domain=" + DomainName ,true); 
    xmlHttp.send(); 
}


function byphp(xmlHttp ,DomainNameObj ,buttonObj) {
         if (xmlHttp.readyState == 4) {
            if (xmlHttp.status == 200) {
               
               if (xmlHttp.responseText.trim() == '1') {
                  alert('此子網域已被其他用戶使用！')
               }

               if (xmlHttp.responseText.trim() == '0') {
                  alert('此子網域可以使用！')
               }
               if (xmlHttp.responseText.trim() == '2') {
                  alert('此子網域為系統保留字！')
               }
               if (xmlHttp.responseText.trim() == '3') {
                  alert('子網域僅能輸入英文或數字！')
               }               
            }
         }
         DomainNameObj.readonly  = false
         buttonObj.disabled = false
}

 function upload_myphoto(thisform) {
    document.getElementById("detail_Uri_Code").value = escape(document.all.detail.value)
    return true;
 }

 function myphoto(store_id) {
    //a = window.open('http://www.pchome.com.tw' ,'_media','height=550, width=850, scrollbars=no')
    //a = window.open('/store_myphoto/?store_id=' + store_id ,'_media','height=550, width=850, scrollbars=no')
    onTop('/store_myphoto/?store_id=' + store_id ,'_media','height=550, width=850, scrollbars=no')
 }


 var w=null;
 function onTop(theURL,winName,features)
 { 
　　if(w!=null)
　　 {
　　　　 if(!w.closed)
　　　　 {
　　　　　　 if(w.blur){w.focus();} 
　　　　} 　　
　　　　else 
　　　　{
　　　　　 w=window.open(theURL,winName,features); 
　　　　}　　
　　}
　　else
　　 {
　　　 w=window.open(theURL,winName,features); 
　　}
 } 




 


 function CheckMail(objMail) {
          var Myemail = objMail.value;
          var rege = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9])+$/;
          if (Myemail.length == 0 || rege.exec(Myemail) == null) {
             return false;
          }
          return true;
 }


 function valueload() {
          if ((document.getElementById("tmp_towns"))) {
//alert (document.getElementById("tmp_towns").value)
             if (!(document.getElementById("tmp_towns").value.trim() == '')) {
             
		        Buildkey(document.getElementById("towns") ,document.getElementById("city").value)
   		        document.getElementById("towns").value = document.getElementById("tmp_towns").value
		     
			    travel_class_key(document.getElementById("travel_class") ,document.getElementById("occupation").value)
			    document.getElementById("travel_class").value = document.getElementById("tmp_travel_class").value
		     }
		  }

 }


 function copy_detail_Base64 (form1) {
          document.getElementById("detail_Base64").value = escape(document.all.acontent.value)
          //alert (document.getElementById("detail_Base64").value)
          //document.all.detail_Base64.value = Base64.encode(document.all.detail.value) 
          //alert (document.getElementById("detail_Base64").value)
          
          //alert('0')
          //document.all.detail.value = Base64.encode(document.all.detail.value) 
          return true
 }




 function copy_detail_Uri_Min (form1) {
          document.getElementById("detail2_URICODE").value = escape(document.getElementById("detail2").value)
          document.getElementById("detail3_URICODE").value = escape(document.getElementById("detail3").value)
          document.getElementById("detail4_URICODE").value = escape(document.getElementById("detail4").value)
          document.getElementById("detail5_URICODE").value = escape(document.getElementById("detail5").value)
          document.getElementById("detail6_URICODE").value = escape(document.getElementById("detail6").value)
          document.getElementById("detail7_URICODE").value = escape(document.getElementById("detail7").value)
          document.getElementById("min_title_URICODE").value = escape(document.getElementById("min_title").value)

          return true
 }

 function copy_product_to_URI(thisform) {
          document.getElementById("acontent_URI").value = escape(document.getElementById("acontent").value)
          document.getElementById("productname_URI").value = escape(document.getElementById("productname").value)
          document.getElementById("Product_introduction_URI").value = escape(document.getElementById("Product_introduction").value)
          return true
 }

 function getMap(MapAddress ,store_name) {

       if (document.getElementById("map")) {

       if (GBrowserIsCompatible()) {
         var map = new GMap2(document.getElementById("map"));
             var geocoder = new GClientGeocoder();
         var address = MapAddress
         map.addControl(new GSmallMapControl());
          

      //map.addControl(new GLargeMapControl());
       map.addControl(new GMapTypeControl());
      //GEvent.addListener(map, 'click', mapClick);
      // geocoder = new GClientGeocoder();

       
                geocoder.getLatLng(address, function(point) {
                         if (!point) {
                           //alert('很抱歉！ 無法查詢到店家所在地址！'); //如果Google Maps無法顯示該地址的警示文字
                           document.getElementById("map").innerHTML = '很抱歉！ 無法查詢到店家所在地址！'
                         } else {
                           map.setCenter(point, 13);
                           var marker = new GMarker(point);
                           map.addOverlay(marker);
                           marker.openInfoWindowHtml(store_name + '<br>' + MapAddress );
                         }
                   });
       }
       }
  }

 function check_home_slide(form) {
      if (form.document.getElementById('file1').value=='') {
         alert ('請選擇圖片！')
         form.document.getElementById('file1').focus()
         return false;
      }
      
      document.getElementById("Url_encode").value = escape(document.getElementById("Url").value)
      document.getElementById("explain_encode").value = escape(document.getElementById("explain").value)

 }

/**
 * 去除多余空格函数
 * trim:去除两边空格 lTrim:去除左空格 rTrim: 去除右空格
 * 用法：
 *     var str = "  hello ";
 *     str = str.trim();
 */
// Removes leading whitespaces
String.prototype.ltrim = function() {
	var re = /\s*((\S+\s*)*)/;
	return this.replace(re, "$1");	
}

// Removes ending whitespaces
String.prototype.rtrim = function() {
	var re = /((\s*\S+)*)\s*/;
	return this.replace(re, "$1");
}

// Removes leading and ending whitespaces
String.prototype.trim = function() {
	return this.ltrim().rtrim();
}



function AddText_parent(NewCode) {
	//setfocus();
	
	//text = (isIE) ? document.selection.createRange().text : getSel();
	
	var postText = opener.document.getElementById("acontent");
	if(isIE) {
		if (postText.createTextRange && postText.caretPos) {
			var caretPos = postText.caretPos;
			//alert (postText.createTextRange +'2:'+ postText.caretPos);
			//caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
			//alert (NewCode);
		} else {
			//var caretPos = postText.caretPos;
			//caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
			postText.value+=NewCode; 
			//alert('ccc');
		}
	} else if (typeof(postText.selectionStart) == "undefined") { 
		postText.value+=NewCode;
	} else {
		pos = postText.selectionStart;
		postText.value = postText.value.substr(0, pos) + NewCode + postText.value.substr(pos);
		postText.selectionStart = pos + NewCode.length;
		postText.selectionEnd = postText.selectionStart;
	}
     window.close();
	setfocus();
}

