var _initText = "" ;
function ResetBox(sender, textVal)
{
	if (textVal != "" && _initText == "")
	{
		_initText = sender.value;
		sender.value="";
		sender.style.color = "#000";
	}
}
/////////////////////////////////////////////////////////////////////////////////////////////
//Hint Start
//hint object format -> {id: "", hint: "", head: "": style: "" }
var HintElements = new Array();
var ValElements = new Array();
var ClientStrings = new Array();	
var ErrorValidators= new Array();
var ErrorInputs= new Array();

addLoadEvent(prepareInputsForHints);
addLoadEvent(prepareSelectsForHints);

function addLoadEvent(func) 
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function') 
  {
    window.onload = func;
  } 
  else 
  {
    window.onload = function() 
    {
      oldonload();
      func();
    }
  }
}
function prepareInputsForHints() 
{
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++)
	{
	    if((inputs[i].type == "text" || inputs[i].type == "password") && (inputs[i].className == 'inputtext' || inputs[i].className == 'signupinputError')) 
	    {
	        //show hint on focus
	        inputs[i].onfocus = function () 
		    {
		        showHint(this);
		    }
		    // when the cursor moves away from the field, hide the hint
		    inputs[i].onblur = function () 
		    {
		        hideHint(); validate(this);
		    }
		    //validate input's content 
//		    inputs[i].onchange = function () 
//		    {
//		        validate(this); 
//		    }
		}
	}
	showHint(document.getElementById('username'));
}

function prepareSelectsForHints() 
{
	var selects = document.getElementsByTagName("select");
	for (var i=0; i<selects.length; i++)
	{
        //show hint on focus
        selects[i].onfocus = function () 
	    {
	        showHint(this);
	    }
	    // when the cursor moves away from the field, hide the hint
	    selects[i].onblur = function () 
	    {
	        hideHint();
	    }
	    //validate content 
//	    selects[i].onchange = function () 
//	    {
//	        validate(this); 
//	    }
	}
}

function buildHintMarkup(ele, head, body, showimg)
{
    var hintstyle = "signupBBdiv";
    var pointerstyle = ele.attributes["hintstyle"];
        
    if(typeof(head) == "object")
        head = head.value;
    if(typeof(body) == "object")
        body = body.value;
    if(typeof(pointerstyle) == "object")
        pointerstyle = pointerstyle.value;
    
    var hintpos = findPos(ele);
    
    var top = hintpos.top + 4;
    var width = hintpos.width;
    var left = hintpos.left + width + 10;
       
    switch(pointerstyle)
    {
        case "top" :
            pointerstyle = "hint-pointer_top";
            top = top + 30  ;
            left = left - width + 50;
            break;
        case "bottom" :
            pointerstyle = "hint-pointer_bottom";
            top = top - 50  ;
            left = left - width;
            break;
            
        case "right" :
            pointerstyle = "hint-pointer_right";
            left = left - width - 240;
            break;
        default:
            hintstyle = " signupBBdiv";
            pointerstyle = "signupBBleft";
            break;
    }
      
    if(typeof(pointerstyle) == "undefined" || !pointerstyle)
        pointerstyle = "signupBBleft";
        
    var hintMarkup = "<div class=\"" + hintstyle + "\">";
    hintMarkup += "<div class=\""+pointerstyle+"\"></div>";
    hintMarkup += "<div class=\"signupBBcontent\">";
    if(typeof(head) != "undefined" || head)
    {
        if(showimg)
            hintMarkup += "<div class=\"signupBBerrorHead\">" + head + "</div>";
        else
            hintMarkup += "<div class=\"signupBBHead\">" + head + "</div>";
    }
    else
        hintMarkup += "<div class=\"signupBBerrorHead\">&nbsp; </div>";
    hintMarkup += "<div style=\"clear:left;\">" + body + "</div> ";
    hintMarkup += "</div>";  
    hintMarkup += "</div>";              

    return {markup:decode(hintMarkup),left:left,top:top};
}

function showHint(ele)
{
    if(typeof(ele) == "undefined" || !ele || ele.style.display == 'none')
        return;
    
    //display any validation err on the page.
    if(ErrorInputs.length > 0)
    {
        var errObj = ErrorValidators[ErrorInputs.indexOf(ele.id)];
        if(typeof(errObj) == "undefined" || !errObj)
            return;
        showErr(ele, errObj.msg, errObj.head);
        return;
    }
        
    var hint = document.getElementById("divHint");
  
    if(typeof(hint) == "undefined" || ! hint)
    {
        hint = document.createElement("div");
        hint.id= "divHint";
        hint.style.position = "absolute";
        document.body.appendChild(hint, ele.parentNode);
        //ele.parentNode.appendChild(hint, ele.parentNode);
    }
    
    var hintobj = GetHint(ele);
    var head = hintobj.head;
    var body = hintobj.hint;
    if(!body || body == "")
        return;
    var hintbody = buildHintMarkup(ele, head, body, false);

    hint.style.left = hintbody.left + "px";
    hint.style.top = hintbody.top + "px";
    if(hintbody.markup && hintbody.markup != "")
        hint.innerHTML = hintbody.markup;
    hint.style.display = "inline";
    hint.style.paddingTop = "5px";
    //ele.className = ele.attributes["orig_class"];
}

function decode(text)
{
    return text.replace(/&lt;/g, "<").replace(/&gt;/g, ">");
}

function GetHint(ele)
{
//hint object format -> {id: "", hint: "", head: "": style: "" }
    if(!HintElements)
        return;
    for(var i=0; i<HintElements.length; i++)
    {
        var hintObj = HintElements[i];
        if(!hintObj)
            break;
        if(ele.id === hintObj.id)
            return {hint: hintObj.hint, head:hintObj.head};
    }
    return {hint:"", head:""};
}

function SetHint(ele, hint)
{
//hint object format -> {id: "", hint: "", head: "": style: "" }
    if(!HintElements)
        HintElements = new Array();
    var hintObj;    
    for(var i=0; i<HintElements.length; i++)
    {
        var v = HintElements[i];
        if(ele.id === v.id)
        {
            hintObj = v;
            break;
        }
    }
    if(hintObj)
    {
        hintObj.hint = hint.hint;
        hintObj.head = hint.head; 
    }
    else
        HintElements.push({id:ele.id, hint:hint.hint, head:hint.head, style: hint.style});
}

function GetValidationObj(ele)
{
//var validationObj = {id: "", type: "", val: "", body: "", head: "", style: ""};
    if(!ValElements)
        return;
    
    // added by Derik H. Jang
    // handle exception which fired when 'ele' variables is null.
    // if 'ele' is null, IE 7 can't submit form data because an exception.
    if (ele == null || typeof(ele) == 'undefined')
		return;
		
    var validations = new Array();
    
    for(var i=0; i<ValElements.length; i++)
    {
        var valObj = ValElements[i];
        if(!valObj)
            break;
        
        if(ele.id === valObj.id)
            validations.push(valObj);
    }
    return validations;
}

function showErr(ele, msg, head)
{
    if(typeof(ele) == "undefined" || !ele)
        return false;
        
    var hint = document.getElementById("divHint");
    if(typeof(hint) == "undefined" || ! hint)
    {
        hint = document.createElement("div");
        hint.id="divHint";
        hint.style.position = "absolute";
        document.body.appendChild(hint, ele.parentNode); 
    }
    
    if(head && typeof(head) == "object")
        head = head.value;
    if(msg && typeof(msg) == "object")
        msg = msg.value;
    
    var hintbody = buildHintMarkup(ele, head, msg, true);
    if(hintbody.markup && hintbody.markup != "")
        hint.innerHTML = hintbody.markup;
    hint.style.left = hintbody.left + "px";
    hint.style.top = hintbody.top + "px";
    hint.style.display = "inline";
    //ele.className = "signupinputError";
    //ele.focus();
}

function hideHint()
{
//    if(ErrorValidators.length > 0)
//        return;
    var hint = document.getElementById("divHint");
    
    if(typeof(hint) == "undefined" || !hint)
        return;
    hint.style.display = "none";
}


var nameRegex = /^([a-zA-Z]+)$/;
var emailRegex = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
                ///^([\w]+)(.[\w]+)*@([\w]+)(.[\w]{2,3}){1,2}$/;
var dobRegex = /^([0-9]){2}(\/|-){1}([0-9]){2}(\/|-)([0-9]){4}$/;

function validate(ele)
{
    //var validationObj = {id: "", type: "", val: "", body: "", head: "", style: ""};        
    var valObj = GetValidationObj(ele);
    
    var flag = true;
    
    if(!valObj || valObj.length <=0)
        return flag;
    
    for(var i=0; i<valObj.length; i++)
    {
        if(!flag)
            break;
        flag = ValidateElement(ele, valObj[i]);
    }
    return flag;
}
function ValidateElement(ele, valObj)
{
    if(typeof(ele) == "undefined" || typeof(valObj) == "undefined")
	    return false;
    var result = true;	
	if(valObj && typeof(valObj.type) != "undefined")
	{
	    switch(valObj.type)
	    {
	        case "required":
	            if(valObj.val == true || valObj.val == "true")
                {
                    //required field validation
                    if(ele.value.length <= 0)
                    {
                        msg = valObj.body;
                        head = valObj.head;
                        if(typeof(msg) == "object")
                                msg = msg.value;
                        if(typeof(head) == "object")
                            head = head.value;
                        updateErrLists(ele.id, {id:ele.id, msg:msg, head:head, style: 'signupinputError'}, false);
                        result = false;
                    }
                    else
                        updateErrLists(ele.id, {style: 'signupinput'}, true);
                }
	            break;
	        case "minlength":
	            //min length validation
                if(ele.value.length < valObj.val)
                {
                    msg = valObj.body;
                    head = valObj.head;
                    if(typeof(msg) == "object")
                            msg = msg.value;
                    if(typeof(head) == "object")
                        head = head.value;

                    updateErrLists(ele.id, {id:ele.id, msg:msg, head:head, style:'signupinputError'}, false);
                    result = false;
                }
                else
                    updateErrLists(ele.id, {style: 'signupinput'}, true);
                break;
	        case "comparewith":
	            var eleToCompare = document.getElementById(valObj.val);
                if(eleToCompare)
                {
                   if(ele.value != eleToCompare.value)
                    {
                        msg = valObj.body;
                        head = valObj.head;
                        if(typeof(msg) == "object")
                            msg = msg.value;
                        if(typeof(head) == "object")
                            head = head.value;
                            
                        updateErrLists(ele.id, {id:ele.id, msg:msg, head:head, style:'signupinputError'}, false);
                        result = false;
                    }
                    else
                        updateErrLists(ele.id, {style: 'signupinput'}, true);
                }
	            break;
	        case "regex":
	            //regex validation
                var regex = valObj.val; 
                switch(regex)
                {
                    case "name":
                        result = validateRegex(ele, nameRegex, valObj);
                        break;
                    case "dob":
                        result = validateRegex(ele, dobRegex, valObj);
                        break;
                    case "email":
                        result = validateRegex(ele, emailRegex, valObj);
                        break;
                    default:
                        result = validateRegex(ele, regex, valObj);
                        break;    
                }
	            break;
	        case "customfunc":
	            var customfunc = valObj.val;
	            if(customfunc && typeof(customfunc) == "function")
	                result = customfunc(ele.id, valObj);
	            break;
	        default:
	            break;
	    }
	} 
	return result;
}

function validateRegex(ele, regex, valObj)
{
    var msg;
    var head;
    var regex = new RegExp(regex);
    var result = true;
    
    if(!ele)
        return result;
    
    if(regex.test(ele.value) != true)
    {
        msg = valObj.body;
        head = valObj.head;
        
        if(typeof(msg) == "object")
            msg = msg.value;
        if(typeof(head) == "object")
            head = head.value;

        updateErrLists(ele.id, {id:ele.id, msg:msg, head:head, style:'signupinputError'}, false);
        result = false;
    }
    else
        updateErrLists(ele.id, {style: 'signupinput'}, true);
    return result;
}

function updateErrLists(eleId, errObj, isvalid)
{
   var ele = document.getElementById(eleId);
   var style = "";
   if(typeof(errObj) != "undefined" && errObj.style != null)
       style = errObj.style;
   if(!isvalid)
   {
        if(ErrorInputs.indexOf(eleId) != -1)
            return;
        showErr(ele,errObj.msg, errObj.head);
        ele.className = style;//"signupinputError";
        ErrorValidators.push(errObj);
        ErrorInputs.push(eleId);
   }
   else
   {
        hideHint();
        if(ErrorInputs.indexOf(eleId) == -1)
            return;
        ele.className = style;
        ErrorValidators.splice(ErrorInputs.indexOf(eleId), 1);
        ErrorInputs.splice(ErrorInputs.indexOf(eleId), 1);
   }
}

function GetClientString(key)
{
    if(!key || typeof(ClientStrings) == "undefined")
        return "";
    for(var i=0; i<ClientStrings.length; i++)
    {
        var errObj = ClientStrings[i];
        if(!errObj || typeof(errObj) == "undefined")
            break;
        if(errObj.key == key)
            return errObj.msg;    
    } 
    return decode(key);
}

[].indexOf || (Array.prototype.indexOf = function(v,n)
{
  n = (n==null)?0:n; var m = this.length;
  for(var i = n; i < m; i++)
    if(this[i] == v)
       return i;
  return -1;
});

function findPos(obj) 
{
	var curleft = curtop = curwidth = 0;
	var elementNode = obj;
	if (obj.offsetParent) 
	{
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) 
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	if(elementNode.offsetWidth) 
	{
		curwidth = elementNode.offsetWidth;
	} 
			
	return {left:curleft, top:curtop, width:curwidth};
}

function ValidateForm()
{
    var isValid = false;
    
    if(ValElements.length >0)
    {
        for(var i=0; i<ValElements.length; i++)
        {
            var valObj = ValElements[i];
            validate(document.getElementById(valObj.id));
        }
    }
    if(ErrorInputs.length <=0)
    {
       isValid = true;
    }
    else
    {
        //display any validation err on the page. 
        for(var i=0; i<ValElements.length; i++)
        {
            var j = ErrorInputs.indexOf(ValElements[i].id);
            if(j >= 0)
            {
                var errObj = ErrorValidators[j];
                if( errObj && typeof(errObj) != "undefined" )
                {
                    var ele = document.getElementById(errObj.id);
                    showErr(ele, errObj.msg, errObj.head);
                    ele.focus();
                    isValid = false;
                    break;
                }
            }
        }
    }
    return isValid;
}

//Hint End
//////////////////////////////////////////////////////////////////////////////////////////////////////

//Region Start
function populateStates(countrylistId, statelistid, selectedState)
{
	var objstate= document.getElementById(statelistid);
	var objregionlabel = document.getElementById('lblRegion');
	var objcountry = document.getElementById(countrylistId);
	objstate.options.length = 1;
	var statelist = g_statelist;	
 
	var countryId = objcountry[objcountry.selectedIndex].value;
	countryId = countryId.split("_")[0];
	var countryCode = countryId.split("_")[1];
	
	var counter = 0;
	var states = new Array();
	
	for ( i=0; i < statelist.length; i++ )
	{
		if ( statelist[i].refID == countryId)
		{
		    //copy matching states into an array
		    states[counter] = { optText:statelist[i].title, optValue:statelist[i].id };
		    counter++;
		}
	}	
	// sort the states array
    states.sort(sortAsc);

    // copy sorted options from array to states dropdown
    for (var j=0; j<states.length; j++) 
    {
        var optObj = document.createElement('option');
        optObj.text = states[j].optText;
        optObj.value = states[j].optValue + "_" + states[j].optText;
        objstate.options.add(optObj);
        
        if(states[j].optValue == selectedState)
            optObj.selected = true;
    }

	if(counter > 0 && countryCode != 'US')
	{
	 	objstate.style.display='';
	 	objregionlabel.style.display = '';
	}
	
	else
	{
	    objregionlabel.style.display = 'none';
		objstate.style.display='none';
	}
}

// sort function - ascending (case-insensitive)
function sortAsc(r1, r2) {
    var v1 = r1.optText.toLowerCase();
    var v2 = r2.optText.toLowerCase();
    if (v1 > v2) return(1);
    if (v1 < v2) return(-1);
    return(0);
}

function validateRegion(id, valObj) 
{
	var country = document.getElementById('Country');
	var region = document.getElementById(id);
	if ((region.options != null ) && (region.options.length > 1) && 
	    country[country.selectedIndex].value.split("_")[1] != 'US' && 
	    country[country.selectedIndex].value.split("_")[1] != 'UK')
	{
		if (region.selectedIndex == -1) 
		{
			//alert("Please Select a State/Province/Territory");
			updateErrLists(id, {id:id, msg:valObj.body, head:valObj.head, style:'signupinputError'}, false);
			return false;
		} 
	}
	updateErrLists(id, {style: 'signupinput'}, true);
	return true;
}

function displayPostalCodeSample(countryListId, postalCodeEleId) 
{
    var objcountry = document.getElementById(countryListId);
	var countryCode =objcountry[objcountry.selectedIndex].value.split("_")[1];
	var objPostalCode = document.getElementById(postalCodeEleId);
	var sampleText = GetClientString("Example") + ": ";
	if(countryCode=="AU" || countryCode=="NO" || countryCode=="DK") 
	{
	    sampleText = sampleText + " 0123";
	}
	else if(countryCode=="FR" || countryCode=="DE" || countryCode=="IT" || countryCode=="ES" || 
		countryCode=="MX") 
    {
		sampleText = sampleText + " 01234";
	}
	else if(countryCode=="AT" || countryCode=="BE" || countryCode=="CH") 
	{
		sampleText = sampleText + " 1234";
	}
	else if(countryCode=="SE" || countryCode=="FI") 
	{
		sampleText = sampleText + "012 34";
	}
	else if(countryCode=="IN" || countryCode=="RU") 
	{
		sampleText = sampleText + "123456";
	}
	else if(countryCode=="BR") 
	{
		sampleText = sampleText + "01234-567";
	}
	else if(countryCode=="NL") 
	{
		sampleText = sampleText + "1111ww";
	}
	else if(countryCode=="PL") 
	{
		sampleText = sampleText + "12345 / 12-345";
	}
	else if(countryCode=="PT") 
	{
		sampleText = sampleText + "1234 / 1234-567";
	}
	else if(countryCode=="TR") 
	{
		sampleText = sampleText + "12345";
	}
	
	if(sampleText != GetClientString("Example") + ": ")
	{
	    //{hint: "", head: "", style: ""}
        SetHint(objPostalCode, {id:objPostalCode.id, hint:sampleText, head:"", style: ""});
        showHint(objPostalCode);
	}
	else
	{
	    SetHint(objPostalCode, {id:objPostalCode.id, hint:"", head:"", style: ""});
	    hideHint();
	}
}

function PostalCodeMessageFocus(countryListId, postalCodeEleId)
{
    var countrySelected = document.getElementById(countryListId);
	var postalCodeCell = document.getElementById(postalCodeEleId);
	var countryCode = countrySelected[countrySelected.selectedIndex].value.split("_")[1];
  
  	if( countryCode!="US" && countryCode!="CA" && countryCode!="UK" && countryCode!="AU" && 
	    countryCode!="FR" && countryCode!="DE" && countryCode!="IT" && countryCode!="ES" && 
	    countryCode!="AT" && countryCode!="MX" && countryCode!="SE" && countryCode!="JP" && 
	    countryCode!="NL" && countryCode!="SE" && countryCode!="CH" && countryCode!="KR" && 
	    countryCode!="NO" && countryCode!="DK" && countryCode!="FI")
	{
		SetHint(postalCodeCell, {id:postalCodeCell.id, hint:GetClientString('International_SignupPleaseEnterPostalCodeErro2'), head:"", style: ""});
        showHint(postalCodeCell);
    }
	else
	{
	    SetHint(postalCodeCell, {id:postalCodeCell.id, hint:"", head:"", style: ""});
        hideHint();
	}
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };

function validatePostalCode(id, valObj) 
{
	var country = document.getElementById('Country');
	var postalCode = document.getElementById('PostalCode');
	var countryZipCodeKey = "";
	var isValid = true;
	var countryCode = country.value.split('_')[1];
	countryZipCodeKey = getCountryZipCodeKey(countryCode)

	if(countryZipCodeKey!="") 
	{
		var items = countryZipCodeKey.split(":")
		
		//Strip space from SE postal code
		if (items[0] == "SE" && postalCode.value.indexOf(" " ) >= 0)
		{	
			var temp = postalCode.value;
			postalCode.value = temp.replace(/\s/g,"");
		}
		
		if (countryCode == "NL" || countryCode == "PL" || countryCode == "TR" || countryCode == "PT") 
		{
		    var countryPostalCode = postalCode.value.trim().replace(" ","");
		    
			if (countryPostalCode=="") 
			{
				//{id:ele.id, msg:msg, head:head}
				updateErrLists(postalCode.id, {id:postalCode.id, msg:GetClientString('PostalCodeErrorMessage'), head:valObj.head, style:'signupinputError'}, false);
				return false;
			}
			else
			{			
				var postalRegEx =  "";//new RegExp(/^\d{4}\w{2}$/i);
				if (countryCode == "NL") 
					postalRegEx =  new RegExp(/^\d{4}( )?\w{2}$/);
				if (countryCode == "PL") 
					postalRegEx =  new RegExp(/^\d{2}(-)?\d{3}$/);
				if (countryCode == "TR") 
					postalRegEx =  new RegExp(/^\d{5}$/);
				if (countryCode == "PT") 
					postalRegEx =  new RegExp(/^\d{4}(-\d{3})?$/);
				
				if(postalRegEx.test(countryPostalCode)) 
				{
				    updateErrLists(postalCode.id, {style: 'signupinput'}, true);
					return true;
				}
				else 
				{
				    updateErrLists(postalCode.id, {id:postalCode.id, msg:GetClientString('ZipCodeErrorMessage'), head:valObj.head, style: 'signupinputError'}, false);
					displayPostalCodeSample(country.id, postalCode.id);
					return false;
				}
			}
		}
		if(items[1]=="1") 
		{
			if(postalCode.value.trim()=="") 
			{
			    updateErrLists(postalCode.id, {id:postalCode.id, msg:GetClientString('PostalCodeErrorMessage'), head:valObj.head, style: 'signupinput'}, false);
				return false;
			}
			else if(!isNumeric(postalCode.value.trim())) 
			{
				if(items[0] != "US" && items[0] != "UK" && items[0] != "JP" && items[0] != "CA" && items[0] != "KR" &&
					items[0] != "NL" && items[0] != "SE") 
				{
					updateErrLists(postalCode.id, {id:postalCode.id, msg:GetClientString('LoginErrorMessage23'), head:valObj.head, style: 'signupinput'}, false);
					return false;
				}
			}
			else 
			{
				isValid = isValidPostalCode(items[0],postalCode.value.trim());
			}
		}
		else 
		{
			isValid = isValidPostalCode(items[0],postalCode.value.trim());
		}
		
		if (!isValid) 
		{
		    updateErrLists(postalCode.id, {id:postalCode.id, msg:GetClientString('LoginErrorMessage18'), head:valObj.head, style: 'signupinputError'}, false);
			return false;
		}
	}
	if(isValid == true)
	    updateErrLists(postalCode.id, {style: 'signupinput'}, true);
	return isValid;
}

function isValidPostalCode(countryCode, postalCodeValue) 
{
	if(countryCode=="AU" || countryCode=="NO" || countryCode=="DK") 
	{
		if(postalCodeValue.length != 4) 
			return false;
	}
	else if(countryCode=="FR" || countryCode=="DE" || countryCode=="IT" || countryCode=="ES" || 
		countryCode=="MX" || countryCode=="FI" || countryCode=="SE" ) 
	{
		if(postalCodeValue.length != 5) 
			return false;
	}
	else if (countryCode=="IN" || countryCode=="CA" || countryCode=="RU") 
	{
		if(postalCodeValue.length != 6) 
			return false;
	}
	else if(countryCode=="AT" || countryCode=="BE" || countryCode=="CH") 
	{
		if(postalCodeValue.length == 4) 
		{
			if(postalCodeValue.charAt(0)=="0") 
				return false;
		}
		else 
			return false;
	}
	else if(countryCode=="BR")
	{		
		if(postalCodeValue.length > 9) 
			return false;
	}
	else if (countryCode=="NL") 
	{
		if (postalCodeValue.length <= 6) 
		{
			if (postalCodeValue.charAt(0)=="0") 
			{
				return false;
			}
		} 
	}
	return true;
}

function getCountryZipCodeKey(countryCode) 
{
	// Key - "US:0" (CountryCode:IsZipCodeRequired)
	var countryCheckList = new Array("AU:1","AT:1","BE:1","CA:1","FR:1",
					                  "DE:1","IT:1","JP:1","KR:1","ES:1",
					                  "NL:1","CH:0","UK:1", "US:1", 
					                  "MX:1","SE:1","NO:1","DK:1",
					                  "FI:1", "IN:1", "BR:0","RU:1","PL:1","TR:1","PT:1");
	var items;
					  
	for(var i=0; i<countryCheckList.length; i++) 
	{
		items = countryCheckList[i].split(":");
		if(countryCode==items[0])
			return countryCheckList[i].toString();
	}
	return "";
}

function isNumeric(s) 
{ 
	var validChars = "0123456789"; 
	var c;
	for (i = 0; i < s.length; i++) 
	{
		c = s.charAt(i);
		if (validChars.indexOf(c) == -1) 
			return false;
	}
	return true;
}
//Region End
//Password Start
function ValidatePassword(id, valObj)
{
    var Password = document.getElementById('password');
    var strPassword = new String(Password.value);
    var flag = true;
    var errMsg = "";
    
    //remove password ele from the errList
	updateErrLists(id, {style: 'signupinput'}, true);
    
    // Password Checker
    var length=Password.value.length;
	if (length<6 || length>32) {
		errMsg = GetClientString('PasswordErrorMessage');
		flag = false;
	} 	
	if(!flag)
	{
	    //remove prev confirm pwd errs
	    updateErrLists('ConfirmPassword', {style: 'signupinput'}, true);
        //display err hint
        updateErrLists(id, {id:id, msg:errMsg, head: valObj.head, style: 'signupinputError'}, false);
	}
	
	return flag;
}

function ValidateConfPassword(id, valObj)
{
    var result = true;
    var pwdEle = document.getElementById('Password');
    
    if(!pwdEle)
        return result;
    
    if(validate(pwdEle))
    {
        var ele = document.getElementById(id);
        if(!ele)
            return result;
        if(ele.value != pwdEle.value)
        {
            updateErrLists(ele.id, {id:ele.id, msg:valObj.body, head:valObj.head, style:'signupinputError'}, false);
            result = false;
        }
        else
            updateErrLists(ele.id, {style: 'signupinput'}, true);
    }
    
    return result;
}
//Password End
//Email Start
function CheckDuplicateEmail(id, valObj)
{
    var ele = document.getElementById(id);
    var prevEmail = GetClientString("PrevEmail");
    
    if(ele.value == prevEmail)
    {
        updateErrLists(id, {id:id, msg:valObj.body, head: valObj.head, style: 'signupinputError'}, false);
		return false; 
    }
    else
    {
        updateErrLists(id, {style: 'signupinput'}, true);
        return true;
    }
}
//Email End
//Age check
function ValidateAge(id, valObj)
{
    var day = document.getElementById('Day');
    var month = document.getElementById('Month');
    var year = document.getElementById(id);
    
    //remove age ele from errList
	updateErrLists(id, {style: ''}, true);
    
    if(day.value == -1 || month.value == -1 || year.value == -1)
    {
        updateErrLists(id, {id:id, msg:GetClientString('BirthdayErrorMessage'), head: valObj.head, style: ''}, false);
		return false;
    }
//    var minAge = new Date();
//    minAge.setYear(minAge.getYear()-14);
//    var enteredAge = new Date(year.value, month.value - 1, day.value);
//    //if selected date is greater than the min age limit, show err hint
//    if(enteredAge > minAge)
//    {
//        updateErrLists(id, {id:id, msg:GetClientString('LoginErrorMessage29'), head: valObj.head, style: ''}, false);
//		return false;
//    }
    return true;
}
//Age check end
//Gender Start
function ValidateGender(id, valObj)
{
    var M = document.getElementById('genderM');
    var F = document.getElementById('genderF');
    if(!M.checked && !F.checked)
    {
        updateErrLists(F.id, {id:M.id, msg:GetClientString('GenderErrorMessage'), head: valObj.head, style: null}, false);
        return false;
    }
    updateErrLists(F.id, {style: null}, true);
    return true;
}
//Gender End
//Preferred Site & Language Start
function handleOnChangePreferredCulture(id) 
{
    var termsEle = document.getElementById('TermsDiv');
    if(!termsEle || typeof(termsEle) == "undefined")
        return;
	
	var ele = document.getElementById(id);
	var val = ele.value;
   
    if(val == 'ja-JP')
    {
        DisplayJapaneseUserAgreement(true);
    }
    else
    {
        DisplayJapaneseUserAgreement(false);
    }
	var strDisclaimer = GetClientString(val);
	termsEle.innerHTML= strDisclaimer;
}
function DisplayJapaneseUserAgreement(show)
{
    var textarea = document.getElementById('UserAgreementJapan');
    if(!textarea)
    {
        return;
    }
    if(show)
    {
        textarea.value = GetClientString("UserAgreementJapan");
        textarea.style.display = "block";
    }
    else
    {
        textarea.style.display = "none";
        textarea.value = "";
    }
}
//Preferred Site & Language End

//Terms Start
function ValidateTermsOfUse(id, valObj)
{
    var tos = document.getElementById(id);
    // TOS check
	if (!tos.checked) 
	{
		//alert("Please check the agree to our terms box.");
		updateErrLists(id, {id:id, msg: GetClientString('TOSErrorMessage'), head: valObj.head, style:null}, false);
		tos.onclick = function()
		               {
		                if(tos.checked)
		                    hideHint();
		                else 
		                    showHint(tos);
		               }
		return false;
	}
	
	updateErrLists(id, {style: null}, true);
	return true;
}
//Terms End

function ShowValidationErrors()
{
    for(var i=0; i < ErrorInputs.length; i++)
    {
        var errObj = ErrorValidators[i];
        if( errObj && typeof(errObj) != "undefined" )
        {
            var ele = document.getElementById(errObj.id);
            showErr(ele, errObj.msg, errObj.head);
            ele.className = errObj.style;
        }
    }
}

//safety tips popup
// Security Pop-up code.

var continueButton;
function DisplaySafetyTips(content, title, continueBtnTitle, cancelBtnTitle)
{
    var p = MySpace.UI.Popup.create(content, title, true);
    p.addCssClass('popUp');
    continueButton = p.add_button(continueBtnTitle, false);
    continueButton.disabled = true;
    continueButton.onclick = function()
    { 
        var v = document.getElementById('safetytipsread');
        if(!v.checked)
        {
            p.show();
            //alert('please select the checkbox');
            return false;
        }
        return true; 
    }
    p.show();                
}   

function toggleContinueBtn()
{
    var v = document.getElementById('safetytipsread');
    if(v && v.checked)
    {
        continueButton.disabled = false;
    }
    else
    {
        continueButton.disabled = true;
    }
    return continueButton.enabled;
}

//
function openWin(url, title, width, height)
{
    window.open(url,title,"height="+height+",width="+width+",status=yes,toolbar=no,menubar=no,location=no,resizable=no");
}

function adjustTabHeight(tab1, tab2)
{
    var t1 = document.getElementById(tab1);
    var t2 = document.getElementById(tab2);

    if(t1 && t2)
    {
        if(t1.offsetHeight - t2.offsetHeight > 6)
        {
            t2.style.height = "27px";
        }
        else if(t2.offsetHeight - t1.offsetHeight > 6)
        {
            t1.style.height = "27px";
        }
    }
}

