﻿var OnlineFlag=false;
jQuery.fn.extend({
				 
/*textbox得到焦点后隐藏默认值,失去后显示默认值
$("#myid").focusValue("default_value");
overload: $("#myid").focusValue("default_value","get focus class","losed focus class");
		  $("#myid").focusValue("default_value","get focus class","losed focus class","type class");
*/

focusValue:function(){  
	 var defaultValue=arguments[0];
	var focusCssClass = arguments[1];
	var normalCssClass = arguments[2];	
	normalCssClass = "textbox_normal_color";
	var keyupCssClass = arguments[3];	
	keyupCssClass = "textbox_type_color";
	this.addClass(focusCssClass);
	//$(this).val(defaultValue);
	return this.focus(function(){			
		focusCssClass!=undefined ?$(this).addClass(focusCssClass):"";	
		
		if($(this).val()==defaultValue){
				$(this).val("");			 
			}
		})
	.blur(function(){						
		normalCssClass!=undefined ?$(this).addClass(normalCssClass):$(this).removeAttr(focusCssClass);	
		if($(this).val()==""){
			$(this).val(defaultValue);
			keyupCssClass!=undefined ?$(this).removeClass(keyupCssClass):"";	
		}
		
	})
	.keyup(function(){
		//keyupCssClass!=undefined ?$(this).addClass(keyupCssClass):"";	
		$(this).css({color:"#000"})
	})		
}
/*============-------------------------------------------------------------*/

}); 




/*------------------------------------------------------------------------

-	other useful function			  -
	
-------------------------------------------------------------------------*/

/* 得到要查询的字符串的值*/
function GetRequestStringByKey(key){
	var full_requset_string=location.search.substring(1,location.search.length)+"&";	
	var bunch=full_requset_string.split("&");//得到所有的串
	var count=bunch.length-1;
	for(var i=0;i<count;i++){
		var temp=bunch[i].split("=");
		if(temp[0]==key)
		return temp[1]
	}
}


/*------------------------------------------------------------------------

-	customization function			  -
	
-------------------------------------------------------------------------*/

$(document).ready(function(){						    												
        GetMessageCount();
        GetCurrTime("TopTime");    
		CheckUserOnline();//判断是否在线
			  $("img").error(function(){				 
				   $(this).src="Images\\BignoPhoto.gif";
		    })
		$("#SeeHowToUse").click(function(){			
			$("#Welcome").fadeIn(500);							 
		})
		$("#CloseWindow").click(function(){
			$("#Welcome").fadeOut(500);
		})
        $("input[rel='fname']").focusValue("first name");
        $("input[rel='mail_for_act']").focusValue("email (valid email reqd for activation)");
        $("input[rel='mail_for_act']").focusValue("email (valid email reqd for activation)");
        $("input[rel='search_eg']").focusValue("e.g: ASP.net, admin..etc");
        $("input[rel='search_attach']").focusValue("Word | PDF only");
        $("input[rel='login_name']").focusValue("email");
        $("input[rel='login_pw']").focusValue("password");
        $("input[rel='reg_name']").focusValue("name");
		    $("input[rel='reg_mail']").focusValue("email");
		//browse project
        $("input[rel='search_project']").focusValue("search titles"); 
		
		//post project
		$("input[rel='project_title']").focusValue("e.g.  software developer, film editor"); 
		$("input[rel='aed']").focusValue("enter only number e.g 2500"); 
		
		//edit profile		
		//$("input[rel='edit_profile_email']").focusValue("somebody@somesting.som"); 
		//$("input[rel='edit_profile_job_title']").focusValue("e.g.Engineer, Sr.Visualiser, Jr. Copywriter"); 
		
		//my inbox
		$("input[rel='myinbox_search_mess']").focusValue("only keywords e.g. ASP.net, kitchen..."); 
		
		//project bid		
		 
		$("textarea[rel='project_bid_proposal']").focusValue("Only 1000 words. Include a brief description of yourself or your company.Describe why you are capable and qualified to complete this job.Attach relevant files or work samples."); 
		$("input[rel='project_bid_bidamount']").focusValue("only numbers e.g 230");
			$("input[rel='project_bid_hourlyrate']").focusValue("only numbers e.g 15");
		$("input[rel='project_bid_deliver']").focusValue("only numbers e.g. 14");
		//report violation
		$("textarea[rel='report_violation_details']").focusValue("Briefly describe within 500 words how the user has violated the Terms of this website."); 
		
		//
		
		//signup	
		$("input[rel='signup_job_title']").focusValue("e.g.Engineer, Sr.Visualiser, Jr. Copywriter"); 
		$("input[rel='signup_salary_expected']").focusValue("enter only numbers e.g 2500"); 
		$("input[rel='signup_hourly_rate']").focusValue("enter only numbers e.g 55"); 
		
		//forgot password
		$("input[rel='email_address']").focusValue("email address");
		 
		//=============-----------------
		$("#ctl00_ContentPlaceHolder1_GridView1 .memtable tr:even").addClass("td1");
/*------------------------------------------------------------------------*/
});

 
function GetTime(){		
	var mydate=new Date()
    var mytime=mydate.toGMTString().replace("Jul","July"); 
	var tempobj=document.getElementById("TopTime");
	if(tempobj!=undefined){
    var timestr="GMT time " + mytime.substring(17,mytime.length-7).replace(":","."); 	
		var month=mytime.substring(7,mytime.length-18);
		var day=mytime.substring(4,mytime.length-22)+",";
		var year=mydate.getFullYear()+" | ";
		var date=month+day+year;	
		var min=mydate.getMinutes();		  
		if(String(min).length<=1){
		    min="0"+min;
		}
		var localtime=mydate.getHours()+"."+min+ " | ";	
	tempobj.innerHTML=date+localtime+timestr;		
	}
} 

function GetCurrTime(obj){
	var tempobj=document.getElementById("TopTime");
	if(tempobj!=undefined){
		setInterval("GetTime()",1000);
	}
}

function Cmstime(){
	var mydate=new Date()
    var mytime=mydate.toLocaleString() ;
	return mytime;
}

var  CustomDropDown = function(ddlid,t,current_value,buttonclass,animation){
	
	var tempset=false;
	var current=false;
	/*得到可用最大深度*/	
	var maxdepth=0;
	$("div").each(
		function(){
			maxdepth=Math.max(maxdepth,$(this).css("z-index")||0)   
		}
	)
	maxdepth+=10;
	
	/*初始化*/
	if(arguments.length==2){
		buttonclass="selectbox";
		tempset=true;
		animation=true;		
		current=true;
	}
	if(arguments.length==3){
		buttonclass="selectbox";		 
		animation=true;		
		current=true;
	}
	if(arguments.length==1){
		buttonclass="selectbox";
		animation=true;
	}
	
	$(ddlid).css({display:"none"})
	.wrap("<div class=\"DropDownListWrap\" ></div>")
	.after("<a href=\"javascript:;\" style=\"color:#666\" class=\""+buttonclass+"\" style=\"outline:none\">select category</a><div class=\"DropDownListMenu\" ><ul></ul></div>")
	.focus(
		function(){
			$(this).blur();
		}
	).next().next().css({
		width:$(ddlid).next().width()-2	
	})
				
	//$("DropDownListMenu").fadeTo(0,0.5)			
	/*获得下拉表的数据*/	
	$(ddlid).children().each(
		function(){	
			var _content=$(this).html()
			_content=_content.length<=23?_content:_content.substring(0,26)+"...";
			$(ddlid).parent().find(".DropDownListMenu ul").append("<li title=\""+$(this).attr("value")+"\">"+_content+"</li>");
			if($(this).attr("value")==$(ddlid).val()){
				$(ddlid).next().html($(this).html());
			}	
			if(current){
				$(ddlid).next().html(current_value);
			}
		}
	);
	
	
	/*根据下拉表内容确定是否显示下拉条*/
	 $(ddlid).next().next().css({
			overflow:$(ddlid).children("option").length<10?"hidden":"auto",
			height:$(ddlid).children("option").length<10?($(ddlid).children("option").length*18+8)+"px":"200px"		
	}); 
	 
	  
	/*按钮事件*/
	var clicked=false;
	$(ddlid).next().click(
		function(e){	
			if(!clicked){
				if(!tempset){
					e.preventDefault() ;	
					if(animation){
						$(".DropDownListMenu").slideUp(400);	
						$(ddlid).next().next().slideDown(400);					
					}else{
						$(ddlid).next().next().show();
					}
				}
				clicked=true;
			}else{				 
				$(ddlid).next().next().slideUp(400);
				clicked=false;
			}		 
		}
	)
	.focus(
		function(e){
			$(this).blur();
			e.stopPropagation();	
		}
	)
	
	/*模拟下拉表点击事件*/
	$(ddlid).parent().find(".DropDownListMenu ul li").click(
		function(){
			clicked=false;
			var _content=$(this).html();
			_content=_content.length<=23?_content:_content.substring(0,26)+"...";
			$(ddlid).next().html(_content)
			.attr("title",$(this).attr("value"));			
			$(this).parent().parent().hide();	
			$(ddlid).children("option").each(					
				function(){							
					if($(this).html()==$(ddlid).next().text()){
						$(this)[0].selected=true;												
					}
				}
			)
		}
	).hover(
		function(){
			$(this).addClass("DropDownListRollOver");			
		},
		function(){
			$(this).removeClass("DropDownListRollOver");			
		}
	)
	
	/*点击空白处消失*/
	$(document).click(
		function(e){
			if(e.target.className!=buttonclass){			
					if(animation){					
						$(ddlid).next().next().slideUp(400);	
					}else{
						$(ddlid).next().next().hide();
					}
			}
		}
	)
	
}
 
/*=----------------------------------------------------------------------------

-Message AJax center

=----------------------------------------------------------------------------*/
var UserId=0;

function LoginSucc(){
	$("#LoginText").html("<a href=\"SignOut.aspx\">sign out</a>");	
}
function GetCurrentUserId(){
	$.ajax({
		url:MainPath+"Get_Current_UserInfo.aspx",
		cache: false,
		success:function(data){
			UserId=data;			
		}
	})
}

function SetOnlineFlag(){
	OnlineFlag=true;
}

function CheckUserOnPage(){ 
	if(OnlineFlag){
    	return true;
	}else{
		alert(Alert.PlsSignUp);
		return false;
	}
}
function CheckUserOnline(){
	$.get(MainPath+"CheckUserOnlineNow.aspx",function(data){		      
			 if(data=="true"){
				 OnlineFlag=true;				  
				 GetMessageCount();
			 }
	})
}
function ShowMessageBox(_type,_userid,_mid,_target,_url,_projectTitle){ 
	if(_userid==UserId){
		alert("you can\'t talk to you self.");
		return false;
	}
	if(_mid==undefined){_mid=0};
	if(_projectTitle==undefined){_projectTitle=="N/A";}
	$("#loading").fadeIn(300);			
    $("#temp_div").load(MainPath+"Message_Ajax_Center.aspx",{type:_type,uid:_userid,mid:_mid,projectTitle:_projectTitle},function(data){
        $(".discussbtn").attr("disabled","disabled");   
        $("#temp_div").remove("#form2");    //delete the form2 tag   
        if(data!="false"){
               $("#MessageBox").show(500,function(){ 
					$(_target).removeClass("boldfont");
					GetMessageCount();
					$("#loading").fadeOut(300);
				}); 		//show message box	   
              
		       $("textarea[rel='messagebox_content']").focusValue("Please keep your message clean and professional. Message can only be upto 500 words. If any violation is reported due to an argument you will be banned from the site. We appreciate your cooperation.");// set message box default content           
               $("#CloseBox").click(function(){ // close message box
                 BoxHidden();
               })   
			  
        }else{
               $(".discussbtn").removeAttr("disabled");
               alert(Alert.PlsSignUp);
              // location.reload();
			         $("#loading").fadeOut(300);
        }     
    }); 
}

function SendMessage(_type,_userid,_url,_projectTitle){
    var content=$("#txtMessageBody").val();
    if(content=="Please keep your message clean and professional. Message can only be upto 500 words. If any violation is reported due to an argument you will be banned from the site. We appreciate your cooperation."){
        alert(Alert.MessageBoxNotNull);
        return false;        
    }else{	         
        if(CheckWordCount(content,1000)){
            alert("The message has exceeded 100 words.");
            return false;
        }     
	 }	  
   if(_projectTitle==undefined){_projectTitle="N/A";}  
	 $("#loading").fadeIn(300);	
   $.post(MainPath+"Message_Ajax_Center.aspx",{type:_type,uid:_userid,messagebody:content,projectTitle:_projectTitle},function(data,statu){ 
      if(data=="true"){
           $("#Omessage").html(Alert.SendSucc).show();
           setTimeout("BoxHidden()",2000);  
		  $("#loading").fadeOut(300);
      }else{
         alert("Please re-try.");
         BoxShow();
      }
   })
}

function DeleteMessage(_type,_userid,_mid,_target,_url){
	$("#loading").fadeIn(300);
	  $.post(MainPath+"Message_Ajax_Center.aspx",{type:_type,uid:_userid,mid:_mid},function(data,statu){
			if(data=="true"){
				$("#Omessage").html(Alert.DeleteMessageSucc).show();
				$("table[rel='message_table"+_mid+"']").slideUp(1000); 		 
				BoxHidden();	
				$("#loading").fadeOut(300);
			}
	  })
}
function BoxShow(){
    $(".discussbtn").removeAttr("disabled");
    $("#MessageBox").hide(500);
}
function BoxHidden(){
    $("#MessageBox").hide(500);
    $(".discussbtn").removeAttr("disabled");
}

function GetMessageCount(){			 
		 if(OnlineFlag){
			GetCurrentUserId();
			$(".Message_Count").load(MainPath+"GetMessageCount.aspx?GetMessageCount=true");
		 }	 
}

function ShowGallery(_userid,_url){
		$("#loading").fadeIn(300);
	  $("#temp_div").load(MainPath+"gallery_ajax_center.aspx",{UserId:_userid},function(data){	
		 //CloseGallery
		 $("#loading").fadeOut(300);
		 $("#Gallery").slideDown(500);		
		 $(".CloseGallery").click(function(){
			 $("#Gallery").slideUp(500);
		 })
		$(".smallimg a").click(function(){
		$(".big_photo").show();
		$(".bigimg img").hide();
		$(".bigimg img").fadeIn(300).attr("src",$(this).attr("href"));
			return false;
		})
	  })
}

function AjaxGet(mytype,myid,pid){  
 if(confirm(Alert.SureDelete)){
      $.get(MainPath+"Ajax_Center.aspx",{"type":mytype,"id":myid,"pid":pid},function(data){   
       if(data=="true"){
          if(pid!=undefined){     
               $("#"+myid).parent().parent().hide();  
               if($("#PhotoBox td:visible").length==0){
                 $("#PhotoBox").hide();
               }        
          }else{            
            $("#"+myid).parent().hide();     
          }
        }
      })
  }
}
/*=----------------------------------------------------------------------------

-ALert text

=----------------------------------------------------------------------------*/
var Alert ={
	PlsSignUp:"You have to login or sign up to use this feature",
	SendSucc:"You message has been send successfully.",
	Message_Default_Content:"Please keep your message clean and professional. Message can only be up to 500 words. If any violation is reported due to an argument you will be banned from the site. We appreciate your cooperation.",
	MessageBoxNotNull:"Please fill message",
	DeleteMessageSucc:"Delete message success.",
	PlsFillRegName:"Please fill you name",
	PlsFillRegEmail:"Please fill email",	
	PlsFillPassword:"Please fill password",
	PlsFillFirstName:"Please fill first name",	
	PlsCEmail:"Please enter the correct Email",
	PlsCMP:"Please enter the correct mobile number",
	PlsAgree:"Please agree to the Terms and Privacy Policy below",
	NoAnyDoc:"Please upload your CV as a Word or PDF.",
	RepeatAccout:"Sorry this account already exists. Please create a new account.",
	LoginError:"Your account or password is not right, please re-try.",
	SureDelete:"Are you sure you want delete?",
	WordCount:"Project title up to 30 letters",
	NoUpBCard:"'Your account is being verified. It usually takes up to 24 hours. Please login again in a short while to post your business card'",
	ProTitle:"The project title excceds the allowed length.",
	Proposal:"The Proposal title excceds the allowed length."
};


/*=----------------------------------------------------------------------------

-ALert text

=----------------------------------------------------------------------------*/

function ShowDateTime(){
	var date=new Date();
	var month=date.getMonth();
	var datenow=date.getDate();
	var year=date.getFullYear(); 	
	var datearr=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	var day=datearr[date.getDay()];
	var hor=date.getHours();	
	var statu=hor>12?"pm":"am";
	var	miu = date.getMinutes() ;
	miu=miu<10?"0"+miu:miu;	
	var arr=new Array("January","February","March","April","May","June","July","August","September","October","November","December"		);
	var str=day+", "+arr[month]+" "+datenow+", "+year+" | "+ showTheHours(hor)+"."+ miu +" "+statu;	
  return str ;
}
function showTheHours(theHour)
	{
    if (theHour > 0 && theHour < 13)
    {
        if (theHour == "0") theHour = 12;
        return (theHour);
    }
    if (theHour == 0)
    {
        return (12);
    }
    return (theHour-12);
	}
	
function settime(){
	$("#showdate").html(ShowDateTime());		
}
function dset(){
	settime();
	setInterval("settime()",60000);
}

//---------------------------------------------------------------------------------------------
function CheckEmail(str)
{	
	var reg =/(\S)+[@]{1}(\S)+[.]{1}(\w)+/;
	return Check( reg, str );
}
function Check( reg, str )
{
	if( reg.test( str ) )
	{
		return true;
	}
	return false;
}
function M(_obj){
    return document.getElementById(_obj);
}
function CheckAgree(_obj){    
    return M(_obj).checked ; 
}//---------------------------------------------------------------------------------------------

//check word count
function CheckWordCount(value,maxcount)
{	
	var	temp = 	value.replace(/[\s|,|.|;|?]+/g," "),
		count = temp.split(/\s/).length;		
	return count > maxcount;
}
function gotop(){
     window.scroll(0,0); 
}
function CheckMpNumber(_str){	 
    var  count=_str.length
     for(var i=0;i<count;i++){
        var temp=_str.substring(i,i+1);
        if(temp=="+"||temp=="-"||temp==" "||!isNaN(temp))
        {            
            return true;
        }else{
            return false;
        }
      }      
   }
   
var Trim = function(_str) 
{ 
	return _str.replace(/ /g, ""); 
}