/////////	function for download	//////////
function validateDownload(filename)
{	
		//var path ='http://192.168.1.7/milestones/custom_images/';
		var path ='http://milestonetelecom.com/custom_images/';
		var fullPath = path+filename;
	    window.location.href = fullPath;  
}

function setLanguage(lang)
{
	var expdate=new Date();
	expdate.setDate(expdate.getDate()+365);
	//document.cookie="language=" +escape(lang)+";expires="+expdate.toGMTString();
	document.cookie="language=" +escape(lang)+";expires="+expdate.toGMTString()+"; path=/";
	window.location.reload(true);
}
///////////	set cookies	////////
function setCookie(c_name,value,exdays)
{
	//alert(c_name);
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value+"; path=/";
	window.location.reload(true);
}
//////////////	get cookie	////////////////
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

/////////////	check cookie	//////////////
function checkCookie()
{
	var language=getCookie("language");

  if (language!=null && language!="")
  {
  //alert("Welcome again " + language);
  }
else
  {
  language=prompt("Please enter your name:","");
  if (language!=null && language!="")
    {
    setCookie("language",language,365);
    }
  }
}

$(document).ready( function () 
{
	$("#typeConsultant").click(function () {
	$("#experienceId").show();
	});	
});

$(document).ready( function () 
{
	$("#typeCustomer").click(function () {
	$("#experienceId").hide();
	$("#other").hide();
	});	
});

////////////	login form validation	////////
$(document).ready(function()
  {
    $("#frmLogin").validate();
  });
////////////	staticpage form validation	////////////
$(document).ready(function()
  {
    $("#editStaticPage").validate();
	//$("#contactUs").validate();
  });


////// to valiadte fckeditior field ////////////////
$(document).ready( function () 
{
	$("#submit").click(function () {
	
	var EditorEnglish = FCKeditorAPI.GetInstance('description').EditorDocument;
		var iLengthEnglish;
		if ( document.all )
		{
			iLengthEnglish = EditorEnglish.body.innerText.length ;
			ivalue = EditorEnglish.body.innerText;
		}
		else
		{
			var r = EditorEnglish.createRange() ;
			r.selectNodeContents( EditorEnglish.body ) ;
			iLengthEnglish = r.toString().length ;
		}
		if(iLengthEnglish == 0)
		{
			$('#error-message').html('Please enter description');
			$('#error-message').show("normal");
			setTimeout(function() {
			 $('#error-message').hide("slow");
		   }, 3000);
			return false;
		}
		
		return true;	
		
	});	
});


//////////////	validate add new activity	////////////////

////// to valiadte fckeditior field ////////////////
$(document).ready( function () 
{
	$("#newActivitySubmit").click(function () {
	var title = $("#title").val();
	if(title == '')
	{
		$('#error-message').html('Please enter activity title');
			$('#error-message').show("normal");
			 window.scrollTo(0,0);
			  $("#title").focus();
			/*setTimeout(function() {
			 $('#error-message').hide("slow");
		   }, 3000);*/
			return false;
	}
	if(title.length > 80)
	{
		$('#error-message').html('Title length can not exceed 80 character');
			$('#error-message').show("normal");
			 window.scrollTo(0,0);
			  $("#title").focus();
			return false;	
	}
	var EditorEnglish = FCKeditorAPI.GetInstance('description').EditorDocument;
		var iLengthEnglish;
		if ( document.all )
		{
			iLengthEnglish = EditorEnglish.body.innerText.length ;
			ivalue = EditorEnglish.body.innerText;
		}
		else
		{
			var r = EditorEnglish.createRange() ;
			r.selectNodeContents( EditorEnglish.body ) ;
			iLengthEnglish = r.toString().length ;
		}
		
		if(iLengthEnglish == 0)
		{
			$('#error-message').html('Please enter activity description');
			$('#error-message').show("normal");
			 window.scrollTo(0,0);
			 
			/*setTimeout(function() {
			 $('#error-message').hide("slow");
		   }, 3000);*/
			return false;
		}
		////////////	check fck lenght	////////////////
		if(iLengthEnglish > 200)
		{
			$('#error-message').html('Description length can not exceed 200 character');
			$('#error-message').show("normal");
			 window.scrollTo(0,0);
			/*setTimeout(function() {
			 $('#error-message').hide("slow");
		   }, 3000);*/
			return false;
		}
		var language_code = $("#language_code").val();
		if(language_code =='')
		{
			$('#error-message').html('Please select language');
			$('#error-message').show("normal");
			 window.scrollTo(0,0);
			 $("#language_code").focus();
			/*setTimeout(function() {
			 $('#error-message').hide("slow");
		   }, 3000);*/
			return false;	
		}
		//////////	check document type	///////////////
		
		return true;	
	});	
	
	/////////////	edit static pages	/////////////////
	$("#Submitstatic").click(function () {
	var title = $("#title").val();
	if(title == '')
	{
		$('#error-message').html('Please enter title');
			$('#error-message').show("normal");
			 window.scrollTo(0,0);
			  $("#title").focus();
			/*setTimeout(function() {
			 $('#error-message').hide("slow");
		   }, 3000);*/
			return false;
	}
	var EditorEnglish = FCKeditorAPI.GetInstance('description').EditorDocument;
		var iLengthEnglish;
		if ( document.all )
		{
			iLengthEnglish = EditorEnglish.body.innerText.length ;
			ivalue = EditorEnglish.body.innerText;
		}
		else
		{
			var r = EditorEnglish.createRange() ;
			r.selectNodeContents( EditorEnglish.body ) ;
			iLengthEnglish = r.toString().length ;
		}
		
		if(iLengthEnglish == 0)
		{
			$('#error-message').html('Please enter description');
			$('#error-message').show("normal");
			 window.scrollTo(0,0);
			 
			/*setTimeout(function() {
			 $('#error-message').hide("slow");
		   }, 3000);*/
			return false;
		}
		
	
	});										
});

			

