/**
 * @author steve
 */

    var justinurl=window.location.toString();
    var justinstr="";

	var  LSA  =  justinurl.split("?")[0].split("/");
	var  CFN  =  LSA[LSA.length-1];
	
	if(CFN == "content.aspx"){
		if(justinurl.indexOf("?")!=-1){ //url裡有"?"符號
			var ary=justinurl.split("?")[1].split("&");
			for(var i in ary){
				if( ary[i].split("=")[0] == 'id'){
					justinstr+=ary[i].split("=")[0]+"="; //變數名稱
					justinstr+=ary[i].split("=")[1]+"\n"; //變數值
				}
			}
		}else{ //url裡沒有"?"符號
			justinstr = "";
		}
	}
    //window.alert(CFN);
	//code/blockquote
	
var sUserAgent=navigator.userAgent;
var mobileAgents=['Windows CE','iPod','Symbian','iPhone','BlackBerry','Android','iPad'];
for(var i=0;i<mobileAgents.length;i++){
	if(sUserAgent.indexOf(mobileAgents[i])>-1){
		if(justinstr == ""){
			location='http://www.jsl.com.tw/m/index.aspx';
		}else{
			location='http://www.jsl.com.tw/m/inner.aspx?'+justinstr;
		}
		break;
	}
}

jQuery(document).ready(function () {
	var phone = window.navigator.userAgent;
	if(phone.indexOf("iphone")>=0){ 
		window.location.href("/m/index.aspx");
	}

    $('a.inner_subnav').click(function () {
    	
    	$(this).parent().find("ul.subnav_items").slideToggle('medium');
   		/*$('ul.subnav_items').slideToggle('medium');*/
    });
    $('a.inner_subnav').hover(function () {
    	if ($(this).parent().find("ul.subnav_items").is(':hidden')) {
        	var state = "closed";
        } else {
            var state = "open";
        }
        if(state=="closed"){
    		$(this).parent().find("ul.subnav_items").slideToggle('medium');
    	}
   		/*$('ul.subnav_items').slideToggle('medium');*/
    }, function () {
    	
    });
	
    $('.nav_div').hover(function () {
    	
   		
    }, function () {
    	if ($(this).parent().find("ul.subnav_items").is(':hidden')) {
        	//var state = "closed";
        } else {
            var state = "open";
        }
        if(state=="open"){
    		$(this).parent().find("ul.subnav_items").slideToggle('slow');
    	}
    });

});


function doSubmit(form){
	var sMsg = "";
	
	for(var i=0;i<form.length;++i){
		var o = form[i];
		var _value = o.value;
		var _validate = $(o).attr("validate");
		var title = $(o).attr("title");
		if(_validate){				
			var re = new RegExp(_validate,"gi");
			if(!re.test(_value)){
				sMsg += "# [" + (o.title?o.title:o.name) + "] " + (o.tagName=="SELECT"?"選擇":"填寫") + " 不正確\n";
				//$(o).css({"background-color":"#FF0000","color":"#FFFFFF"});
				if(!t)var t = o;
			}else{
				//$(o).css({"background-color":"","color":""});
			}
		}
	}
	if(sMsg){
		
		sMsg = "再您提交的表單中，以下資訊填寫不正確，請檢查：\n---------------------------------------\n" + sMsg;
		alert(sMsg);
		if(t){
			var idname = $(t).closest("table").closest("div").attr("id");
			$("a[href=#"+idname+"]").click();
			$(t).focus();
		}
		return false;
	}else{
		return true;
	}
}

function doPost(form){
	var pid = $("input[name=pid]");
	var t = false;
	for(var i = 0;i<pid.length;i++){
		if(pid.eq(i).attr("checked")){
			var t = true;
		}
	}
	if(!t){
		alert("請選擇您要預約的建案");
		return false;
	}else{
		return doSubmit(form);
	}

	
}

   function getFxUrl(s, title, img, note, sUrl) {
	var href = location.href;
	
	if (img != ""){
		if (img.indexOf("/db/newsite/") == -1)
	 		img = "http://www.jsl.com.tw/db/newsite/" + img;	
	}
	
	if (sUrl.indexOf("www.jsl.com.tw") == -1) 
		sUrl = "http://www.jsl.com.tw/" + sUrl;
	
	
	if (s == "f") {
		var url =
                     "&p[title]=" + encodeURIComponent(title) +
                     "&p[summary]=" + encodeURIComponent(note.substring(0,100))+"..." +
                     "&p[url]=" + sUrl +
                     "&p[images][0]=" + img;
    
		window.open("http://www.facebook.com/sharer/sharer.php?s=100" + url);

	} else if (s == "p") {
		var url = "http://ping.fm/ref/?link=" + escape(sUrl) + "&title=" + escape(title);
	} else if (s == "t") {
		window.open('http://twitter.com/home/?status='.concat(encodeURIComponent(title)).concat(' '));
	} else if (s == "plurk") {
		
		var url = "http://www.plurk.com/?qualifier=shares&status=" +
		//encodeURIComponent(title) + " " +
                      img + " " +
                       sUrl + " " +
                      "(".concat(encodeURIComponent(title)) + ")" + " " +                      
                      encodeURIComponent(note);
     window.open(url);
	} else if (s == "funp") {
		var url = "http://funp.com/push/submit/?url=" + escape(title) + "-----" + escape(href);
	}
	//window.open(url, parseInt(Math.random() * 1000000000), "toolbar=no,menu=no,status=no,width=600px,height=500px,scrollbars=1,resizable=1")
}


function videoStop() { swfobject.getObjectById("flashContainer").videoPause(); }

function videoStop2() { swfobject.getObjectById("pro_picurl_div").videoPause(); }


