﻿function validatesmall(Name,Password,PleaseFill,TooShort,EmailInvalid,EmailIllegal)
{
  var result;
  result = false;
  
  if (checkWord(PleaseFill,TooShort,document.aspnetForm.ctl00_CPH_Name.value, Name))
  {
  	result = false;	
  }
  else if (checkEmail(EmailInvalid,EmailIllegal,document.aspnetForm.ctl00_CPH_Email.value,PleaseFill + ' '))
  {
  	result = false;
  }
  else if (checkEmail(EmailInvalid,EmailIllegal,document.aspnetForm.ctl00_CPH_msmEmail.value,PleaseFill + ' '))
  {
  	result = false;
  }
  else if (checkWord(PleaseFill,TooShort,document.aspnetForm.ctl00_CPH_msmPassword.value, Password))
  {
  	result = false;
  }  
  else
  {
    document.aspnetForm.ctl00_CPH_createprofile.style.display = 'none';
    document.aspnetForm.ctl00_CPH_loader.style.display = '';
    state = 1;
    callwebpage("welcomehandler.aspx?t=c&name=" + encodeURI(document.aspnetForm.ctl00_CPH_Name.value) + "&email=" + encodeURI(document.aspnetForm.ctl00_CPH_Email.value) + "&msnemail=" + encodeURI(document.aspnetForm.ctl00_CPH_msmEmail.value) + "&msnpw=" + encodeURI(document.aspnetForm.ctl00_CPH_msmPassword.value) + "&swid=" + document.aspnetForm.ctl00_CPH_swid.value);
    state = 2;
    callwebpage("welcomehandler.aspx?t=s" + "&email=" + encodeURI(document.aspnetForm.ctl00_CPH_Email.value))
	result = false;
  }  
  
  return result;
}

function checkWord(PleaseFill,TooShort,strng, txt) 
{
	if (strng == "") 
	{
	    alert(PleaseFill + " " + txt);
		return true;
	}	
	if ((strng.length < 2)) 
	{
	   alert(txt + " " + TooShort + "\n");
	   return true;
	}
}

function checkEmail(EmailInvalid,EmailIllegal,strng,txt)
{
	var emailFilter=/^.+@.+\..{2,4}$/;
	if (!(emailFilter.test(strng))) 
	{ 
       alert (txt + EmailInvalid);
	   return true;
	}
	
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
	if (strng.match(illegalChars)) 
	{
   		alert(txt + EmailIllegal);
		return true;
	}
}

var xmlhttp;
var state;
function callwebpage(url)
{
	if (window.XMLHttpRequest)
	  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else if (window.ActiveXObject)
	  {
	  // code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	else
	  {
	  alert("Your browser does not support XMLHTTP!");
	  }

	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		  {
		  if (state == 2)
		    {
    		  if(xmlhttp.responseText.search(/importsucceded/)>=0)
                {
            	var myRandomNum = parseInt(Math.random()*99999999);  // cache buster
                var diviframe=document.getElementById("ctl00_iframewelcomehandler");
                diviframe.src = "welcomehandler.aspx?t=e" + "&email=" + encodeURI(document.aspnetForm.ctl00_CPH_Email.value) + "&rand=" + myRandomNum
                var mpu = top.$find('ctl00_createprofilepopup'); 
                mpu.show();
                document.aspnetForm.ctl00_CPH_createprofile.style.display = '';
                document.aspnetForm.ctl00_CPH_loader.style.display = 'none';
                }  
    		  else
    		    {
    		        callwebpage("welcomehandler.aspx?t=s" + "&email=" + encodeURI(document.aspnetForm.ctl00_CPH_Email.value))
                }
            }  
		  }
	}

	var myRandom = parseInt(Math.random()*99999999);  // cache buster
	xmlhttp.open("GET",url + "&rand=" + myRandom,true);
	xmlhttp.send(null);
	return xmlhttp
}

function callwebpagesilent(url) {
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.open("GET", url, true);
    xmlhttp.send(null);
    return false;
}
