var bPageValidate = false;var oldMemberPassword;var bPlusMemOptn;var subscriptionId = "";
var defkodetxt = "";
/*global start*/
function validateIsEmpty( Element )
{
  var Valid = true;
  if(Element == null || Element.value == "")
       Valid = false;
 return Valid;       
}
function validateIsEqual( Element1, Element2 )
{
  var Valid = true;
  if((Element1 == null || Element1.value == "" ) || 
     (Element2 == null || Element2.value == "" ) ||
     (Element1.value.toLowerCase() != Element2.value.toLowerCase()))      
       Valid = false;
 return Valid;
}
function validatePassword( Element1, Element2 )
{
  var Valid = true;
  if((Element1 == null || Element1.value == "" ) || 
     (Element2 == "" ) ||(Element1.value.toLowerCase() != Element2.toLowerCase()))      
       Valid = false;
 return Valid;
}
function validateEmail( Element1, Email )
{
  var Valid = true;
  if((Element1 == null || Element1.value == "" ) || 
     (Email == "" ) ||(Element1.value.toLowerCase() != Email.toLowerCase()))      
       Valid = false;
 return Valid;
}
function validateGenderBtns( Button1 , Button2)
{
  var Valid = true;
  if((Button1 == null || Button1.checked == false) && 
     (Button2 == null || Button2.checked == false))
     {
       Valid = false;     
     }     
    return Valid;
}
function validateCheckBox( CButton )
{
 var Valid = true;
 if((CButton == null || CButton.checked == false))
    Valid = false;    
 return Valid;
}
function validateDropDown( DropDownlist )
{
var Valid = true;
if((DropDownlist == null || DropDownlist.selectedIndex == 0))
  Valid = false; 
return Valid;
}
function validateReqDate( DropDownDay,DropDownMonth,DropDownYear )
{
var Valid = true;
if((DropDownDay == null || DropDownDay.selectedIndex == 0) ||
   (DropDownMonth == null || DropDownMonth.selectedIndex == 0) || 
   (DropDownYear == null || DropDownYear.selectedIndex == 0))
  Valid = false;     
  return Valid;     
} 
function IsValidDate( DropDownDay,DropDownMonth,DropDownYear )
{
  var day   = DropDownDay.value;
  var month = DropDownMonth.value;
  var year  = DropDownYear.value;   
  
  var objdate = new Date(month + "/" + day + "/" + year); 
  var valid = false ;
   
  if( (objdate.getDate() == day) && 
      (objdate.getMonth() + 1 == month) && 
      (objdate.getFullYear() == year) )
       valid = true;             
  return valid;
}
function IsValidString( UserData )
{		
	var objStringRegex = new RegExp(/^\D{1,100}$/);	
	return objStringRegex.test(UserData);
}
function IsValidEmail( EmailAddress )
{
     //var emailRegExp = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\.\\w+([-.]\\w+)*";          
     var objRegex = new RegExp(/^.+@.+\..{2,4}$/);
     return objRegex.test(EmailAddress);
}
function IsValidPostNumber( UserData, lang )
{
	var objStringRegex  =  null;var bValidpost = true;
	if(lang == "da" || lang == "dk" || lang == "no")
	{objStringRegex  = new RegExp(/^\d{4,4}$/);}
	else if(lang == "sv" || lang == "se")
	{objStringRegex  = new RegExp(/^\d{5,5}$/);}
	else if(lang == "de")
	{objStringRegex  = new RegExp(/^\d{5,5}$/);}	
	if(objStringRegex != null)		
	{bValidpost = objStringRegex.test(UserData);}
	return bValidpost;
}
function IsValidPhone( UserData, lang )
{
	var bValidphone = true;
	var objStringRegex  =  null;
	if(lang == "da" || lang == "dk")
	{
		objStringRegex  = new RegExp(/^\d{8,8}$/);
	}
	else if(lang == "sv" || lang == "se")
	{
		//objStringRegex  = new RegExp(/^\d{8,10}$/);	
		objStringRegex = new RegExp(/^[0-9- ]{8,10}$/);	
	}
	else if(lang == "de")
	{
		objStringRegex  = new RegExp(/^\d{7,12}$/);
	}
	else if(lang == "no")
	{
		objStringRegex  = new RegExp(/^\d{8,8}$/);
	}	
	else
	{
		objStringRegex  = new RegExp(/^\d{7,12}$/);
	}
	if(objStringRegex != null)		
	{
		bValidphone = objStringRegex.test(UserData);
	}	
	return bValidphone;
}
/*global end*/
function RestoreMemberDetails()
{
  AjaxPro.timeoutPeriod = 60*1000;
  AjaxWrapper.GetEditMemberDetails(1,GetEditMemberDetailsCallBack,null,null, null, TimeOut, null);
}
function RestoreMemberDetails(Mode)
{
  AjaxPro.timeoutPeriod = 60*1000;
  AjaxWrapper.GetEditMemberDetails(Mode,GetEditMemberDetailsCallBack,null,null, null, TimeOut, null);
}
function GetEditMemberDetailsCallBack(ret)
{
	if(ret.value[0] == 1)
	{
	    var nIndx;var nSelectedIndx;	    
	    var maleRdBtn=document.getElementById("pageProfilEditGenderMale");
		var femaleRdBtn=document.getElementById("pageProfilEditGenderFemale");
		
		getElementsByClassName(document,"input","csECTextBox")[0].value = ret.value[1]; // FirstName
		oldMemberPassword = ret.value[14];		
		oldMemberEmail = ret.value[9];		
		getElementsByClassName(document,"input","csECTextBox")[1].value = ret.value[2]; // LastName
		getElementsByClassName(document,"input","csECTextBox")[2].value = ret.value[3]; // Addresss
		getElementsByClassName(document,"input","csECTextBox")[3].value = ret.value[4]; // postnumber
		getElementsByClassName(document,"input","csECTextBox")[4].value = ret.value[5]; // city
		getElementsByClassName(document,"input","csECTextBox")[5].value = ret.value[7]; // telefon
		getElementsByClassName(document,"input","csECTextBox")[6].value = ret.value[8]; // mobile
		
		var dayDdl,mthDdl,yrDdl;
		
		(dayDdl = getElementsByClassName(document,"select","ddlClassDay")[0]).value = ret.value[10];
		(mthDdl = getElementsByClassName(document,"select","ddlClassMonth")[0]).value = ret.value[11];
		(yrDdl = getElementsByClassName(document,"select","ddlClassYear")[0]).value = ret.value[12];
		
		RefrsehJQCombo(dayDdl);
		RefrsehJQCombo(mthDdl);
		RefrsehJQCombo(yrDdl);
		
		if(ret.value[13] == 1)
		{
			maleRdBtn.checked = true;
			femaleRdBtn.checked = false;
		}
		else if(ret.value[13] == 0)
		{
			maleRdBtn.checked = false;
			femaleRdBtn.checked = true;
		}		
		var dropCountry = getElementsByClassName(document,"select","ddlClassCountry")[0];
		for(nIndx=0;nIndx<dropCountry.length;nIndx++)
		{
			if(dropCountry.options[nIndx].value == ret.value[6])
			{
				nSelectedIndx = nIndx;
			}
		}
		dropCountry.selectedIndex = nSelectedIndx;		
		RefrsehJQCombo(dropCountry);
	}
	else if(ret.value[0] != -1)
	{
	    oldMemberPassword = ret.value[14];		
		oldMemberEmail = ret.value[9];		
	}
	
}
function ValidatePasswordSaveEditProfile()
{

    //Old Password
   var txtPwdBox = getElementsByClassName(document,"input","csOldPwdBox")[0];
   var validPwd = validateIsEmpty(txtPwdBox);    
   //New Password
   var txtNPwdBox = getElementsByClassName(document,"input","csPwdBox")[0];         
   var validNPwd = validateIsEmpty(txtNPwdBox);    
   //Retype New Password
   var txtRNPwdBox = getElementsByClassName(document,"input","csRepPwdBox")[0];         
   var validRNPwd = validateIsEmpty(txtRNPwdBox);   
   
   var validCurrentPass = validatePassword(txtPwdBox,oldMemberPassword);
   var validComparePwd = validateIsEqual(txtNPwdBox,txtRNPwdBox);      
   bPageValidate = false;   
   if( validPwd && validNPwd && validRNPwd && validCurrentPass && validComparePwd )
   {
		bPageValidate = true;  	

		AjaxPro.timeoutPeriod = 60*1000;
		AjaxWrapper.FillPassword(txtNPwdBox.value,null,null,null, null, TimeOut, null);
		AjaxWrapper.ChangeMemberProfile(ValidateSaveEditProfileCallBack,null,null, null, TimeOut, null);				
   }		
   else
   {
		if(bPageValidate == false)
		{


		    scrollTo(0,100);
			HideError();
			ClearAllValidityMsgs();
			//Password
			if( !validPwd )
			{
			   positionValidityMsg(getElementsByClassName(document,"div","csOldPwdErr")[0],txtPwdBox,false);
			}
			if( !validNPwd ) //new Password
			{  
			    positionValidityMsg(getElementsByClassName(document,"div","csPwdErr")[0],txtNPwdBox,false);   
			}   
			if( !validRNPwd ) //Repeat Password
			{     
				positionValidityMsg(getElementsByClassName(document,"div","csRepPwdEmpty")[0],txtRNPwdBox,false);   
			}    
			if( validPwd && !validCurrentPass)
			{
			    positionValidityMsg(getElementsByClassName(document,"div","csInvPwdErr")[0],txtPwdBox,false);   
			}
			if(validNPwd && validRNPwd && !validComparePwd)
			{
			    positionValidityMsg(getElementsByClassName(document,"div","csRepPwdErr")[0],txtRNPwdBox,false);   

			}
		}
	}    
}
function ShowError(ctrl)
{
    var evt = ctrl["onblur"];
    if(typeof(evt) == 'function') evt();
}
function HideError()
{
    var Containers = getElementsByClassName(document,"div","csDefEPErrDiv");    
    for(nIndx=0;nIndx<Containers.length;nIndx++)
    {Containers[nIndx].style.display = "none";}
}
function ValidateSaveEditProfileCallBack(ret)
{	
	if( ret != null && ret.value != null && ret.value.length > 0)
	{
	    scrollTo(0,100);
	    HideError();
	    if(ret.value[0] == 1)
	    {

	        var msg = document.getElementById('pageProfilEditSuccess');
	        msg.style.display = "block"
	        if(ret.value[1] != "")
	            msg.innerHTML = ret.value[1];
	        document.getElementById('pageProfilEditErrorMsg').style.display = 'none';

	    }
	    else
	    {

	        var msg = document.getElementById('pageProfilEditErrorMsg');
	        msg.style.display = "block"
	        if(ret.value[1] != "")
	            msg.innerHTML = ret.value[1];

	        document.getElementById('pageProfilEditSuccess').style.display = "none";
	    }	    
	    
	}
}
function ValidateSaveEditContact()
{	
   var txtBoxes = getElementsByClassName(document,"input","csECTextBox");
   
   //Nationality DropDown   
   var DropDownElements = getElementsByClassName(document,"select","ddlClassCountry");
   var DropDownNational = DropDownElements[0];   
   var validNational   = validateDropDown(DropDownNational);       
   
   var validNameBox
   var txtLastNameBox ;
   var validLastNameBox;
   var txtAddressBox ;
   var validAddress;
   var txtPostNumberBox ;
   var validPostNumber;
   var txtCityBox ;
   var validCity;
   var txtPhoneNumberBox ;   
   var validPhoneNumber;   
   var txtMobNumberBox ;   
   var validMobNumber;   
   var validphone;
   var validmobile = true;  
   var ValidEmailAddress;    

   var txtNameBox = txtBoxes[0];
   validNameBox = validateIsEmpty(txtNameBox);   
   if(validNameBox)
   {   
		validNameBox  = IsValidString(txtNameBox.value);		
   }   

   txtLastNameBox = txtBoxes[1];
   validLastNameBox = validateIsEmpty(txtLastNameBox);
   if(validLastNameBox)
   {   		
		validLastNameBox  = IsValidString(txtLastNameBox.value);		
   }		
    
    txtAddressBox   = txtBoxes[2];
    validAddress = validateIsEmpty(txtAddressBox);		
	
	txtPostNumberBox  = txtBoxes[3];
	validPostNumber = validateIsEmpty(txtPostNumberBox);
	/*if(validPostNumber)
	{			
		validPostNumber = IsValidPostNumber(txtPostNumberBox.value,DropDownNational.value);		
	}*/		
	
	txtCityBox  = txtBoxes[4];
	validCity = validateIsEmpty(txtCityBox);
	if(validCity)
	{
		validCity = IsValidString(txtCityBox.value);
	}		
	
	txtPhoneNumberBox  = txtBoxes[5];
	validPhoneNumber = validateIsEmpty(txtPhoneNumberBox);
	if(validPhoneNumber)
		validphone = IsValidPhone(txtPhoneNumberBox.value, DropDownNational.value);

	txtMobNumberBox  = txtBoxes[6];
	/*validMobNumber  = validateIsEmpty(txtMobNumberBox);		
	if(validMobNumber)
		validmobile = IsValidPhone(txtMobNumberBox.value, DropDownNational.value);						
	else
	    validmobile = true;*/

   //Gender RadioButtons
   var maleRdBtn=document.getElementById("pageProfilEditGenderMale");
   var femaleRdBtn=document.getElementById("pageProfilEditGenderFemale");
   var validGender = validateGenderBtns(maleRdBtn,femaleRdBtn);           
   var DropDownDay = getElementsByClassName(document,"select","ddlClassDay")[0];
   var DropDownMonth = getElementsByClassName(document,"select","ddlClassMonth")[0];
   var DropDownYear= getElementsByClassName(document,"select","ddlClassYear")[0];   
   var validReqDate = validateReqDate(DropDownDay,DropDownMonth,DropDownYear);
   if(validReqDate)
   var validDate = IsValidDate(DropDownDay,DropDownMonth,DropDownYear);    
   bPageValidate = false;   
   if( validNameBox && validGender && validNational && validReqDate && validDate  && validLastNameBox && validAddress && validPostNumber && validCity && validmobile && validphone)
   {   
		bPageValidate = true;  		
		LastName = txtLastNameBox.value;		
		Address = txtAddressBox.value;
		PostNumber = txtPostNumberBox.value;
		City = txtCityBox.value;		
		PhoneNumber = txtPhoneNumberBox.value ;
		MobNumber = txtMobNumberBox.value;				
		var dayIndex   = DropDownDay.selectedIndex;
		var monthIndex = DropDownMonth.selectedIndex;
		var yearIndex  = DropDownYear.selectedIndex;		
		var day = DropDownDay.options[dayIndex].text;
		var month = DropDownMonth.options[monthIndex].value;
		var year = DropDownYear.options[yearIndex].text;		
		sexId = 1;
		if(maleRdBtn.checked == true)
			sexId = 1;
		else if(femaleRdBtn.checked == true)   
			sexId = 0;
		var nationIndex = DropDownNational.selectedIndex;     
		CountryId = DropDownNational.options[nationIndex].value;
		var EditName = txtNameBox.value;
		SaveEditProfile(EditName,LastName,"",Address,PostNumber,City,CountryId,PhoneNumber,MobNumber,year,month,day,sexId,"");

	}		
	else
	{
		if(bPageValidate == false)
		{
		    var evt;
			scrollTo(0,100);
			HideError();
			ClearAllValidityMsgs();
			if( !validNameBox )
			{
				ShowError(txtNameBox);
			}
			if(!validLastNameBox  )
			{
				ShowError(txtLastNameBox);
			}
			if(!validAddress  )
			{
				ShowError(txtAddressBox);
			}
			if(!validPostNumber || !validNational )
			{
				ShowError(txtPostNumberBox);
			}
			if(!validCity)
			{
			    ShowError(txtCityBox);
			}
			if(!validPhoneNumber || !validphone )
			{
			    ShowError(txtPhoneNumberBox);
			}
			if(!validmobile )
			{
			    ShowError(txtMobNumberBox);
			}

			if( !validReqDate || !validDate )
			{
				var errDiv = getElementsByClassName(document,"div","csEPDOBErr")[0];
				positionValidityMsg(errDiv,DropDownMonth.nextSibling,false);
			}     
			if( !validGender )  //Gender RadioButtons
			{
				var errDiv = getElementsByClassName(document,"div","csEPGenErr")[0];
				positionValidityMsg(errDiv,document.getElementById("spnEPGender"),false);
			}     	
		}
	} 
}
function SaveEditProfile(EditName,LastName,EditEmail,Address,PostNumber,City,CountryId,PhoneNumber,MobNumber,year,month,day,sexId,EditMemberShipPeriod)
{
	AjaxPro.timeoutPeriod = 60*1000;	
	AjaxWrapper.FillMemberDetails(EditName,LastName,EditEmail,Address,PostNumber,City,CountryId,PhoneNumber,MobNumber,year,month,day,sexId,EditMemberShipPeriod,null,null,null, null, TimeOut, null);			
	AjaxWrapper.ChangeMemberProfile(ValidateSaveEditProfileCallBack,null,null, null, Timedout, null);	
}
/*signup*/
function ValidateFreeMemberDetails(langCode)
{
	HideError();
	var txtFirstName = getElementsByClassName(document,"input","tbClass")[0];
	var txtLastName = getElementsByClassName(document,"input","tbClass")[1];
	var txtemail = getElementsByClassName(document,"input","tbClass")[2];
	var txtRepeatEmail = getElementsByClassName(document,"input","tbClass")[3];
	var txtPass = getElementsByClassName(document,"input","tbClass")[4];
	var txtRepeatPass = getElementsByClassName(document,"input","tbClass")[5];	
	
	var chkCond = document.getElementById("pageSignupFreeTermsChk");
	var chkNews = document.getElementById("pageSignupFreeNewsletterChk");
	
	var validFirstName = validateIsEmpty(txtFirstName);
	if(validFirstName)
		validFirstName = IsValidString(txtFirstName.value);	
	
	var validLastName = validateIsEmpty(txtLastName);
	if(validLastName)
		validLastName = IsValidString(txtLastName.value);	
		
		
	var validEmail = validateIsEmpty(txtemail);
	if(validEmail)
		validEmail = IsValidEmail(txtemail.value);	

	var validMail = validateIsEqual(txtemail,txtRepeatEmail);
	
	var validCond = validateCheckBox(chkCond);
	var NewsLetter = validateCheckBox(chkNews);	
	
    //Password   
    var validPwd = validateIsEmpty(txtPass,"");   
    var validRPwd = validateIsEqual(txtPass,txtRepeatPass);   	
	
	if(validFirstName && validLastName && validEmail && validMail && validPwd && validRPwd && validCond && NewsLetter)
	{			
		AjaxPro.timeoutPeriod = 60*1000;
		AjaxWrapper.UpdateDetailsToMemberObject(txtFirstName.value, txtLastName.value, txtemail.value,txtPass.value,langCode,NewsLetter,null,null,null,null,null,null,null,0,"B",0,"",UpdateMemberCallBack,null,null, null, TimeOut, null);
	}
	else
	{
		if(!validFirstName)
		{
			SignUpError(0);
		}
		if(!validLastName)
		{
			SignUpError(1);
		}
		if(!validEmail)
		{
			SignUpError(2);
		}
		if(!validMail)
		{
		    SignUpError(2);
			SignUpError(3);
		}
		if(!validPwd)
		{
			SignUpError(4);
		}
		if(!validRPwd)
		{
		    SignUpError(4);
			SignUpError(5);
		}
		if(!validCond)
		{
			SignUpError(6);
		}
		if(!NewsLetter)
		{
			SignUpError(7);
		}
	}
}
function SignUpError(index)
{    
    document.getElementById('pageSignupErrorMsg').style.display = "block";    
    getElementsByClassName(document,"span","tbError")[index].style.display = "block";
}
function UpdateMemberCallBack(ret)
{	
    if(ret != null && ret.value != null && ret.value[0] != null)
	{
		if(ret.value[0] == 1)
		{
		    AjaxPro.timeoutPeriod = 60 * 1000;
		    document.getElementById('pageSignupErrorMsg').style.display = "none";
			document.getElementById('pageSignupFreeConfirm').style.display = 'block';
			document.getElementById('pageSignupFree').style.display = 'none';
			document.getElementById('hsignupHead').innerHTML = AjaxWrapper.GetLabel(1025,null,null,null, null, TimeOut, null).value;
			document.getElementById('psignupSubhead').innerHTML = AjaxWrapper.GetLabel(1026,null,null,null, null, TimeOut, null).value;
			try{document.getElementById('confirmFN').innerHTML = ret.value[1];}catch(e){};
			try{document.getElementById('confirmLN').innerHTML = ret.value[2];}catch(e){};
			try{document.getElementById('confirmEmail').innerHTML = ret.value[3];}catch(e){};	
		}
	}
}

function CreateFreeMember(langCode,sapCode,programId)
{
    AjaxPro.timeoutPeriod = 60*1000;
    var ret = AjaxWrapper.GetDetailsFromMemberObject("B",null,null,null, null, TimeOut, null);
    if(ret != null && ret.value != null && ret.value[0] != null)
    {
    if(ret.value[0] == 1)
    {
    document.getElementById('CreateFreeMemberwait').style.display = "block";
    AjaxPro.timeoutPeriod = 60*1000;
    AjaxWrapper.CreateFreeMemberSignUp(0,sapCode,programId,CreateMemberCallBack,null,null, null, TimeOut, null);
    }
    else if(ret.value[0] == 0)
    location.href = location.href;
    }
}
function TimeOut()
{
}

function CreateMemberCallBack(ret)
{
	document.getElementById('CreateFreeMemberwait').style.display = "none";
	if(ret != null && ret.value != null && ret.value[0] != null)
	{
		if(ret.value[0] == 1)
		{
		    AjaxPro.timeoutPeriod = 60 * 1000;
		    document.getElementById('pageSignupErrorMsg').style.display = "none";
            document.getElementById('editDiv').style.display = 'none';
            document.getElementById('divCreateMember').style.display = 'none';
            //document.getElementById('divLogin').style.display = 'block';	
            document.getElementById('hsignupHead').innerHTML = AjaxWrapper.GetLabel(1027,null,null,null, null, TimeOut, null).value;//'Vi har sendt en aktiveringsmail til din<br />e-mail adresse';
            document.getElementById('divFMemberPixel').innerHTML = (ret.value[1] != null)? ret.value[1]:"";
		}
		else
		{
		    document.getElementById('pageSignupErrorMsg').style.display = "block";		    
			if(ret.value[0] == 2)	// Email Already Exist		
				SignUpAjaxError(2630);			
			else if(ret.value[0] == 3)	//A Member Inactive
			{document.getElementById('pageSignupErrorMsg').innerHTML = "<p>" + ret.value[5] + "</p>";}
			else if(ret.value[0] == 4)	//B Member Inactive
			{document.getElementById('pageSignupErrorMsg').innerHTML = "<p>" + ret.value[5] + "</p>";}
			else if(ret.value[0] == 5)	// already B Member with correct e-mailid and passsword
			{document.getElementById('pageSignupErrorMsg').innerHTML = "<p>" + ret.value[5] + "</p>";}
			else if(ret.value[0] == 6)	// already A Member with correct e-mailid and passsword
			{document.getElementById('pageSignupErrorMsg').innerHTML = "<p>" + ret.value[5] + "</p>";}			
			else if(ret.value[0] == -1 || ret.value[0] == -2 || ret.value[0] == -3 || ret.value[0] == -4)	//CreateMember unknown Error
				SignUpAjaxError(2032);
		}
	}
	else
	{
	    document.getElementById('pageSignupErrorMsg').style.display = "block";
		SignUpAjaxError(2019);// UnKnown Error	
	}
}
function SignUpAjaxError(labelId)
{   
    AjaxPro.timeoutPeriod = 60 * 1000; 
    document.getElementById('pageSignupErrorMsg').innerHTML = "<p>" + AjaxWrapper.GetLabel(labelId,null,null,null, null, TimeOut, null).value + "</p>";
}

function FillFreeMemberDetails()
{
	AjaxPro.timeoutPeriod = 60*1000;
	var ret = AjaxWrapper.GetDetailsFromMemberObject("B",null,null,null, null, TimeOut, null);
	if(ret != null && ret.value != null && ret.value[0] != null)
	{
		if(ret.value[0] == 1)
		{
			document.getElementById('pageSignupFreeConfirm').style.display = 'none';
			document.getElementById('pageSignupFree').style.display = 'block';
			document.getElementById('hsignupHead').innerHTML = AjaxWrapper.GetLabel(1028,null,null,null, null, TimeOut, null).value;//'Bliv medlem og fÃ¥ masser ar fordele<br />- det er 100% gratis';
			document.getElementById('psignupSubhead').innerHTML = AjaxWrapper.GetLabel(1029,null,null,null, null, TimeOut, null).value;//'Meld dig ind herunder og masser af ekstra billige ferietilbud,<br />konkurrencer og rejseauktioner.';
		}
		else if(ret.value[0] == 0)
			location.href = location.href;
	}	
}
function RedirectToLogin(url)
{location.href=url;}
function SendSignUpActivateMail()
{
	var txtemail = getElementsByClassName(document,"input","tbClass")[2].value;
	AjaxPro.timeoutPeriod = 60*1000;
	AjaxWrapper.SendActivateMail(txtemail,"INACTIVE",null,null,null, null, TimeOut, null);
}
function signupPlusSelector(id)
{    
    if(id == 200)
    {
        getElementsByClassName(document,"div","pageSignupPlusSelector200")[0].className = 'pageSignupPlusSelector200 active';
        getElementsByClassName(document,"div","pageSignupPlusSelector150")[0].className = 'pageSignupPlusSelector150 inactive';        
        document.getElementById('oneYear').checked = true;
    }
    else if(id == 150)
    {
        getElementsByClassName(document,"div","pageSignupPlusSelector200")[0].className = 'pageSignupPlusSelector200 inactive';
        getElementsByClassName(document,"div","pageSignupPlusSelector150")[0].className = 'pageSignupPlusSelector150 active';        
        document.getElementById('halfYear').checked = true;
    }
}
function switchPayOption(id)
{
    if(id=='pageSignupPlusPaymentDIBS')
    {document.getElementById('divOnlinePayment').style.display = 'block';document.getElementById('divBS').style.display = 'none';document.getElementById('divFree').style.display = 'none';}
    else if(id=='pageSignupPlusPaymentPBS')
    {document.getElementById('divOnlinePayment').style.display = 'none';document.getElementById('divBS').style.display = 'block';document.getElementById('divFree').style.display = 'none';}
    
    var selection = "pageSignupPlusPaymentDIBS#pageSignupPlusPaymentPBS";
    var selectionArray = selection.split("#");
    var e = document.getElementById(id);    
    if (e != null) {
        for (var i = 0; i < selectionArray.length; i++) {
            
            var s = document.getElementById(selectionArray[i]);
            if (s != null) {
                s.className = "inactive";
            }
            
        }
        e.className = "active";
    }   
}
function ValidatePlusMemberDetails(langCode,anniversary,programId)
{
    HideError();
	if(document.getElementById("oneYear").checked)
		bPlusMemOptn = 1;
	else if(document.getElementById("halfYear").checked)
		bPlusMemOptn = 2;	

	var txtFirstName = getElementsByClassName(document,"input","tbClass")[0];
	var txtLastName = getElementsByClassName(document,"input","tbClass")[1];
	var txtAddress = getElementsByClassName(document,"input","tbClass")[2];
	var txtPostNo = getElementsByClassName(document,"input","tbClass")[3];
	var txtPhone = getElementsByClassName(document,"input","tbClass")[5];
	var txtMobile = getElementsByClassName(document,"input","tbClass")[6];
	var txtCity = getElementsByClassName(document,"input","tbClass")[4];
	var txtemail = getElementsByClassName(document,"input","tbClass")[7];
	var txtRepeatEmail = getElementsByClassName(document,"input","tbClass")[8];
	var txtPass = getElementsByClassName(document,"input","tbClass")[9];
	var txtRepeatPass = getElementsByClassName(document,"input","tbClass")[10];
	var txtSubscriptionId=null;
	if(programId == "153")
	    txtSubscriptionId = getElementsByClassName(document,"input","tbClass")[11];
		
	var chkCond = document.getElementById("pageSignupPlusTermsChk");
	var chkNews = document.getElementById("pageSignupPlusNewsletterChk");
	
	var validFirstName = validateIsEmpty(txtFirstName);
	if(validFirstName)
		validFirstName = IsValidString(txtFirstName.value);	
	
	var validLastName = validateIsEmpty(txtLastName);
	if(validLastName)
		validLastName = IsValidString(txtLastName.value);	

	var validAddress = validateIsEmpty(txtAddress);
	

   //Nationality DropDown   
   var DropDownElements = getElementsByClassName(document,"select","ddlClassCountry");   
   var DropDownNational = DropDownElements[0];   
   var validNational   = validateDropDown(DropDownNational);       


	var validPostNo = validateIsEmpty(txtPostNo);
	/*if(validPostNo)
		validPostNo = IsValidPostNumber(txtPostNo.value,DropDownNational.value);	*/

	//CountryId = DropDownNational.value;	 
	
	var validCity = validateIsEmpty(txtCity);
	if(validCity)
		validCity = IsValidString(txtCity.value);	
				
    var nationIndex = DropDownNational.selectedIndex;     
    var CountryCode = DropDownNational.options[nationIndex].value;	 
    var CountryName = DropDownNational.options[nationIndex].text;	 

	var validPhone = validateIsEmpty(txtPhone);
	if(validPhone)
		validPhone = IsValidPhone(txtPhone.value,DropDownNational.value);	

	var validMobile = true;
	var validMobileNumber = validateIsEmpty(txtMobile);
	if(validMobileNumber)
		validMobile = IsValidPhone(txtMobile.value,DropDownNational.value);	
		
	var validEmail = validateIsEmpty(txtemail);
	if(validEmail)
		validEmail = IsValidEmail(txtemail.value);	

	var validMail = validateIsEqual(txtemail,txtRepeatEmail);
	
	var validCond = validateCheckBox(chkCond);
	var NewsLetter = validateCheckBox(chkNews);	
	
    //Password   
    var validPwd = validateIsEmpty(txtPass,"");   
    var validRPwd = validateIsEqual(txtPass,txtRepeatPass);   
    
    var validSubscritionId=true;
    if(txtSubscriptionId != null)
    {
        validSubscritionId = validateIsEmpty(txtSubscriptionId);	
        if(validSubscritionId)
            subscriptionId = txtSubscriptionId.value;
    }    
	if(validFirstName && validLastName && validAddress && validPostNo && validCity && validNational && validPhone && validMobile && validEmail && validMail && validPwd && validRPwd && validCond && validSubscritionId)
	{			
		AjaxPro.timeoutPeriod = 60*1000;
		AjaxWrapper.UpdateDetailsToMemberObject(txtFirstName.value, txtLastName.value, txtemail.value,txtPass.value,langCode,NewsLetter,txtAddress.value,txtPostNo.value,txtPhone.value,txtMobile.value,txtCity.value,CountryCode,CountryName,bPlusMemOptn,"A",anniversary,programId,UpdatePlusMemberCallBack,null,null, null, TimeOut, null);
	}
	else
	{
		if(!validFirstName)
		{
			SignUpError(0);
		}
		if(!validLastName)
		{
			SignUpError(1);
		}
		if(!validAddress)
		{
			SignUpError(2);
		}
		if(!validPostNo)
		{
			SignUpError(3);
		}
		if(!validCity)
		{		
			SignUpError(4);
		}
		if(!validNational)
		{
			SignUpError(5);
		}
		if(!validPhone)
		{
			SignUpError(6);
		}
		if(!validMobile)
		{
			SignUpError(7);
		}
		if(!validEmail)
		{
			SignUpError(8);
		}
		if(!validMail)
		{
			SignUpError(9);
		}
		if(!validPwd)
		{
			SignUpError(10);
		}
		if(!validRPwd)
		{
			SignUpError(11);
		}
		if(!validCond)
		{
			SignUpError(12);
		}
		if(!validSubscritionId)
		{
		    document.getElementById('pageSignupErrorMsg').style.display = "block";    
            getElementsByClassName(document,"span","tbErrorSId")[0].style.display = "block";
		}		
		
	}
}
function UpdatePlusMemberCallBack(ret)
{	
	if(ret != null && ret.value != null && ret.value[0] != null)
	{
		if(ret.value[0] == 1)
		{
			AjaxPro.timeoutPeriod = 60 * 1000;
		    //If anniversary
		    if(ret.value[10] != null && ret.value[10] == 1)
		    {
		        getElementsByClassName(document,"h2","hplussignupHead")[0].innerHTML = AjaxWrapper.GetLabel(1094, null,null,null, null, TimeOut, null).value;
		        try{document.getElementById('memPeriod').innerHTML = ret.value[4];}catch(e){};		        
		    }
		    else
		    {
		        if(ret.value[11] && ret.value[11] != '1-0252')
		            getElementsByClassName(document,"h2","hplussignupHead")[0].innerHTML = AjaxWrapper.GetLabel(1024,null,null,null, null, TimeOut, null).value;//'BekrÃ¦ft dit<br />PLUSmedlemskab';
		            
		        try{document.getElementById('memPeriod').innerHTML = ret.value[4];}catch(e){};
		    }		    
			document.getElementById('plussignupSubhead').style.display = 'block';
		    document.getElementById('pageSignupErrorMsg').style.display = "none";
			document.getElementById('pageSignupPlusConfirm').style.display = 'block';
			document.getElementById('pageSignupPlus').style.display = 'none';
			try{document.getElementById('fn').innerHTML = ret.value[1];}catch(e){};
			try{document.getElementById('ln').innerHTML = ret.value[2];}catch(e){};	
			try{document.getElementById('email').innerHTML = ret.value[3];}catch(e){};	
			
			try{document.getElementById('address').innerHTML = ret.value[5];}catch(e){};	
			try{document.getElementById('zip').innerHTML = ret.value[6];}catch(e){};	
			try{document.getElementById('city').innerHTML = ret.value[7];}catch(e){};	
			try{document.getElementById('phone').innerHTML = ret.value[8];}catch(e){};	
			if(ret.value[9] != null && ret.value[9] != "")
			{
				try{document.getElementById('mobilediv').style.display = 'block';}catch(e){};
				try{document.getElementById('mobile').innerHTML = ret.value[9];}catch(e){};
			}
			else
				try{document.getElementById('mobilediv').style.display = 'none';}catch(e){};		
		    try{document.getElementById('subscriptionId').innerHTML = subscriptionId;}catch(e){};	
		}
	}
}
function FillPlusMemberDetails(anniversary, programId)
{
	AjaxPro.timeoutPeriod = 60*1000;
	var ret = AjaxWrapper.GetDetailsFromMemberObject("A",null,null,null, null, TimeOut, null);
	if(ret != null && ret.value != null && ret.value[0] != null)
	{
		if(ret.value[0] == 1)
		{
		    document.getElementById('pageSignupPlusConfirm').style.display = 'none';
			document.getElementById('pageSignupPlus').style.display = 'block';
			if(anniversary == 1)
			    getElementsByClassName(document,"h2","hplussignupHead")[0].innerHTML = AjaxWrapper.GetLabel(1095,null,null,null, null, TimeOut, null).value;
			else if(programId != '1-0252')			    
			    getElementsByClassName(document,"h2","hplussignupHead")[0].innerHTML = AjaxWrapper.GetLabel(1030,null,null,null, null, TimeOut, null).value;//'Bliv PLUSmedlem<br />og fÃ¥ adgang til alle fordele!';			    
			
			document.getElementById('plussignupSubhead').style.display = 'none';
		}
		else if(ret.value[0] == 0)
			location.href = location.href;
	}		
}

function ProceedPayementA(langCode,IPAdress, RootPath, nDibs,programId,sapCode,conditionMail,discItemId,discItemName,discPrice,anniversary)
{
	document.getElementById('CreatePlusMemberwait').style.display = "block";	  
	
	var txtemail = getElementsByClassName(document,"input","tbClass")[7];
	var txtPass = getElementsByClassName(document,"input","tbClass")[9];

	AjaxPro.timeoutPeriod = 60*1000;		
	var RetRes = AjaxWrapper.CheckMemberStatus(txtemail.value,txtPass.value,null,null,null, null, TimeOut, null);
	if(RetRes != null && RetRes.value[0] == 1)
	{
		AjaxPro.timeoutPeriod = 60*1000;
		var ret = AjaxWrapper.GetDetailsFromMemberObject("A",null,null,null, null, TimeOut, null);
		if(ret != null && ret.value != null && ret.value[0] != null)
		{
			if(ret.value[0] == 1)
			{
				AjaxPro.timeoutPeriod = 60*1000;
				var strRef = '';
				var nBusRel = 0; 	
				document.getElementById('pageSignupErrorMsg').style.display = "none";				
				AjaxWrapper.SignupPlusPayment(IPAdress, RootPath,nBusRel,strRef,bPlusMemOptn,programId,nDibs,sapCode,conditionMail,discItemId,discItemName,discPrice,anniversary,subscriptionId,PaymentACallBack,null,null, null, Timedout, null);
			}		
			else if(ret.value[0] == 0)
				location.href = ret.value[1];
		}	
	}
	else
	{
		document.getElementById('pageSignupErrorMsg').style.display = "block";		
		document.getElementById('CreatePlusMemberwait').style.display = "none";	  		
		
		if(RetRes.value[0] ==null || RetRes.value[0] ==  0) 
		{
			// UnKnown Error
			SignUpAjaxError(2019);			
		}     
		else if(RetRes.value[0] ==  2) 
		{
			// Email Already Exist
			SignUpAjaxError(2630);
		}     
		else if(RetRes.value[0] == 3) 
		{
			//A Member Inactive       
			document.getElementById('pageSignupErrorMsg').innerHTML = "<p>" + RetRes.value[1] + "</p>";
		}     
		else if(RetRes.value[0] == 4) 
		{
			//B Member Inactive       
			document.getElementById('pageSignupErrorMsg').innerHTML = "<p>" + RetRes.value[1] + "</p>";
		}
		else if(RetRes.value[0] == 5)
		{
			// already B member with correct e-mailid and passsword
			document.getElementById('pageSignupErrorMsg').innerHTML = "<p>" + RetRes.value[1] + "</p>";
		}     
		else if(RetRes.value[0] == 6)
		{
			// already A member with correct e-mailid and passsword
			document.getElementById('pageSignupErrorMsg').innerHTML = "<p>" + RetRes.value[1] + "</p>";
		}
		else
		{
			//CreateMember Error			
			SignUpAjaxError(2032);
		}		
	}
}
function PaymentACallBack(res)
{    
	if( res.value != null && res.value[0] == 1 )
	{
	    try{document.getElementById('CreatePlusMemberwait').style.display = "none";}catch(e){};	
		location.href = res.value[1];
		return false;	
	}
	else if( res.value != null && res.value[0] == 5 )
	{
		AjaxPro.timeoutPeriod = 60 * 1000;
		AjaxWrapper.BetalingSuccess(0, freeCB,null,null, null, TimeOut, null);
	}
	else
	{
		try{document.getElementById('CreatePlusMemberwait').style.display = "none";}catch(e){};	
		document.getElementById('pageSignupErrorMsg').style.display = "block";	
		//Send Error Mail		
		var err = "";
		if(res.error != null && res.error.Message != null)
			err = res.error.Message;
			
		if(res.value == null)
		{
			SignUpAjaxError(2019);// UnKnown Error
			AjaxPro.timeoutPeriod = 60 * 1000;
			AjaxWrapper.SendErrorMail("Plussignup ajax call fails", -1, err,null,null,null, null, TimeOut, null);
		}
		else if( res.value[0] == -1)
		{
		    SignUpAjaxError(2019);
		    if(res.value[1] != null && res.value[1] != "")
		        location.href = res.value[1]; 
		}		
		else if( res.value[0] == 2 )
		{
			SignUpAjaxError(2058);			
		}		  
		else if( res.value[0] == 3 )
		{
			SignUpAjaxError(2019);			
		}
		else if( res.value[0] == 0 || res.value[0] == 4)
		{
			SignUpAjaxError(2019);			
		}
		else if( res.value[0] == -999999)
		{
		    SignUpAjaxError(2058);		    
		}
		else if( res.value[0] == 999999)
		{
		    SignUpAjaxError(2058);
		}
	}	
}
function freeCB(ret)
{
	try{document.getElementById('CreatePlusMemberwait').style.display = "none";}catch(e){};	
	if(ret != null && ret.value != null && ret.value.length > 0)
    {
        if(ret.value[0] != null)
        {            
            if(ret.value[0] == "0")//session not null
            {
                if(ret.value[1] != null && ret.value[1] != "")
                {                    
                    //Show error msg
                    document.getElementById('pageSignupErrorMsg').style.display = "block";						
					document.getElementById('pageSignupErrorMsg').innerHTML = "<p>" + ret.value[1] + "</p>";					
					var err = "";
					if(ret.error != null && ret.error.Message != null)
						err = ret.error.Message;					
					AjaxPro.timeoutPeriod = 60 * 1000;
					AjaxWrapper.SendErrorMail("Plussignup (100% discount) ajax call fails", 0, err,null,null,null, null, TimeOut, null);
                }
                else if(ret.value[2] != null && ret.value[2] != "")
                {                    
                    location.href = ret.value[2];//receipt page
                }
            }
            else
                location.href = ret.value[0];
        }        
    }
}
function Timedout(ret){alert('Timed out');}
function HideWaitSymbol()
{
    try{document.getElementById('divOnlineErr').innerHTML = '';}catch(e){};
	try{document.getElementById('bsWait').style.display='none';}catch(e){};	
	try{document.getElementById('divOnline').style.display='';}catch(e){};	
	if(document.getElementById('hisLength').value == 0)
	{document.getElementById('hisLength').value = history.length;}
	else
	{
	    AjaxPro.timeoutPeriod = 60*1000;
	    var ret = AjaxWrapper.CheckReceiptData(null,null,null, null, TimeOut, null);
	    if(ret != null && ret.value[0] == true)
	    {
	        try{document.getElementById('divOnline').style.display='none';}catch(e){};
	        try{document.getElementById('bsWait').style.display='';}catch(e){};				
	        try{document.getElementById('divWaitMsg').style.display='none';}catch(e){};
	        try{document.getElementById('divOrderCreateMsg').style.display='';}catch(e){};
	        AjaxPro.timeoutPeriod = 60*1000;
		    AjaxWrapper.BetalingSuccess(2,BetalingSuccessCallBack,null,null, null, TimeOut, null);
	    }
	    else
	    {	        
	        history.forward();	        
	        try{document.getElementById('divOnline').style.display='none';}catch(e){};	    
	    }
	}
}
function BetalingSuccessCallBack(ret)
{
    try{document.getElementById('bsWait').style.display='none';}catch(e){};
    if(ret != null && ret.value != null && ret.value.length > 0)
    {
        if(ret.value[0] != null)
        {            
            if(ret.value[0] == "0")
            {
                if(ret.value[1] != null)
                {                    
                    if(ret.value[1] != "")
                    {
                        try{document.getElementById('divOnlineErr').innerHTML = ret.value[1];}catch(e){};
                    }
                }
            }
            else
                location.href = ret.value[0];
        }        
    }    
}
function RedirectToOnlinePayment()
{
    AjaxPro.timeoutPeriod = 60 * 1000;
    var strURL = AjaxWrapper.GetOnlinePaymentURL(null,null,null, null, TimeOut, null);      
    if(strURL != null && strURL.value != "")
        location.href = strURL.value;
}
function CheckReceiptData()
{
    AjaxPro.timeoutPeriod = 60*1000;
	AjaxWrapper.CheckReceiptData(CheckReceiptDataCB,null,null, null, TimeOut, null);	
}

function CheckReceiptDataCB(ret)
{
	if(ret != null && ret.value[0] == true)
	{
	    history.forward();
	    location.href = ret.value[1];
	}
}
function SendMemberSignupInvoice(lang,toMailAddress)
{
	var content =document.getElementById('MainContentDiv');	
	AjaxPro.timeoutPeriod = 60 * 1000;			
	AjaxWrapper.SendMemberSignupInvoice(content.innerHTML,toMailAddress,null,null,null, null, TimeOut, null);
}
function FillUpgradeMemberDetails()
{
	HideError();
	document.getElementById('pageSignupErrorMsg').style.display = "none";
	document.getElementById('plussignupSubhead').style.display = 'none';
	AjaxPro.timeoutPeriod = 60*1000;
	var ret = AjaxWrapper.GetDetailsFromMemberObject("U",null,null,null, null, TimeOut, null);
	if(ret != null && ret.value != null && ret.value[0] != null)
	{
		if(ret.value[0] == 1)
		{
			document.getElementById('pageSignupUpgrade').style.display = 'none';
			document.getElementById('pageSignupPlus').style.display = 'block';			
			getElementsByClassName(document,"input","tbClass")[2].value = ret.value[1];
			getElementsByClassName(document,"input","tbClass")[3].value = ret.value[2];
			getElementsByClassName(document,"input","tbClass")[7].value = ret.value[3];			
 			getElementsByClassName(document,"input","tbClass")[4].value = ret.value[6];
			getElementsByClassName(document,"input","tbClass")[5].value = ret.value[7];			
			getElementsByClassName(document,"input","tbClass")[6].value = ret.value[8];
			getElementsByClassName(document,"input","tbClass")[8].value = ret.value[10];
			getElementsByClassName(document,"input","tbClass")[9].value = ret.value[11];			
		}
		else if(ret.value[0] == 0)
			location.href = location.href;
	}	
}

function UpgradeLoginBoxClick(Type , LanguageId , sessionID , e)
{	
	if(e.which || event.keyCode)
	{
		if(e.which == 13 || event.keyCode == 13)
		{
			switch(Type)
			{
				case '0':
					ValidateUpgradeLogin(LanguageId , sessionID );
					return false;
					break;
				case '1':
					UpgradeSendPassToEmail(LanguageId);
					return false;
					break;
			}
		}
	}		
}
function ValidateUpgradeLogin(LanguageId,sessionID)
{		
	HideError();
	document.getElementById('pageSignupErrorMsg').style.display = "none";
	var TxtEmail = getElementsByClassName(document,"input","tbClass")[0];
	var TxtPass = getElementsByClassName(document,"input","tbClass")[1];	
	if(TxtEmail.value != "" && TxtPass.value != "")
	{
		if(IsValidEmail(TxtEmail.value))
		{			
			document.getElementById('loginWait').style.display = "block";
			AjaxPro.timeoutPeriod = 60*1000;
			AjaxWrapper.DoLogin(TxtEmail.value, TxtPass.value, LanguageId,GetUpgradeMemberDetailsCallBack,null,null, null, Timedout, null);
		}
		else
		{
		    SignUpError(0);
		}
	}
	else
	{
		if(TxtEmail.value == "")
		{
			SignUpError(0);
		}
		else if(!IsValidEmail(TxtEmail.value))
		{
			SignUpError(0);
		}
		if(TxtPass.value == "")
		{
			SignUpError(1);
		}
	}
}
function GetUpgradeMemberDetailsCallBack(ret)
{
	document.getElementById('loginWait').style.display = "none";
	if(ret.value[0] == 1 )
	{
	    window.location.href = window.location;
	}
	
	else 
	{
		document.getElementById('pageSignupErrorMsg').style.display = "block";
		if( ret.value[0] == -1 )
		{
		    //Wrong Password
			SignUpAjaxError(2035);
		}		
		else if( ret.value[0] == 2 )
		{			
			//If Member Inactive
			SignUpAjaxError(2014);
		}		
		else
		{
			//If Email is not found in DB	
			SignUpAjaxError(2349);
		}
	}
}

function UpgradePayement(langCode,IPAdress, RootPath, bDibs,programId,sapCode,CountryCode,conditionMail,discItemId,discItemName,discPrice,anniversary)
{
	HideError();
	if(document.getElementById("oneYear").checked)
		bPlusMemOptn = 1;
	else if(document.getElementById("halfYear").checked)
		bPlusMemOptn = 2;	

	var txtFirstName = getElementsByClassName(document,"input","tbClass")[2];
	var txtLastName = getElementsByClassName(document,"input","tbClass")[3];
	var txtAddress = getElementsByClassName(document,"input","tbClass")[4];
	var txtPostNo = getElementsByClassName(document,"input","tbClass")[5];
	var txtPhone = getElementsByClassName(document,"input","tbClass")[8];
	var txtMobile = getElementsByClassName(document,"input","tbClass")[9];
	var txtCity = getElementsByClassName(document,"input","tbClass")[6];
	
	var validFirstName = validateIsEmpty(txtFirstName);
	if(validFirstName)
		validFirstName = IsValidString(txtFirstName.value);	
	
	var validLastName = validateIsEmpty(txtLastName);
	if(validLastName)
		validLastName = IsValidString(txtLastName.value);	

	var validAddress = validateIsEmpty(txtAddress);	

	var validPostNo = validateIsEmpty(txtPostNo);
	/*if(validPostNo)
		validPostNo = IsValidPostNumber(txtPostNo.value,CountryCode);	*/

		
	var validCity = validateIsEmpty(txtCity);
	if(validCity)
		validCity = IsValidString(txtCity.value);	

	var validPhone = validateIsEmpty(txtPhone);
	if(validPhone)
		validPhone = IsValidPhone(txtPhone.value,CountryCode);	

	var validMobile = true;
	var validMobileNumber = validateIsEmpty(txtMobile);
	if(validMobileNumber)
		validMobile = IsValidPhone(txtMobile.value,CountryCode);	
	
	var validCond = false;
	var NewsLetter = false;
	var trCondition = getElementsByClassName(document,"div","conditionsDiv")[0];		
	if(trCondition != null)
	{
		var chkCond = document.getElementById("pageSignupPlusTermsChk");
	    var chkNews = document.getElementById("pageSignupPlusNewsletterChk");
		
		validCond = validateCheckBox(chkCond);
		NewsLetter = validateCheckBox(chkNews);			
	}
		
	if(validFirstName && validLastName && validAddress && validPostNo && validCity && validPhone && validMobile && (trCondition == null || (trCondition != null && validCond)))
	{	
		document.getElementById('CreatePlusMemberwait').style.display = "block";
		AjaxPro.timeoutPeriod = 60*1000;
		AjaxWrapper.UpgradePlusMember(txtFirstName.value, txtLastName.value, txtAddress.value,txtPostNo.value,txtCity.value,txtPhone.value,txtMobile.value,bPlusMemOptn,langCode,IPAdress, RootPath,programId,bDibs,sapCode,CountryCode,NewsLetter,conditionMail,discItemId,discItemName,discPrice,anniversary,UpgradePlusMemberCallBack,null,null, null, TimeOut, null);
	}
	else
	{
	    document.getElementById('CreatePlusMemberwait').style.display = "none";		
		if(!validFirstName)
		{
			SignUpError(2);
		}
		if(!validLastName)
		{
		    SignUpError(3);
		}
		if(!validAddress)
		{
			SignUpError(4);
		}
		if(!validPostNo)
		{
			SignUpError(5);
		}
		if(!validCity)
		{		
			SignUpError(6);
		}	
		if(!validPhone)
		{
			SignUpError(8);
		}
		if(!validMobile)
		{
			SignUpError(9);
		}		
		if(trCondition != null && !validCond)
		{
			SignUpError(10);
		}
	}
}
function UpgradePlusMemberCallBack(res)
{
	document.getElementById('CreatePlusMemberwait').style.display = "none";
	if(res.value != null && res.value.length > 0 && res.value[0] == "paymenttypelayer")
	{
	    if(res.value[1] == 1)//BS-BS
	    {
	        ShowPaymentLayer(2);
	         if(res.value.length >= 2)
	            document.getElementById('spnBS_BS_Brel').innerHTML = res.value[2];
	        if(res.value.length >= 3)
	            document.getElementById('spnBS_BS_Date').innerHTML = res.value[3];
	    }
	    else //BS-DIBS
	    {
	        ShowPaymentLayer(1);
	        if(res.value.length >= 2)
	            document.getElementById('spnBS_DIBS_Brel').innerHTML = res.value[2];
	        if(res.value.length >= 3)
	            document.getElementById('spnBS_DIBS_Date').innerHTML = res.value[3];
	        
	    }
	}
	else if( res.value != null && res.value[0] == 1 )
	{
		location.href = res.value[1];	
		return false;	
	}
	else if( res.value != null && res.value[0] == 5 )
	{
		AjaxPro.timeoutPeriod = 60 * 1000;
		AjaxWrapper.BetalingSuccess(0, freeCB,null,null, null, TimeOut, null);
	}
	else
	{
		try{document.getElementById('CreatePlusMemberwait').style.display = "none";}catch(e){};	
		document.getElementById('pageSignupErrorMsg').style.display = "block";	
		//Send Error Mail		
		var err = "";
		if(res.error != null && res.error.Message != null)
			err = res.error.Message;
			
		if(res.value == null)
		{
			SignUpAjaxError(2019);// UnKnown Error
			AjaxPro.timeoutPeriod = 60 * 1000;
			AjaxWrapper.SendErrorMail("UpgradetoPlusMember ajax call fails", -1, err,null,null,null, null, TimeOut, null);
		}
		else if( res.value[0] == -1)
		{
		    SignUpAjaxError(2019);
		    if(res.value[1] != null && res.value[1] != "")
		        location.href = res.value[1]; 
		}		
		else if( res.value[0] == 2 )
		{		    
			SignUpAjaxError(2058);			
		}		  
		else if( res.value[0] == 3 )
		{
			SignUpAjaxError(2019);			
		}
		else if( res.value[0] == 0 || res.value[0] == 4)
		{
			SignUpAjaxError(2019);			
		}
		else if( res.value[0] == -999999)
		{
		    SignUpAjaxError(2058);				    
		}
		else if( res.value[0] == 999999)
		{
		    SignUpAjaxError(2058);		    
		}
	}		
}
var cat;
function showForm(category)
{
	cat = category;
	document.getElementById('contact').style.display = "none";
	document.getElementById('confirm1').style.display = "none";
	document.getElementById('confirm2').style.display = "none";
	document.getElementById('contactForm').style.display = "block";
}
function validateContactForm()
{
	var txtboxes = getElementsByClassName(document,"input","textBox");
	ClearFormErrors(txtboxes);	
	var validName = validateIsEmpty(txtboxes[0]);
	if(validName)
		validName = IsValidString(txtboxes[0].value);	
		
	var validEmail = validateIsEmpty(txtboxes[1]);
	if(validEmail)
		validEmail = IsValidEmail(txtboxes[1].value);
		
	var validPhone = validateIsEmpty(txtboxes[2]);	
	
	var txtboxesMulti = getElementsByClassName(document,"textArea","textBoxMulti");
	var validMessage = validateIsEmpty(txtboxesMulti[0]);
	
	if(validName && validEmail && validPhone && validMessage)
	{
		AjaxPro.timeoutPeriod = 60 * 1000;
		AjaxWrapper.SendContactMail(txtboxes[0].value,txtboxes[1].value,txtboxes[2].value,txtboxesMulti[0].value,cat,false,SCMCallBack,null,null, null, TimeOut, null);
	}
	else
	{
		if(!validName)			
			txtboxes[0].style.border = '1px dotted red';
			
		if(!validEmail)
			txtboxes[1].style.border = '1px dotted red';
		
		if(!validPhone)
			txtboxes[2].style.border = '1px dotted red';
			
		if(!validMessage)
			txtboxesMulti[0].style.border = '1px dotted red';
	}
	
}
function SCMCallBack(ret)
{
    document.getElementById('contact').style.display = "none";
    document.getElementById('contactForm').style.display = "none";
    document.getElementById('confirm2').style.display = "none";
    document.getElementById('confirm1').style.display = "block";	
	//setTimeout("GoToHome('"+ ret.value +"')",10000);
}
function sendCMail()
{
	var txtboxes = getElementsByClassName(document,"input","textBox");
	var txtboxesMulti = getElementsByClassName(document,"textArea","textBoxMulti");
	AjaxPro.timeoutPeriod = 60 * 1000;
	AjaxWrapper.SendContactMail(txtboxes[0].value,txtboxes[1].value,txtboxes[2].value,txtboxesMulti[0].value,cat,true,SCMAgainCallBack,null,null, null, TimeOut, null);
}
function SCMAgainCallBack(ret)
{
    document.getElementById('contact').style.display = "none";
    document.getElementById('contactForm').style.display = "none";
    document.getElementById('confirm1').style.display = "none";
    document.getElementById('confirm2').style.display = "block";
	setTimeout("GoToHome('"+ ret.value +"')",10000);
}
function GoToHome(url)
{location.href = url;}
function ClearFormErrors(txtboxes)
{
	for(var i=0;i<txtboxes.length-1;i++)
	{
		txtboxes[i].style.border = '1px solid #CED3D6';
	}		
	var txtboxesMulti = getElementsByClassName(document,"textArea","textBoxMulti");
	txtboxesMulti[0].style.border = '1px solid #CED3D6';
	
}
function updateWelcomePackage(recId)
{
    AjaxPro.timeoutPeriod = 60 * 1000;
    AjaxWrapper.updateWelcomePackage(recId,null,null,null, null, TimeOut, null);
}
function welcomePackage(recId,text,url) {
	if (confirm(text)) {
		updateWelcomePackage(recId);
		location.href=url;
		//return true;
	}
	else {
		return false;
	}
}
function welcomePackageNew(recId,text,url) {
	if (confirm(text)) {
		updateWelcomePackage(recId);
		window.open(url);
		location.href=location.href;
		//return true;
	}
	else {
		return false;
	}
}
function setJubiBg(lang)
{
    var txtboxes = getElementsByClassName(document,"input","tbClass"); 
    var atags = getElementsByClassName(document,"a","btn");
    var tbColor = "#c29595";var linkColor = "#dd4644";
    if(lang == "sv")
        {tbColor = "#95a3c2";linkColor = "#447add";}
    
    for(var i=0;i<txtboxes.length;i++)
    {
        txtboxes[i].style.border = '1px solid ' + tbColor;
    }
    for(var i=0;i<atags.length;i++)
    {
        atags[i].style.color = linkColor;
    }    
    try{getElementsByClassName(document,"h2","hplussignupHead")[0].style.color = "#fff";
    document.getElementById('pplussignupSubhead').style.color = "#fff";
    getElementsByClassName(document,"select","ddlClassCountry")[0].style.border = '1px solid ' + tbColor;}catch(e){}
}
function random_imglink(){
  var myimages=new Array();
  //specify random images
  myimages[1]="http://vielskerferie.dk/media/776539/ski_dtf_vef_dk.jpg";
  myimages[2]="http://vielskerferie.dk/media/492538/dtf-travel.jpg";
  myimages[3]="http://vielskerferie.dk/media/492543/nemrejse.jpg";

  //specify corresponding links below
  var imagelinks=new Array();
  imagelinks[1]="http://www.dtf-travel.dk/tilbud/skiferie?utm_souce=vef&utm_medium=banner";
  imagelinks[2]="http://www.dtf-travel.dk/default.aspx?siteid=255&utm_source=VEF&utm_medium=banner&utm_term=koebenhavn&utm_campaign=koebenhavn";
  imagelinks[3]="http://www.nemrejser.dk";

  var imagetitle=new Array();
  imagetitle[1] = "DTF travel - Skisæson 2011/2012";
  imagetitle[2] = "DTF travel";
  imagetitle[3] = "Nem rejse";

  var ry=Math.floor(Math.random()*myimages.length);

  if (ry==0)
  {ry=1;}
  
  document.write('<a target=_blank onClick='+'"'+'javascript:pageTracker._trackPageview('+'\''+'/vpv/bannere/Randombanner/'+imagetitle[ry]+'/'+'\''+');" href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>');
}
ViElskerFerie = {
    randomDyk: {
        'dk': [
            [
                'http://vielskerferie.dk/media/488249/vidste-du-chat-dk.png',
                'http://vielskerferie.dk/min-forside/selvbetjening/kontakt-os.aspx',
                'Chat med kundeservice'
            ],
            [
                'http://vielskerferie.dk/media/465013/vidste-du-fordele-og-rabatter-dk.png',
                'http://vielskerferie.dk/tilbud-og-rabatter.aspx',
                'Fordele og rabatter'
            ],
            [
                'http://vielskerferie.dk/media/465043/vidste-du-last-minute-dk.jpg',
                'http://vielskerferie.dk/last-minute.aspx',
                'Last Minute'
            ]
        ],
        'se': [
            [
                'http://vielskerferie.dk/media/465023/vidste-du-fordele-se.png',
                'http://vialskarresor.se/erbjudanden.aspx',
                'FÃ¶rmÃ¥ner och rabatter'
            ],
            [
                'http://vielskerferie.dk/media/465053/vidste-du-last-minute-se.png',
                'http://vialskarresor.se/sista-minuten.aspx',
                'Sista Minuten'
            ]
        ],
        'no': [
            [
                'http://vielskerferie.dk/media/465018/vidste-du-fordele-no.png',
                'http://vielskerferie.no/tilbud-og-rabatter.aspx',
                'Fordeler og rabatter'
            ],
            [
                'http://vielskerferie.dk/media/465048/vidste-du-last-minute-no.png',
                'http://vielskerferie.no/last-minute.aspx',
                'Last Minute'
            ]
        ]
    },

    DidYouKnow: function (language) {
        var randomDyk = this.randomDyk[language];
        if (!randomDyk) {
            alert('Could not find any "Did you know" in that language');
            return;
        }
        var randomInt = Math.floor(Math.random() * randomDyk.length);
        document.write('<a href="' + randomDyk[randomInt][1] + '" onclick="javascript:pageTracker._trackPageview(\'/vpv/bannere/Randombanner/' + randomDyk[randomInt][0] + '/);" target="_self" title="' + randomDyk[randomInt][2] + '"><img src="' + randomDyk[randomInt][0] + '" border="0"></a>');
    }
};
function ShowBilkaPop()
{
    document.getElementById('divMask').className='popupMask';
    document.getElementById('PopUp_Img_Div').style.display='block';    
    var DivTag = document.getElementById('PopUp_Img_Div');		
	DivTag.style.display='block';
	DivTag.style.position = 'absolute';
	DivTag.style.left = '100px';
	DivTag.style.top = '10px';
}
function validateBilka()
{
    document.getElementById('bilkaWait').style.display = "block";
    var txtboxes = getElementsByClassName(document,"input","layerTxt");
    var storeName = getElementsByClassName(document,"select","ddllayer");       
    ClearBilkaErrors(storeName[0], txtboxes);
    
    var validStore = validateDropDown(storeName[0]);
	if(validStore)
		validStore = IsValidString(storeName[0].value);    
    var validDate = validateIsEmpty(txtboxes[0]);	
    if(validDate)
        validDate = txtboxes[0].value != "dd-mm-åååå" ? true : false;
    var validReceipt = validateIsEmpty(txtboxes[1]);
    
    if(validStore && validDate && validReceipt)   
    {
        var selIdx = storeName[0].selectedIndex;     
		storeName = storeName[0].options[selIdx].value;		
        AjaxPro.timeoutPeriod = 60*1000;
	    AjaxWrapper.InsertBilkaOrder(storeName,txtboxes[0].value, txtboxes[1].value, BilkaCB,null,null, null, Timedout, null);        
    }
    else
    {
        document.getElementById('bilkaWait').style.display = "none";
        if(!validStore)			
			storeName[0].style.border = '2px dotted red';
		if(!validDate)			
			txtboxes[0].style.border = '2px dotted red';
		if(!validReceipt)			
			txtboxes[1].style.border = '2px dotted red';
    }    
}
function BilkaCB(res)
{
    document.getElementById('bilkaWait').style.display = "none";
    if( res.value != null && res.value == 1 )
    {
        document.getElementById('divMask').className='';
        document.getElementById('PopUp_Img_Div').style.display='none';     
    }
    else if(res != null) 
    {
        if(res.value == -1)
        {
            alert('Ugyldig købtdato.');
            txtboxes[0].style.border = '1px solid #CED3D6';
        }
        else if(res.value == -2)
            alert('Du har allerede aktiveret dit købte PLUSmedlemskab.');
    }
}
function ClearBilkaErrors(dd,txtboxes)
{
	for(var i=0;i<txtboxes.length;i++)
	{
		txtboxes[i].style.border = '1px solid #CED3D6';
	}		
	dd.style.border = '1px solid #CED3D6';
}
function ShowPaymentLayer(n)
{
    switch(n)
    {
        case 1:
        ShowPaymentMask();
        document.getElementById('divPBS_PBS').style.display = 'none';
        var c1 = document.getElementById('divPBS_CreditCard');        
        c1.style.display = 'block';
        c1.style.top ='100px';c1.style.left='100px';
        c1.style.zIndex = 1000;      
        break;
        case 2:
        ShowPaymentMask();
        document.getElementById('divPBS_CreditCard').style.display = 'none';
        var c1 = document.getElementById('divPBS_PBS');        
        c1.style.display = 'block';
        c1.style.top ='100px';c1.style.left='100px';
        c1.style.zIndex = 1000;  
             
        break;
    }
}
function ClosePaymentLayer()
{
    document.getElementById('divPBS_PBS').style.display = 'none';
    document.getElementById('divPBS_CreditCard').style.display = 'none';
    HidePaymentLayer();  
}
function ShowPaymentMask()
{
    var ctrlLock = document.getElementById('divLayerMask');
    ctrlLock.style.width = $(document).width()+'px';
    ctrlLock.style.height = $(document).height()+'px';
    ctrlLock.style.display = 'block';
}
function HidePaymentLayer()
{
    var ctrlLock = document.getElementById('divLayerMask');
    ctrlLock.style.width = '0px';
    ctrlLock.style.height = '0px';
    ctrlLock.style.display = 'none';
}
function GoToPage(url)
{
    if(url != null && url != "")
    {location.href = url;}
}
function CheckedChange(type)
{
     if(type == 5)
        getElementsByClassName(document,"textarea","CM_txtClass")[0].style.display ="inline";
    else
    {
        for (var i = 1 ; i<=4; i++)
        { 
            if(i == type) 
            {
                getElementsByClassName(document,"span","CM_Computerprob")[i-1].style.visibility ="visible";
                getElementsByClassName(document,"textarea","CM_txtClass")[0].style.display ="none"; 
            }
            else 
            {
                getElementsByClassName(document,"span","CM_Computerprob")[i-1].style.visibility ="hidden";
                getElementsByClassName(document,"textarea","CM_txtClass")[0].style.display ="none";
            }
        }
    }
}
function ShowWarning()
{
    var ctrlLock = document.getElementById('divMCancelLayer');
    ctrlLock.style.width = $(document).width()+'px';
    ctrlLock.style.height = $(document).height()+'px';
    ctrlLock.style.display = 'block';
    var c1 = document.getElementById('MCancelWarning');        
    c1.style.display = 'block';
    c1.style.top ='100px';
    c1.style.zIndex = 1000; 
}
function HideWarning()
{
    var ctrlLock = document.getElementById('divMCancelLayer');
    ctrlLock.style.width = '0px';
    ctrlLock.style.height = '0px';
    ctrlLock.style.display = 'none';
    document.getElementById('MCancelWarning').style.display = 'none';
}
/*New Edit profile*/
function InitECJQCombos()
{
    $(function () {
        var combos = getElementsByClassName(document,"select","csECJQCombo");
        if(combos != null && combos.length > 0)
        {
            var ctrlwidth;
            for(var i = 0; i < combos.length; i++)
            {
                ctrlwidth = $(combos[i]).width();
                $(combos[i]).selectmenu({ style: 'dropdown', maxHeight: 300, width: ctrlwidth, menuWidth: ctrlwidth - 5 });				
            }
        }
    });
}
function RefrsehJQCombo(ctrl)
{
    if(ctrl != null)
    {
        var ctrlwidth = $(ctrl).width();
        $(ctrl).selectmenu("destroy");
        $(ctrl).selectmenu({ style: 'dropdown', maxHeight: 300, width: ctrlwidth, menuWidth: ctrlwidth - 5 });		
    }
}

function validateEditProfileInput(ctrlid,type,validmsg,invalidmsg,rootpath)
{
    HideError();
    var bRet = true;
    var ctrl = document.getElementById(ctrlid);
    if(ctrl != null)
    {
        var refCtrl = ctrl;
        switch(type)
        {
            case 'string':
            {
                bRet = validateIsEmpty(ctrl);
	            if(bRet)
		            bRet = IsValidString(ctrl.value);	
		        break;
            }
            case 'an':
            {
                bRet = validateIsEmpty(ctrl);	            
		        break;
            }
            case 'phone':
            {
                var DropDownNational = getElementsByClassName(document,"select","ddlClassCountry")[0];   
                var validNational   = validateDropDown(DropDownNational);       
                
                if(validNational)
                {
	                bRet = validateIsEmpty(ctrl);
	                if(bRet)
		                bRet = IsValidPhone(ctrl.value,DropDownNational.value);	
	            }		
	            else
	            {
	                bRet = false;
	                refCtrl = DropDownNational;
	                AjaxPro.timeoutPeriod = 60 * 1000;		    
	                invalidmsg = AjaxWrapper.GetLabel(1208,null,null,null, null, TimeOut, null).value;
	            }
                
		        break;
            }
            case 'mobile':
            {
                var DropDownNational = getElementsByClassName(document,"select","ddlClassCountry")[0];   
                var validNational   = validateDropDown(DropDownNational);       
                
                if(validNational)
                {	                
                    ClearChildErrControls(DropDownNational);	
	                if(validateIsEmpty(ctrl))
		                bRet = IsValidPhone(ctrl.value,DropDownNational.value);	
		            else
		            {
		                ClearChildErrControls(refCtrl);   
		                return;
		             }
	            }		
	            else
	            {
	                bRet = false;
	                refCtrl = DropDownNational;	    
	                AjaxPro.timeoutPeriod = 60 * 1000;		    
	                invalidmsg = AjaxWrapper.GetLabel(1208,null,null,null, null, TimeOut, null).value;
	            }
                
		        break;
            }
            case 'postcode':
            {
                var DropDownNational = getElementsByClassName(document,"select","ddlClassCountry")[0];   
                var validNational   = validateDropDown(DropDownNational);       
                
                if(validNational)
                {
                    ClearChildErrControls(DropDownNational);
	                bRet = validateIsEmpty(ctrl);
	                /*if(bRet)
	                {			
		                bRet = IsValidPostNumber(ctrl.value,DropDownNational.value);		
	                }*/
	            }		
	            else
	            {
	                bRet = false;
	                refCtrl = DropDownNational;
	                AjaxPro.timeoutPeriod = 60 * 1000;		    
	                invalidmsg = AjaxWrapper.GetLabel(1208,null,null,null, null, TimeOut, null).value;
	            }
		        break;
            }
            case 'email':
                bRet = validateIsEmpty(ctrl);
	            if(bRet)
		            bRet = IsValidEmail(ctrl.value);	
		        break;
            default:
                bRet = validateIsEmpty(ctrl);
                break;
                
        }
        
        var newErrDiv;
        
        if(refCtrl.parentNode)
            newErrDiv = getElementsByClassName(refCtrl.parentNode,"div","csEPErrDiv")[0];
        
        if(newErrDiv == null)
        {
            var ErrDivColl = getElementsByClassName(document,"div","csDefEPErrDiv");
            if(ErrDivColl != null && ErrDivColl.length > 0)
            {
                newErrDiv = ErrDivColl[0].cloneNode(true);
                newErrDiv.className = "csEPErrDiv";
            }
        }
        if(!bRet)
        {
            if(newErrDiv != null)
            {
                newErrDiv.getElementsByTagName("img")[0].src = rootpath + "/Images/EditProfileNew/wrong.png";
                newErrDiv.getElementsByTagName("span")[0].innerHTML = invalidmsg;
            }
        }
        else 
        {
            if(newErrDiv != null)
            {
                newErrDiv.getElementsByTagName("img")[0].src = rootpath + "/Images/EditProfileNew/correct.png";
                newErrDiv.getElementsByTagName("span")[0].innerHTML = validmsg;            
            }
        }
        ClearChildErrControls(refCtrl);        
        var Parent = refCtrl.parentNode; 
        if(Parent != null)
        {
            Parent.appendChild(newErrDiv);
        }
        else
            document.getElementById('divErrContainer').appendChild(newErrDiv);
        
        if(refCtrl.tagName.toLowerCase() == "select")
            refCtrl = refCtrl.nextSibling;
        
        positionValidityMsg(newErrDiv,refCtrl,bRet);
    }
}

function ClearChildErrControls(ctrl)
{
    if(ctrl != null && ctrl.parentNode)
    {
        var errDivs = getElementsByClassName(ctrl.parentNode,"div","csEPErrDiv");
        for(var i =0;i<errDivs.length;i++)
            ctrl.parentNode.removeChild(errDivs[0]);
    }
}

function positionValidityMsg(ctrl, refCtrl, bClose )
{
    var pos = $(refCtrl).position();
    var refPos = getPosition(getElementsByClassName(document,'div','csEPMain')[0]); 	
    if(pos != null)
    {
        ctrl.style.display = 'block';
        ctrl.style.left = ((pos.left + $(refCtrl).width() - 10))  + 'px';
	ctrl.style.top = pos.top - 15 + 'px';
        if(bClose)
            setTimeout(function() {ClearValidityMsg(ctrl,refCtrl)},3000);
    }       
}

function ClearValidityMsg(ctrl,refCtrl)
{
    try
    {
        if(ctrl != null)
        {
            var Parent = refCtrl.parentNode; //document.getElementById('divErrContainer');
            if(Parent != null )
            {
                Parent.removeChild(ctrl);
            }
        }
    }
    catch(e){}
}

function ClearAllValidityMsgs()
{
    var Containers = getElementsByClassName(document,"div","csEPErrDiv");    
    for(nIndx=0;nIndx<Containers.length;nIndx++)
    {Containers[nIndx].style.display = "none";}
}
function validateEditEmail()
{
    HideError();
    ClearAllValidityMsgs();
   // email
   var txtEmailBox = getElementsByClassName(document,"input","csCurEmailBox")[0];         
   var validEmail = validateIsEmpty(txtEmailBox);    

   //New email
   var txtNEmailBox = getElementsByClassName(document,"input","csEmailBox")[0];         
   var validNEmail = validateIsEmpty(txtNEmailBox);    
   
   //Retype New email
   var txtRNEmailBox = getElementsByClassName(document,"input","csRepEmailBox")[0];         
   var validRNEmail = validateIsEmpty(txtRNEmailBox);    
   
   var validCurrentEmail = validateEmail(txtEmailBox,oldMemberEmail);
   var validCompareEmail = validateIsEqual(txtNEmailBox,txtRNEmailBox);      
   
   bPageValidate = false;   
   if( validEmail && validNEmail && validRNEmail && validCurrentEmail && validCompareEmail )
   {
		bPageValidate = true;  	
		AjaxWrapper.FillMemberEmail(txtNEmailBox.value);
		AjaxPro.timeoutPeriod = 60*1000;		
		AjaxWrapper.ChangeMemberProfile(ValidateSaveEditProfileCallBack);				
   }		
   else
   {
		if(bPageValidate == false)
		{
			scrollTo(0,100);
			if( !validEmail)
			{
			    positionValidityMsg(getElementsByClassName(document,"div","csEPEmailErr")[0],txtEmailBox ,false);
			}
			if( !validNEmail ) //new Email
			{     
				positionValidityMsg(getElementsByClassName(document,"div","csEPNewEmailErr")[0],txtNEmailBox,false);
			}   
			if( !validRNEmail ) //Repeat Email
			{     
				positionValidityMsg(getElementsByClassName(document,"div","csEPRepEmailErr")[0],txtRNEmailBox,false);
			}    
			if(validEmail && !validCurrentEmail)
			{
				positionValidityMsg(getElementsByClassName(document,"div","csOldEmailErr")[0],txtEmailBox,false);
			}
			if(validNEmail && validRNEmail && !validCompareEmail)
			{
			    positionValidityMsg(getElementsByClassName(document,"div","csInvRepEmailErr")[0],txtRNEmailBox,false);
			}
		}
	}    
}
//GroupOn
function initGroupon(defText)
{
    defkodetxt = defText;
    $(".csGrponBox").addClass("csDefTxt");
}

function validateGroupOn(Mode)
{
    var txtCtrl;
    txtCtrl = $(".csGrponBox")[Mode];
    if(txtCtrl != null)
    {
        if(txtCtrl.value == "" || txtCtrl.value == defkodetxt )
        {
            txtCtrl.value = defkodetxt;
            txtCtrl.className = "csGrponBox csErrTxt";
        }
        else
        {
            AjaxPro.timeoutPeriod = 60 * 1000;
            AjaxWrapper.CheckGrouponCode(txtCtrl.value,Mode,GrouponCodeCB,null,null,null,TimeOut,null);
        }
    }
}
function GrouponCodeCB(ret)
{
    if(ret != null && ret.value != null && ret.value.length > 1)
    {
        if(ret.value[1] == "1")
        {
            window.location.href = ret.value[2];
        }
        else
        {
            var txtInx;
            if(ret.value[0] != null)
            {
                txtInx = ret.value[0];
                $(".csGrponBox")[txtInx].value = ret.value[2];   
                $(".csGrponBox")[txtInx].className = "csGrponBox csErrTxt";            
            }
        }
    }
}
function PrepareGrouponText(objSender, strText , refClassName)
{
	if(objSender.value == strText || objSender.className.indexOf('csErrTxt') > -1)
	{
		objSender.value = "";
		objSender.className = refClassName + " csNormalTxt";
	}
	else{
		if(objSender.value == "" )
		{
			objSender.value = strText;
			objSender.className = refClassName + " csDefTxt";
		}
		else
		{
			objSender.value = objSender.value;
			objSender.className = refClassName + " csNormalTxt";
		}
	}
}
function ShowGrpLayer(Mode)
{
    $("#divGrponLayer").dialog({dialogClass: 'no-header', width:(Mode == 0 ? 420 : 453 ), modal: true, zIndex: 100, closeOnEscape: false}).show();
    document.getElementById('divGrpRegisterLayer').style.display = (Mode == 0 ? "block" : "none");
    document.getElementById('divGrpUpgradeLayer').style.display = (Mode == 1 ? "block" : "none");
    document.getElementById('divGrpRegDealLayer').style.display = (Mode == 2 ? "block" : "none");
    document.getElementById('divTele2UpgDealLayer').style.display = (Mode == 3 ? "block" : "none");
}
function HideGrpLayer()
{
    $("#divGrponLayer").dialog("destroy");
    $(".csGrponBox").removeClass().addClass("csGrponBox csDefTxt");
    $(".csGrponBox").val(function(i,value){return defkodetxt;});
}
function positionGrpLayer()
{
    var divGrpLyr = document.getElementById('divGrponLayer');    
    if(divGrpLyr!=null)
    {   
        var clientX = (document.getElementById('divGrponMask').clientWidth - divGrpLyr.clientWidth) / 2 ;
        var clientY = 100;  
        divGrpLyr.style.top = clientY +'px';             
        divGrpLyr.style.left = clientX  +'px';        
        divGrpLyr.style.position= 'absolute';
        scrollTo(clientX,clientY);
    }
}
/*login popup Start*/
function ClearMReqLoginErr()
{
	$('.csMReq_Err').hide();
}
function GoToForgetPwd()
{		
	ClearMReqLoginErr();		
	$('#divMReq_Step1').hide();
	$('#divMReq_Step2').show();
	$('#divMReq_Step3').hide();	
	$('.csMReqTxtBox')[1].value = $('.csMReqTxtBox')[0].value;
}
function GoBackToLogin()
{
	ClearMReqLoginErr();	
	$('#divMReq_Step1').show();
	$('#divMReq_Step2').hide();
	$('#divMReq_Step3').hide();
	$('.csMReqTxtBox')[1].value = "";	
}	

function DoMReqLoginBoxClick(Type , LanguageId ,  e)
{	
    try{
	    if(e.which || event.keyCode)
	    {
		    if(e.which == 13 || event.keyCode == 13)
		    {
			    switch(Type)
			    {
				    case '0':
					    ValidateMReqLogin(LanguageId);
					    return false;
					    break;
				    case '1':
					    MReqSendPassToEmail(LanguageId);
					    return false;
					    break;
			    }
		    }
	    }
	}catch(e){}
}	
function MReqSendPassToEmail(languageId)
{	
	ClearMReqLoginErr();
	var strEmail="";	
	var txtFPwdEmail = $('.csMReqTxtBox')[1];	
	if (txtFPwdEmail != null && txtFPwdEmail.value != "" )
	{
		strEmail = txtFPwdEmail.value;
		if(IsEmailValid(strEmail))
		{
			//If the entered Email id is correct
			AjaxPro.timeoutPeriod = 60 * 1000;					
			var ret = AjaxWrapper.SendPassword(strEmail, languageId,null,null,null, null, TimeOut, null);
			if(ret.value == 1) // password send
			{
			    $('#divMReq_Step1').hide();
	            $('#divMReq_Step2').hide();
	            $('#divMReq_Step3').show();
	            $('#divMReq_SuccessEmail').html(strEmail);
			}
			else if( ret.value == 2) // Error - Member withdrawn
			{$('#divMReq_FPwd_InvalidEmail').show();}
			else if( ret.value == 3) // Error - Member Inactive
			{$('#divMReq_FPwd_WrongParamter').show();}
			else if( ret.value == -1)// Error - Wrong Param
			{$('#divMReq_FPwd_InvalidKey').show();}
			else if( ret.value == -2)// Error - Member not found
			{$('#divMReq_FPwd_InvalidEmail').show();}
			else // Error - Wrong param
			{$('#divMReq_FPwd_WrongParamter').show();}
		}
		else
		{$('#divMReq_FPwd_InvalidEmail').show();}		
	}
	else
	{$('#divMReq_FPwd_EnterEmail').show();}		
}
function toggle_Mreq_Rem_ChkBox(ctrl)
{
     if (ctrl != null) {
        if (ctrl.getAttribute('value') == '0') {
            ctrl.src = '/Images/MReqLogin/Chkbox_tick.png';
            ctrl.setAttribute('value', '1');
        }
        else {
            ctrl.src = '/Images/MReqLogin/Chkbox.png';
            ctrl.setAttribute('value', '0');
        }
    }   
}
function ValidateMReqLogin(LanguageId)
{
	ClearMReqLoginErr();
	var TxtControls = $('.csMemReqLogin .csMReqTxtBox');// getElementsByClassName(document,"input","LoginBox");
	var TxtEmail = (TxtControls[0] != null)? TxtControls[0]:null;
	var TxtPass = $('.csMemReqLogin .csPWBox')[0];
	if(TxtEmail != null && TxtPass != null)
	{
		if(TxtEmail.value != "" && TxtPass.value != "")
		{
			if(IsEmailValid(TxtEmail.value))
			{
				ClearMReqLoginErr();			
				$('#divMReqWait').show();
				AjaxPro.timeoutPeriod = 60*1000;
				AjaxWrapper.DoLogin(TxtEmail.value, TxtPass.value, LanguageId,MReqLoginCallBack,null,null, null, LoginTimeout, null);
			}
			else
			{
				$('#divMReq_InvalidEmail').show();
			}
		}
		else
		{		
			if(TxtEmail.value == "" || !IsEmailValid(TxtEmail.value))
				$('#divMReq_InvalidEmail').show();
			else if(TxtPass.value == "")
				$('#divMReq_EnterPwd').show();
		}
	}
}
function MReqLoginCallBack(ret)
{	
	$('#divMReqWait').hide();
	ClearMReqLoginErr();	
	if(ret.value[0] == 1 )
	{			
		if(document.getElementById('imgMReqRemPwd').getAttribute('value') == '1')
		{   
			var strEmail = $('.csMemReqLogin .csMReqTxtBox')[0].value;
			var strPassword = $('.csMemReqLogin .csPWBox')[0].value;
			createCookie("email", strEmail , 7);  
			createCookie("password", strPassword , 7);      
		}
		else
		{
			removeCookie("email");
			removeCookie("password");
		}
		location.href = location.href;
	}
	//Wrong Password
	else if( ret.value[0] == -1 )
	{$('#divMReq_WrongPwd').show();}
	//If Member Inactive
	else if( ret.value[0] == 2 )	
	{$('#divMReq_MemInactive').show();}
	//If Email is not found in DB
	else
	{$('#divMReq_EmailNotFoun').show();}	
}
function LoadMReqLogin() 
{   
    if (readCookie("email") != null && readCookie("email") != "" && readCookie("password") != null && readCookie("password") != "") 
    {
        $('.csMemReqLogin .csFakePWBox').hide();
        $('.csMemReqLogin .csPWBox').show();
        $('.csMemReqLogin .csMReqTxtBox')[0].value = readCookie("email");
        $('.csMemReqLogin .csPWBox')[0].value = readCookie("password");       
        
        document.getElementById("imgMReqRemPwd").src = '/Images/MReqLogin/Chkbox_tick.png';
        document.getElementById("imgMReqRemPwd").setAttribute('value', '1');
    }
}
/*login popup end*/
function ShowJQPopup(titleTxt, contentTxt, widthInt, heightInt) {
    var $dialog = $('<div>' + contentTxt + '</div>').dialog({ autoOpen: false, title: titleTxt, width: widthInt, height: heightInt, modal: true,zIndex:100001 });
    $dialog.dialog('open');
}
/*PBS popup start*/
var divPBSDlg;
function ShowPBSPopupLayer()
{
	$(document).ready(function() {if (readCookie("DTFBS") == null || readCookie("DTFBS") != "2" ){divPBSDlg = $("#divPBSPopup").dialog({ dialogClass: 'no-header',autoOpen: true, width: 650, modal: true,zIndex:100001});divPBSDlg.show();}});
}
function HidePBSPopupLayer()
{
	if(divPBSDlg != null)
	{
	    divPBSDlg.dialog('destroy');
	    if (readCookie("DTFBS") != null  ) 
        {            
            var pbsCount = parseInt(readCookie("DTFBS"));
            pbsCount = pbsCount + 1;
            createCookie("DTFBS",pbsCount,365);
        }
        else
            createCookie("DTFBS",1,365);	    
	}
}
function StartJQCountdown(seconds)
{

	var tmpSeconds;
	var days,hours, minutes, tmpSeconds;
	if(seconds >= 0) 
	{
		tmpSeconds = seconds
		days = parseInt(tmpSeconds / 86400);
		tmpSeconds -= (days * 86400);		
		hours = parseInt(tmpSeconds / 3600);
		tmpSeconds -= (hours * 3600);
		minutes = parseInt(tmpSeconds / 60);
		tmpSeconds -= (minutes * 60);
		
		days = ""+days+"";
		if(days.length == 1)
		{
			days = "0" + days;
		}
		
		hours = ""+hours+"";
		if(hours.length == 1)
		{
			hours = "0" + hours;
		}		
		minutes = ""+minutes+"";
		if(minutes.length == 1)
		{
			minutes = "0" + minutes;
		}		
		tmpSeconds = ""+tmpSeconds+"";
		if(tmpSeconds.length == 1)
		{
			tmpSeconds = "0" + tmpSeconds;
		}
		document.getElementById('countdown_days_number').innerHTML = days;
		document.getElementById('countdown_hours_number').innerHTML = hours;
		document.getElementById('countdown_minutes_number').innerHTML = minutes;
		document.getElementById('countdown_seconds_number').innerHTML = tmpSeconds;
		if(seconds == 0)
		{
			setTimeout("reload()", 3000);			
		}
		else if( seconds > 0 )
		{	
			setTimeout("StartJQCountdown(" + (seconds-1) +")", 1000)
		}
	}

}
