/* pageableTag*/
function pageableAction(currentPage, url, formName, totalPage, parameters, cuttleSupport, tagKey){
	try{
	currentPage=currentPage.replace(/(^\s*)|(\s*$)/g, '');
	if(currentPage =='' || isNaN(currentPage)){
	  return;
	}else if(currentPage >totalPage){
	  return;
	}
	
	var cuttleRefreshZone;
	form=eval('document.'+formName);
	form.action=url;
	parameterList=parameters.split('&');
	var AJAX=false;
	var refreshZone="";
	for(i=0;i<parameterList.length;i++){
		parameterObj=parameterList[i].split("=");
		if(parameterObj[0].indexOf('?')>=0)continue;
		if(parameterObj[0]=='')continue;
		if(parameterObj[0]=='AJAX'){
			if(parameterObj[1]=='true'){
				AJAX=true;
			}
			continue;
		}
		if(parameterObj[0]=='refreshZone'){
			refreshZone=parameterObj[1];
			continue;
		}
		if(parameterObj[0]==tagKey+'_pageable_currentPage'){
			continue;
		}else{
		field=eval('document.'+formName+'.'+parameterObj[0]);
		if(field)
		field.value=parameterObj[1];
		}
		if(parameterObj[0]=='cuttleRefreshZone'){
			cuttleRefreshZone=parameterObj[1];
		}
	}
	try{
		if(isArray(form.refreshZone) && form.refreshZone[0]){
			refreshZone=form.refreshZone[0].value;
		}else if(!isArray(form.refreshZone) && form.refreshZone){
			refreshZone=form.refreshZone.value;
		}
	if(isArray(form.AJAX) && form.AJAX[0]){
		AJAX=form.AJAX[0].value;
	}else if(!isArray(form.AJAX) && form.AJAX){
		AJAX=form.AJAX.value;
	}
	}catch(e){
		//alert(e);
	}
	
	if(tagKey!='null' && tagKey!=''){
		firstRec=eval('form.'+tagKey+'_pageable_firstRec');
		firstRec.value='';
		maxRec=eval('form.'+tagKey+'_pageable_maxRec');
		maxRec.value='';
		pCurrentPage=eval('form.'+tagKey+'_pageable_currentPage');
		pCurrentPage.value=currentPage;
	}else{
		form.pageable_firstRec.value='';
		form.pageable_maxRec.value='';
		form.pageable_currentPage.value=currentPage;
	}
	
	if(cuttleSupport=='true'){
		doAjaxFormRequest(url, formName, cuttleRefreshZone);
	}else if(AJAX){
		fullUrl=url.replace('#','');
		/* fix the bug that can't change page
		if(parameters.length>0){
			if(url.indexOf("?")>0){
				
				fullUrl=fullUrl+"&"+parameters;
			}else{
				fullUrl=fullUrl+"?"+parameters;
			}
		}
		*/
		doAR(fullUrl, refreshZone, formName);
	}else{
		form.submit();
		return false;
	}
	}catch(e){
		alert(e);
	}
	//}else{
		//form.submit();
	//}
}
function isArray(obj) {
	   if (obj.constructor.toString().indexOf("Array") == -1)
	      return false;
	   else
	      return true;
	}
function doAR(url, refreshZone, formName, callback){
	var data;
	var qssNames="";
	var json;
	if(url.indexOf('?')>0){
		url+="&AJAX=true";

	}else{
		url+="?AJAX=true";

	}
	qss=url.split("?")[1].split("&");
	for(i=0;i<qss.length;i++){
		if(qssNames!=""){
			qssNames+=",";
		}
		qssNames+=qss[i].split("=")[0];
	}
	data=preparePostDataFromQueryString(url.split("?")[1]);
	var preData='';
	if(formName){
		preData=preparePostData(document.forms[formName]);
		if(preData!=''){
		//if(!preData.substring(preData.length-2,preData.length-1)==','){
		if(!preData.match("/,$/")){
			preData+=",";
		}
		data=preData+data;
		}
	}
	json="";
	eval("json={"+data+"};");
	
	$('#'+refreshZone).load(url.split("?")[0], json, callback);
}
function preparePostDataFromQueryString(qs, skipParams){
	qss=qs.split("&");
	var result="";
	for(i=0;i<qss.length;i++){
		qssValuePair=qss[i].split("=");
		needSkip=false;
		if(skipParams){
			for(j=0;j<skipParams.length;j++){
				if(qssValuePair[0]==skipParams[j]){
					needSkip=true;
					break;
				}
			}
		}
		if(needSkip)continue;
		if(result!=""){
			result+=",";
		}
		
		result+="\""+qssValuePair[0]+"\":";
		if(qssValuePair.length>1){
			result+="\""+qssValuePair[1]+"\"";
		}
	}
	//alert("qs:"+result);
	return result;
}
function preparePostData(form, skipParams) {
	var result = "";
	for (var i = 0; i < form.elements.length; i++) {
		//alert("i:"+i);
		var el = form.elements[i];
		needSkip=false;
		if(skipParams){
			for(j=0;j<skipParams.length;j++){
				if(el.name==skipParams[j]){
					needSkip=true;
					break;
				}
			}
		}
		if(needSkip)continue;
		if((result!="" && el.type.toLowerCase()!="reset" && el.type.toLowerCase()!="button" && el.type.toLowerCase()!="submit" && el.type.toLowerCase()!="radio" && el.type.toLowerCase()!="checkbox") 
				|| (result!="" && el.type.toLowerCase()=='radio' && el.checked) 
				|| (result!="" && el.type.toLowerCase()=='checkbox' && el.checked)){
			if (el.tagName.toLowerCase() != "select") {
				result+=",";
			}
		}else{
			
		}
		//alert("type:"+el.type.toLowerCase()+"; result:"+result);
		if (el.tagName.toLowerCase() == "select") {
			var isMulti=false;
			var countSelect=0;
			var multiSelectStr='';
			for (var j = 0; j < el.options.length; j++) {
				var op = el.options[j];
				if (op.selected) {
					countSelect++;
				}
			}
			if(countSelect>1)isMulti=true;
			
			if(countSelect>0){
				result+=",";
			}
			
			if(isMulti){
				for (var j = 0; j < el.options.length; j++) {
					var op = el.options[j];
					if (op.selected) {
						if(multiSelectStr!='')multiSelectStr+=',';
						multiSelectStr+="\"" + replaceEscape(op.value)+"\"";
						
					}
				}
				result+="\""+(el.name) + "\":["+multiSelectStr+"]";
			}else{
				for (var j = 0; j < el.options.length; j++) {
					var op = el.options[j];
					if (op.selected) {
						
						result += "\""+(el.name) + "\":\"" + replaceEscape(op.value)+"\"";
						
					}

				}
			}
		} else {
			if (el.tagName.toLowerCase() == "textarea") {
				result += "\"" + (el.name) + "\":\"" + replaceEscape(el.value)+"\"";
			} else {
				if (el.tagName.toLowerCase() == "input") {
					if (el.type.toLowerCase() == "checkbox" || el.type.toLowerCase() == "radio") {
						if (el.checked) {
							result += "\""+(el.name) + "\":\"" + replaceEscape(el.value)+"\"";
						}
					} else {
						if (el.type.toLowerCase() == "text" || el.type.toLowerCase() == "hidden") {
							result += "\""+(el.name) + "\":\"" + replaceEscape(el.value)+"\"";
						} else {
							
							//do nothing
							//result += "\""+encodeURIComponent(el.name) + "\":\"" + encodeURIComponent(el.value)+"\"";
						}
					}
				}
			}
		}
	}
	//json='';
	//eval("json={"+result+"}");
	//alert("data:"+result);
	return result;
}
function replaceEscape(source){
	return source.replace(/[\r\n]/g,"");  
}
function openDialog2(title, contentId){
	var content;
	openDialog(title, content);
	$('#dialog').html($('#'+contentId).html());

}
function openDialogById(title, content,width,height,dialogId){
	//Jquery ui中的Dialog只能运行一次，原来是close方法并没有把dialog destory
	$('#'+dialogId).dialog('destroy');
	if ( width =="" || width == 0) width = 500;
	if ( height =="" || height == 0) height = 400;
	//if($('div.ui-dialog').size()<=0){
	//	$('#dialog').empty();
		$('#'+dialogId).dialog(
			{ 
				bgiframe:true,
				title:title,
				width:width,
				height:height,
				modal: true
			}
			);
	//}else{
	//	$('#dialog').empty();
	//	$('div.ui-widget-overlay').css({display:'block'});
	//	$('div.ui-dialog').css({display:'block'});
		
	//}
	if(content){
		$('#'+dialogId).html(content);
	}
}
function openDialog(title, content,width,height){
	openDialogById(title, content,width,height, 'dialog');
	
}
function alertDialogById(title, content, callbackFunctionName, width, height, id){
	if(callbackFunctionName){
		functionName=callbackFunctionName;
	}else{
		functionName="";
	}
	var w,h;
	if(width){
		w=width;
	}else{
		w=350;
	}
	if(height){
		h=height;
	}else{
		h=180;
	}
	content='<div class="pdnm-alert"><p>'+content+'</p><div align="center"><a href="javascript:closeDialog(\''+id+'\');'+functionName+'" class="btn-mid" onfocus="blur()">确定</a></div></div>';
	openDialogById(title, content, w,h, id);
}
function alertDialog(title, content, callbackFunctionName, width, height){
	alertDialogById(title, content, callbackFunctionName, width, height, "dialog");
}
function  confirmDialog(title, content, callbackFunctionName, width, height){
	if(callbackFunctionName){
		functionName=callbackFunctionName;
	}else{
		functionName="";
	}
	var w,h;
	if(width){
		w=width;
	}else{
		w=350;
	}
	if(height){
		h=height;
	}else{
		h=180;
	}
	content='<div class="dailog-ok-L2"><p>'+content+'</p><div align="center"><a href="javascript:'+functionName+';closeDialog();" class="btn-mid" onfocus="blur()">确定</a></div></div>';
	openDialog(title, content, w, h);
}
function  promptDialog(title, content, callbackFunctionName, width, height){
	if(callbackFunctionName){
		functionName=callbackFunctionName;
	}else{
		functionName="";
	}
	var w,h;
	if(width){
		w=width;
	}else{
		w=350;
	}
	if(height){
		h=height;
	}else{
		h=180;
	}
	content='<div class="pdnm-alert"><p>'+content+'</p><div align="center"><a href="javascript:'+functionName+';closeDialog();" class="btn-mid" onfocus="blur()">确定</a><a href="javascript:closeDialog();" class="btn-mid">取消</a></div></div>';
	openDialog(title, content, w, h);
}
function  loginPromptDialog(title, content, callbackFunctionName,callbackFunctionName2, width, height){
	if(callbackFunctionName){
		functionName=callbackFunctionName;
	}else{
		functionName="";
	}
	if(callbackFunctionName2){
		functionName2=callbackFunctionName2;
	}else{
		functionName2="";
	}	
	var w,h;
	if(width){
		w=width;
	}else{
		w=350;
	}
	if(height){
		h=height;
	}else{
		h=180;
	}
	if(window.location.host.match('^pclady')){
		content='<div class="pdnm-alert"><p><br/>'+content+'</br></p><div align="center"><a href="javascript:'+functionName+';closeDialog();" class="btn-mid" onfocus="blur()">登录</a></div></div>';
	}else{
		content='<div class="pdnm-alert"><p><br/>'+content+'</br></p><div align="center"><a href="javascript:'+functionName+';closeDialog();" class="btn-mid" onfocus="blur()">登录或注册</a><a href="javascript:' + functionName2 + ';closeDialog();" class="btn-mid">非会员购买</a></div></div>';
		content=content + '<div align="center" class="txt-rd">提示：限时秒杀会员专属优惠，非会员无法购买！</div>';
	}
	openDialog(title, content, w, h);
}
function  loginTimeLimitDialog(title, content, callbackFunctionName,width, height){
	if(callbackFunctionName){
		functionName=callbackFunctionName;
	}else{
		functionName="";
	}
	var w,h;
	if(width){
		w=width;
	}else{
		w=350;
	}
	if(height){
		h=height;
	}else{
		h=180;
	}
	if(window.location.host.match('^pclady')){
		content='<div class="alert-caution"><p>'+content+'</br></p><div align="center"><a href="javascript:'+functionName+';closeDialog();" class="btn-mid" onfocus="blur()">登录</a><a href="javascript:closeDialog();" class="btn-mid">关闭</a></div></div>';
	}else{
		content='<div class="alert-caution"><p>'+content+'</br></p><div align="center"><a href="javascript:'+functionName+';closeDialog();" class="btn-mid" onfocus="blur()">登录或注册</a><a href="javascript:closeDialog();" class="btn-mid">关闭</a></div></div>';
		content=content + '<div align="center" class="txt-rd">提示：限时秒杀会员专属优惠，非会员无法购买！</div><br/>';
	}
	openDialog(title, content, w, h);
}
function closeDialog(dialogId){
	var di=dialogId;
	if(di!='undefined' && di!='' && di){
		$('#'+di).dialog('close');
	}else{
		$('#dialog').dialog('close');
	}
	
}
function validateEmail(email) {
	   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	   var address = email;
	   return reg.test(address);
	}

function isLogin(){
	cookies=document.cookie.split(';');
	for(i=0;i<cookies.length;i++){
		theCookie=cookies[i].split('=');
		if(theCookie[0].replace(' ', '')=='_1.100.D'){
			if(theCookie[1]!=''){
				return true;
			}else{
				return false;
			}
		}
	}
	return false;
	
}
function getParameter(name)
{
	    var qs = window.location.search.substring(1);
	    var psPairs = qs.split("&");
	    for (i = 0; i < psPairs.length; i++)
	    {
	        var ps = psPairs[i].split("=");
	        if (ps[0] == name) return ps[1];
	    }
	    return "";
}
//event popup info
function compositeCampaign(title, desc, detail, startDate, endDate, url, dialogId){
	if(url!='' && url!='null'){
		eventUrl='<p><a href="'+url+'" target="_blank"><strong>&gt;&gt; 看活动网页</strong></a></p>';
	}else{
		eventUrl='';
	}
		
	var campaignContent='<div class="promo-popup">'+ 
	  '<h2>'+title+'</h2>'+
	
	'<p>'+detail+'</p>'+

	'<p class="d-line">&nbsp;</p>'+
	'<h3>活动时间：</h3>'+
	'<p>'+startDate+' ~ '+endDate+'</p>'+

	eventUrl+


	'<p class="d-line">&nbsp;</p>'+
	'<h3>活动说明：</h3>'+
	desc+
	'<p align="center"><a href="javascript:closeDialog(\''+dialogId+'\');" class="btn-mid">关闭</a></p>'+
	'</div>';
	return campaignContent;
	}
