var _initText = "" ;
function ResetBox(sender, textVal) {
	if (textVal != "" && _initText == "")
	{
		_initText =  _proxy_jslib_handle(sender, 'value', '', 0, 0);
		 _proxy_jslib_assign('', 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 =  _proxy_jslib_handle(document, 'getElementsByTagName', '', 1, 0)("input");
	for (var i=0; i<inputs.length; i++)
	{
	    if(( _proxy_jslib_handle(inputs, (i), 0, 0).type == "text" ||  _proxy_jslib_handle(inputs, (i), 0, 0).type == "password") && 
	        ( _proxy_jslib_handle(inputs, (i), 0, 0).className == 'signupinput' ||  _proxy_jslib_handle(inputs, (i), 0, 0).className == 'signupinputError')) 
	    {
	        //show hint on focus
	         _proxy_jslib_handle(inputs, (i), 0, 0).onfocus = function () {
		        showHint(this);
		    }
		    // when the cursor moves away from the field, hide the hint
		     _proxy_jslib_handle(inputs, (i), 0, 0).onblur = function () {
		        hideHint(); validate(this);
		    }
		    //validate input's content 
//		    inputs[i].onchange = function () 
//		    {
//		        validate(this); 
//		    }
		}
	}
}

function prepareSelectsForHints() {
	var selects =  _proxy_jslib_handle(document, 'getElementsByTagName', '', 1, 0)("select");
	for (var i=0; i<selects.length; i++)
	{
        //show hint on focus
         _proxy_jslib_handle(selects, (i), 0, 0).onfocus = function () {
	        showHint(this);
	    }
	    // when the cursor moves away from the field, hide the hint
	     _proxy_jslib_handle(selects, (i), 0, 0).onblur = function () {
	        hideHint();
	    }
	    //validate content 
//	    selects[i].onchange = function () 
//	    {
//	        validate(this); 
//	    }
	}
}

function buildHintMarkup(ele, head, body, showimg) {
    var hintstyle = "signupBBdiv";
    var pointerstyle =  _proxy_jslib_handle(ele.attributes, ("hintstyle"), 0, 0);
        
    if(typeof(head) == "object")
        head =  _proxy_jslib_handle(head, 'value', '', 0, 0);
    if(typeof( _proxy_jslib_handle(null, 'body', body, 0, 0)) == "object")
         body= _proxy_jslib_assign_rval('', 'body', '=', (  _proxy_jslib_handle( _proxy_jslib_handle(null, 'body', body, 0, 0), 'value', '', 0, 0)), body);
    if(typeof(pointerstyle) == "object")
        pointerstyle =  _proxy_jslib_handle(pointerstyle, 'value', '', 0, 0);
    
    var hintpos = findPos(ele);
    
    var top =  _proxy_jslib_handle(hintpos, 'top', '', 0, 0) + 4;
    var width = hintpos.width;
    var left = hintpos.left + width + 10;
       
    switch(pointerstyle)
    {
        case "top" :
            pointerstyle = "hint-pointer_top";
             top= _proxy_jslib_assign_rval('', 'top', '=', (  _proxy_jslib_handle(null, 'top', top, 0, 0) + 30 ), top);
            left = left - width + 50;
            break;
        case "bottom" :
            pointerstyle = "hint-pointer_bottom";
             top= _proxy_jslib_assign_rval('', 'top', '=', (  _proxy_jslib_handle(null, 'top', top, 0, 0) - 50 ), top);
            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;\">" +  _proxy_jslib_handle(null, 'body', body, 0, 0) + "</div> ";
    hintMarkup += "</div>";  
    hintMarkup += "</div>";              

    return {markup:decode(hintMarkup),left:left,top: _proxy_jslib_handle(null, 'top', top, 0, 0)};
}

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 =  _proxy_jslib_handle(ErrorValidators, (ErrorInputs.indexOf(ele.id)), 0, 0);
        if(typeof(errObj) == "undefined" || !errObj)
            return;
        showErr(ele, errObj.msg, errObj.head);
        return;
    }
        
    var hint =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)("divHint");
  
    if(typeof(hint) == "undefined" || ! hint)
    {
        hint = document.createElement("div");
        hint.id= "divHint";
        hint.style.position = "absolute";
         _proxy_jslib_handle(document, 'body', '', 0, 0).appendChild(hint, ele.parentNode);
        //ele.parentNode.appendChild(hint, ele.parentNode);
    }
    
    var hintobj = GetHint(ele);
    var head = hintobj.head;
    var body = hintobj.hint;
    if(! _proxy_jslib_handle(null, 'body', body, 0, 0) ||  _proxy_jslib_handle(null, 'body', body, 0, 0) == "")
        return;
    var hintbody = buildHintMarkup(ele, head,  _proxy_jslib_handle(null, 'body', body, 0, 0), false);

    hint.style.left = hintbody.left + "px";
     _proxy_jslib_assign('', hint.style, 'top', '=', (  _proxy_jslib_handle(hintbody, 'top', '', 0, 0) + "px"));
    if(hintbody.markup && hintbody.markup != "")
         _proxy_jslib_assign('', hint, 'innerHTML', '=', ( hintbody.markup));
    hint.style.display = "inline";
    hint.style.paddingTop = "5px";
    //ele.className = ele.attributes["orig_class"];
}

function decode(text) {
    return  _proxy_jslib_handle( _proxy_jslib_handle(text, 'replace', '', 1, 0)(/&lt;/g, "<"), 'replace', '', 1, 0)(/&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 =  _proxy_jslib_handle(HintElements, (i), 0, 0);
        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 =  _proxy_jslib_handle(HintElements, (i), 0, 0);
        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 =  _proxy_jslib_handle(ValElements, (i), 0, 0);
        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 =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)("divHint");
    if(typeof(hint) == "undefined" || ! hint)
    {
        hint = document.createElement("div");
        hint.id="divHint";
        hint.style.position = "absolute";
         _proxy_jslib_handle(document, 'body', '', 0, 0).appendChild(hint, ele.parentNode); 
    }
    
    if(head && typeof(head) == "object")
        head =  _proxy_jslib_handle(head, 'value', '', 0, 0);
    if(msg && typeof(msg) == "object")
        msg =  _proxy_jslib_handle(msg, 'value', '', 0, 0);
    
    var hintbody = buildHintMarkup(ele, head, msg, true);
    if(hintbody.markup && hintbody.markup != "")
         _proxy_jslib_assign('', hint, 'innerHTML', '=', ( hintbody.markup));
    hint.style.left = hintbody.left + "px";
     _proxy_jslib_assign('', hint.style, 'top', '=', (  _proxy_jslib_handle(hintbody, 'top', '', 0, 0) + "px"));
    hint.style.display = "inline";
    //ele.className = "signupinputError";
    //ele.focus();
}

function hideHint() {
//    if(ErrorValidators.length > 0)
//        return;
    var hint =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)("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,  _proxy_jslib_handle(valObj, (i), 0, 0));
    }
    return flag;
}
function ValidateElement(ele, valObj) {
    if(typeof(ele) == "undefined" || typeof(valObj) == "undefined")
	    return false;
	
    var result = true;
	if(valObj && typeof(valObj.type) != "undefined")
	{
	    var eleDefaultStyle = "signupinput";
	    var eleErrStyle = (valObj.style && valObj.style != "" && valObj.style != null)? valObj.style : 'signupinputError';
	    switch(valObj.type)
	    {
	        case "required":
	            if(valObj.val == true || valObj.val == "true")
                {
                    //required field validation
                    if( _proxy_jslib_handle(ele, 'value', '', 0, 0).length <= 0)
                    {
                        msg =  _proxy_jslib_handle(valObj, 'body', '', 0, 0);
                        head = valObj.head;
                        if(typeof(msg) == "object")
                                msg =  _proxy_jslib_handle(msg, 'value', '', 0, 0);
                        if(typeof(head) == "object")
                            head =  _proxy_jslib_handle(head, 'value', '', 0, 0);
                        updateErrLists(ele.id, {id:ele.id, msg:msg, head:head, style: eleErrStyle}, false);
                        result = false;
                    }
                    else
                        updateErrLists(ele.id, {style: eleDefaultStyle}, true);
                }
	            break;
	        case "minlength":
	            //min length validation
                if( _proxy_jslib_handle(ele, 'value', '', 0, 0).length < valObj.val)
                {
                    msg =  _proxy_jslib_handle(valObj, 'body', '', 0, 0);
                    head = valObj.head;
                    if(typeof(msg) == "object")
                            msg =  _proxy_jslib_handle(msg, 'value', '', 0, 0);
                    if(typeof(head) == "object")
                        head =  _proxy_jslib_handle(head, 'value', '', 0, 0);

                    updateErrLists(ele.id, {id:ele.id, msg:msg, head:head, style:eleErrStyle}, false);
                    result = false;
                }
                else
                    updateErrLists(ele.id, {style: eleDefaultStyle}, true);
                break;
	        case "comparewith":
	            var eleToCompare =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(valObj.val);
                if(eleToCompare)
                {
                   if( _proxy_jslib_handle(ele, 'value', '', 0, 0) !=  _proxy_jslib_handle(eleToCompare, 'value', '', 0, 0))
                    {
                        msg =  _proxy_jslib_handle(valObj, 'body', '', 0, 0);
                        head = valObj.head;
                        if(typeof(msg) == "object")
                            msg =  _proxy_jslib_handle(msg, 'value', '', 0, 0);
                        if(typeof(head) == "object")
                            head =  _proxy_jslib_handle(head, 'value', '', 0, 0);
                            
                        updateErrLists(ele.id, {id:ele.id, msg:msg, head:head, style:eleErrStyle}, false);
                        result = false;
                    }
                    else
                        updateErrLists(ele.id, {style: eleDefaultStyle}, 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;
    
    var eleDefaultStyle = "signupinput";
	var eleErrStyle = (valObj.style && valObj.style != "" && valObj.style != null)? valObj.style : 'signupinputError';
    
    if(regex.test( _proxy_jslib_handle(ele, 'value', '', 0, 0)) != true)
    {
        msg =  _proxy_jslib_handle(valObj, 'body', '', 0, 0);
        head = valObj.head;
        
        if(typeof(msg) == "object")
            msg =  _proxy_jslib_handle(msg, 'value', '', 0, 0);
        if(typeof(head) == "object")
            head =  _proxy_jslib_handle(head, 'value', '', 0, 0);

        updateErrLists(ele.id, {id:ele.id, msg:msg, head:head, style:eleErrStyle}, false);
        result = false;
    }
    else
        updateErrLists(ele.id, {style: eleDefaultStyle}, true);
    return result;
}

function updateErrLists(eleId, errObj, isvalid) {
   var ele =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(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 =  _proxy_jslib_handle(ClientStrings, (i), 0, 0);
        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( _proxy_jslib_handle(this, (i), 0, 0) == 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 =  _proxy_jslib_handle(ValElements, (i), 0, 0);
            validate( _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(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( _proxy_jslib_handle(ValElements, (i), 0, 0).id);
            if(j >= 0)
            {
                var errObj =  _proxy_jslib_handle(ErrorValidators, (j), 0, 0);
                if( errObj && typeof(errObj) != "undefined" )
                {
                    var ele =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(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=  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(statelistid);
	var objregionlabel =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('lblRegion');
	var objcountry =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(countrylistId);
	objstate.options.length = 1;
	var statelist = g_statelist;	
 
	var countryId =  _proxy_jslib_handle( _proxy_jslib_handle(objcountry, (objcountry.selectedIndex), 0, 0), 'value', '', 0, 0);
	var countryCode = countryId.split("_")[1];
	countryId = countryId.split("_")[0];	
	var counter = 0;
	var states = new (Array)();
	
	for ( i=0; i < statelist.length; i++ )
	{
		if (  _proxy_jslib_handle(statelist, (i), 0, 0).refID == countryId)
		{
		    //copy matching states into an array
		     _proxy_jslib_assign('', states, (counter), '=', ( { optText: _proxy_jslib_handle(statelist, (i), 0, 0).title, optValue: _proxy_jslib_handle(statelist, (i), 0, 0).id }));
		    counter++;
		}
	}	
	
	var postalCode =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)("PostalCode");
	var postcodeDiv =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)("postCodeDiv");
	
	// sort the states array
	if(countryCode != "JP")
	{
        states.sort(sortAsc);

        if(postcodeDiv)
            postcodeDiv.style.display="inline";
    }
    else
    {
        if(postcodeDiv)
            postcodeDiv.style.display="none";
        if(postalCode)
             _proxy_jslib_assign('', postalCode, 'value', '=', ( "11111"));
    }

    // copy sorted options from array to states dropdown
    for (var j=0; j<states.length; j++) 
    {
        var optObj = document.createElement('option');
        optObj.text =  _proxy_jslib_handle(states, (j), 0, 0).optText;
         _proxy_jslib_assign('', optObj, 'value', '=', (  _proxy_jslib_handle(states, (j), 0, 0).optValue + "_" +  _proxy_jslib_handle(states, (j), 0, 0).optText));
        objstate.options.add(optObj);
        
        if( _proxy_jslib_handle(states, (j), 0, 0).optValue == selectedState)
            optObj.selected = true;
    }

	if(counter > 0)
	{	
	 	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 =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('Country');
	var region =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(id);
	
	if ((region.options != null ) && (region.options.length > 1) && 
	     _proxy_jslib_handle( _proxy_jslib_handle(country, (country.selectedIndex), 0, 0), 'value', '', 0, 0).split("_")[1] != 'US' && 
	     _proxy_jslib_handle( _proxy_jslib_handle(country, (country.selectedIndex), 0, 0), 'value', '', 0, 0).split("_")[1] != 'UK')
	{
		if ( _proxy_jslib_handle(region, 'value', '', 0, 0) == "" ||  _proxy_jslib_handle(region, 'value', '', 0, 0) == " ") 
		{
			//alert("Please Select a State/Province/Territory");
			updateErrLists(id, {id:id, msg: _proxy_jslib_handle(valObj, 'body', '', 0, 0), head:valObj.head, style:'signupinputError'}, false);
			return false;
		} 
	}
	updateErrLists(id, {style: 'signupinput'}, true);
	return true;
}

function displayPostalCodeSample(countryListId, postalCodeEleId) {
    var objcountry =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(countryListId);
	var countryCode = _proxy_jslib_handle( _proxy_jslib_handle(objcountry, (objcountry.selectedIndex), 0, 0), 'value', '', 0, 0).split("_")[1];
	var objPostalCode =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(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 =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(countryListId);
	var postalCodeCell =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(postalCodeEleId);
	var countryCode =  _proxy_jslib_handle( _proxy_jslib_handle(countrySelected, (countrySelected.selectedIndex), 0, 0), 'value', '', 0, 0).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  _proxy_jslib_handle(this, 'replace', '', 1, 0)(/^\s+|\s+$/g, ""); };

function validatePostalCode(id, valObj) {
	var country =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('Country');
	var postalCode =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('PostalCode');
	var countryZipCodeKey = "";
	var isValid = true;
	var countryCode =  _proxy_jslib_handle(country, 'value', '', 0, 0).split('_')[1];
	countryZipCodeKey = getCountryZipCodeKey(countryCode)



 if(countryZipCodeKey!="") 
	{
		var items = countryZipCodeKey.split(":")
		
		//Strip space from SE postal code
		if (items[0] == "SE" &&  _proxy_jslib_handle(postalCode, 'value', '', 0, 0).indexOf(" " ) >= 0)
		{	
			var temp =  _proxy_jslib_handle(postalCode, 'value', '', 0, 0);
			 _proxy_jslib_assign('', postalCode, 'value', '=', (  _proxy_jslib_handle(temp, 'replace', '', 1, 0)(/\s/g,"")));
		}
		
		if (countryCode == "NL" || countryCode == "PL" || countryCode == "TR" || countryCode == "PT") 
		{
		    var countryPostalCode =  _proxy_jslib_handle( _proxy_jslib_handle(postalCode, 'value', '', 0, 0).trim(), 'replace', '', 1, 0)(" ","");
		    
			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( _proxy_jslib_handle(postalCode, 'value', '', 0, 0).trim()=="") 
			{
			    updateErrLists(postalCode.id, {id:postalCode.id, msg:GetClientString('PostalCodeErrorMessage'), head:valObj.head, style: 'signupinput'}, false);
				return false;
			}
			else if(!isNumeric( _proxy_jslib_handle(postalCode, 'value', '', 0, 0).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], _proxy_jslib_handle(postalCode, 'value', '', 0, 0).trim());
			}
		}
		else 
		{
			isValid = isValidPostalCode(items[0], _proxy_jslib_handle(postalCode, 'value', '', 0, 0).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 =  _proxy_jslib_handle(countryCheckList, (i), 0, 0).split(":");
		if(countryCode==items[0])
			return  _proxy_jslib_handle( _proxy_jslib_handle(countryCheckList, (i), 0, 0), 'toString', '', 1, 0)();
	}
	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 =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('Password');
    var firstname =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('FirstName');
    var lastname =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('LastName');
    var email =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('Email');
    var strPassword = new (String)( _proxy_jslib_handle(Password, 'value', '', 0, 0));
    var flag = true;
    var errMsg = "";
    
    //remove password ele from the errList
	updateErrLists(id, {style: 'signupinput'}, true);
    
    // Password Checker
	if ( _proxy_jslib_handle(Password, 'value', '', 0, 0) =="") {
		errMsg = GetClientString('PasswordErrorMessage');
		flag = false;
	} else if (strPassword.length < 6) {
		errMsg = GetClientString('PasswordErrorMessage');
		flag = false;
	} else if (!strPassword.match(/[0-9!@##\$%\^&\*\(\)\-_\+=\{\}\[\|:;'\?<>\.,~`"]/)) {
		errMsg = GetClientString('PasswordErrorMessage');
		flag = false;
	} else if (!strPassword.match(/[A-Za-z]/)) {
		errMsg = GetClientString('PasswordErrorMessage');
		flag = false;
	} else if ( _proxy_jslib_handle(firstname, 'value', '', 0, 0).length > 2 && strPassword.toUpperCase().lastIndexOf( _proxy_jslib_handle(firstname, 'value', '', 0, 0).toUpperCase()) > -1) {
		errMsg = GetClientString('EmailErrorMessage5');
		flag = false;
	} else if ( _proxy_jslib_handle(lastname, 'value', '', 0, 0).length > 2 && strPassword.toUpperCase().lastIndexOf( _proxy_jslib_handle(lastname, 'value', '', 0, 0).toUpperCase()) > -1) {
		errMsg = GetClientString('PasswordErrorMessage6');
		flag = false;
	} else if ( _proxy_jslib_handle(email, 'value', '', 0, 0).length > 2 && strPassword.toUpperCase().lastIndexOf( _proxy_jslib_handle(email, 'value', '', 0, 0).toUpperCase()) > -1) {
        errMsg = GetClientString('PasswordErrorMessage7');		
		flag = false;
	} else if ( _proxy_jslib_handle(Password, 'value', '', 0, 0).indexOf(" ") >= 0) {
		errMsg = GetClientString('PasswordErrorMessage8');
		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 =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('Password');
    
    if(!pwdEle)
        return result;
    
    if(validate(pwdEle))
    {
        var ele =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(id);
        if(!ele)
            return result;
        if( _proxy_jslib_handle(ele, 'value', '', 0, 0) !=  _proxy_jslib_handle(pwdEle, 'value', '', 0, 0))
        {
            updateErrLists(ele.id, {id:ele.id, msg: _proxy_jslib_handle(valObj, 'body', '', 0, 0), 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 =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(id);
    var prevEmail = GetClientString("PrevEmail");
    
    if( _proxy_jslib_handle(ele, 'value', '', 0, 0) == prevEmail)
    {
        updateErrLists(id, {id:id, msg: _proxy_jslib_handle(valObj, 'body', '', 0, 0), head: valObj.head, style: 'signupinputError'}, false);
		return false; 
    }
    else
    {
        updateErrLists(id, {style: 'signupinput'}, true);
        return true;
    }
}

function ValidateConfEmail(id, valObj) {
    var result = true;
    var emailEle =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('Email');
    
    if(!emailEle)
        return result;
    
    if(validate(emailEle))
    {
        var ele =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(id);
        if(!ele)
            return result;
		
		var email1 =  _proxy_jslib_handle(emailEle, 'value', '', 0, 0).toLowerCase();            
		var email2 =  _proxy_jslib_handle(ele, 'value', '', 0, 0).toLowerCase();            
        if(email1 != email2)
        {
            updateErrLists(ele.id, {id:ele.id, msg: _proxy_jslib_handle(valObj, 'body', '', 0, 0), head:valObj.head, style:'signupinputError'}, false);
            result = false;
        }
        else
            updateErrLists(ele.id, {style: 'signupinput'}, true);
    }
    
    return result;
}

function PreventEmailConfirmPasteByMouse(e) {
	var btnType = 0;
    
    btnType = e.button;
		
	if(btnType == 2 || btnType == 3)
        MustTypeConfirmEmail();
}

function PreventEmailConfirmPasteByKeyboard(e) {	               
	SetCtrlKey(e);
	
	if(e.keyCode == "86" && ctrlKeyCode == "17") //ctrl+v
	{                    
		 _proxy_jslib_assign('', confirmEmailTextBox, 'value', '=', ( ""));
		MustTypeConfirmEmail();
		e.preventDefault();
	}
}

function SetCtrlKey(e) {
	var pressedKeyCode = e.keyCode; 
	if (pressedKeyCode == "17") //ctrl
	{
		ctrlKeyCode = pressedKeyCode;                    
	}	
}

function UnsetCtrlKey(e) {
	var releasedKeyCode = e.keyCode; 
	if (releasedKeyCode == "17") //ctrl
	{
		ctrlKeyCode = 0;                    
	}	
}

//Email End
//Age check
function ValidateAge(id, valObj) {
    var day =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('Day');
    var month =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('Month');
    var year =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(id);
    
    //remove age ele from errList
	updateErrLists(id, {style: ''}, true);
    
    if( _proxy_jslib_handle(day, 'value', '', 0, 0) == -1 ||  _proxy_jslib_handle(month, 'value', '', 0, 0) == -1 ||  _proxy_jslib_handle(year, 'value', '', 0, 0) == -1)
    {
        updateErrLists(id, {id:id, msg:GetClientString('BirthdayErrorMessage'), head: valObj.head, style: ''}, false);
		return false;
    }
    return true;
}
//Age check end
//Gender Start
function ValidateGender(id, valObj) {
    var M =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('genderM');
    var F =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('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 ele = $get('TermsDiv');
    
    if(ele)
    {
        var prefCultureDropDown = $get(id);
        if(prefCultureDropDown)
        {   
            //display secondary disclaimer for ja-JP, ko-KR
            DisplaySecondaryUserAgreement( _proxy_jslib_handle(prefCultureDropDown, 'value', '', 0, 0));
            //display disclaimer for selected pref culture.
             _proxy_jslib_assign('', ele, 'innerHTML', '=', ( GetClientString( _proxy_jslib_handle(prefCultureDropDown, 'value', '', 0, 0))));
        }
    }
}
function DisplaySecondaryUserAgreement(culture) {
    var termsJP = $get('SecondaryTermsJP');
    var termsKR1 = $get('SecondaryTermsKR1');
    var termsKR2 = $get('SecondaryTermsKR2');
    
    if(termsJP)
        termsJP.style.display = "none";
    if(termsKR1)
        termsKR1.style.display = "none";
    if(termsKR2)
        termsKR2.style.display = "none";
    
    //display secondary disclaimer, if pref culture selected is ja-JP or ko-KR 
    if(termsJP && culture === "ja-JP")
    {
         _proxy_jslib_assign('', termsJP, 'value', '=', (  _proxy_jslib_handle(termsJP, 'value', '', 0, 0).trim()));
        termsJP.style.display = "block";
    }
    else if(termsKR1 && termsKR2 && culture === "ko-KR")
    {
         _proxy_jslib_assign('', termsKR1, 'value', '=', (  _proxy_jslib_handle(termsKR1, 'value', '', 0, 0).trim()));
        termsKR1.style.display = "block";
         _proxy_jslib_assign('', termsKR2, 'value', '=', (  _proxy_jslib_handle(termsKR2, 'value', '', 0, 0).trim()));
        termsKR2.style.display = "block";
    }
}
//Preferred Site & Language End

//Terms Start
function ValidateTermsOfUse(id, valObj) {
    var tos =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(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 =  _proxy_jslib_handle(ErrorValidators, (i), 0, 0);
        if( errObj && typeof(errObj) != "undefined" )
        {
            var ele =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(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( _proxy_jslib_handle(null, 'content', content, 0, 0), title, true);
    p.addCssClass('popUp');
    continueButton = p.add_button(continueBtnTitle, false);
    continueButton.disabled = true;
    continueButton.onclick = function() { 
        var v =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('safetytipsread');
        if(!v.checked)
        {
            p.show();
            //alert('please select the checkbox');
            return false;
        }
        return true; 
    }
    p.show();                
}   

function toggleContinueBtn() {
    var v =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('safetytipsread');
    if(v && v.checked)
    {
        continueButton.disabled = false;
    }
    else
    {
        continueButton.disabled = true;
    }
    return continueButton.enabled;
}

//
function openWin(url, title, width, height) {
     _proxy_jslib_handle(window, 'open', '', 1, 0)(url,title,"height="+height+",width="+width+",status=yes,toolbar=no,menubar=no,location=no,resizable=no");
}

function adjustTabHeight(tab1, tab2) {
    var t1 =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(tab1);
    var t2 =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(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";
        }
    }
}

function adjustTabHeight(tab1, tab2, tab3) {
    var t1 =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(tab1);
    var t2 =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(tab2);
    var t3 =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(tab3);

    if(t1 && t2 && t3)
    {
        if(t1.offsetHeight - t2.offsetHeight > 6)
        {
            t2.style.height = "27px";
            t3.style.height = "27px";
        }
        else if(t2.offsetHeight - t1.offsetHeight > 6)
        {
            t3.style.height = "27px";
            t1.style.height = "27px";
        }
        else if(t3.offsetHeight - t1.offsetHeight > 6)
        {
			t2.style.height = "27px";
            t1.style.height = "27px";
        }
    }
}
function ValidateSignupInviteForm(id) {
    //the id passed is the first input box id(could be any id). 
    //and holds the err msgs that are required 
    var eles =  _proxy_jslib_handle(document, 'getElementsByTagName', '', 1, 0)("input");
    if(!eles)
        return;
        
    var isValid = true;    
    var errEle = null;
    var valType = null;
    var emptyEleCount = 0;
    var eleCount = 0;
    var firstEleIndex = null;
    
    for(var i =0; i < eles.length; i++)
    {
        if( _proxy_jslib_handle(eles, (i), 0, 0).className === "signupinput2" ||  _proxy_jslib_handle(eles, (i), 0, 0).className === "signupinput2 signupinput2error")
        {
            if(!firstEleIndex)
                firstEleIndex = i;
            //count the number of email inputs
            eleCount++;

            //clear prev errs
            updateErrLists( _proxy_jslib_handle(eles, (i), 0, 0).id, {style:'signupinput2'}, true);
            
            if( _proxy_jslib_handle( _proxy_jslib_handle(eles, (i), 0, 0), 'value', '', 0, 0).length == 0)         
                emptyEleCount++; //count number of empty inputs
    
            //validate email(s) entered
            if( _proxy_jslib_handle( _proxy_jslib_handle(eles, (i), 0, 0), 'value', '', 0, 0).length > 0 && !emailRegex.test( _proxy_jslib_handle( _proxy_jslib_handle(eles, (i), 0, 0), 'value', '', 0, 0)))      
            {
                valType = "regex";
                errEle =  _proxy_jslib_handle(eles, (i), 0, 0);
                isValid = false;
                //break out of the loop if there's invalid input
                break;
            }
        }
    }
    
    //if all the inputs are empty show err msg for the first input
    if(errEle == null && emptyEleCount == eleCount)
    {
        errEle =  _proxy_jslib_handle(eles, (firstEleIndex), 0, 0);
        valType = "required";
        isValid = false;
    }   
    
    //get all validation objs for these inputs
    //Note: as all the text boxes had same type of validations and need to display same err msgs,
    //stored all the validation objects under one id(the first text box) so that they can be used for all validations.
    var valObjs = GetValidationObj($get(id));
    var valObj = null;
    
    for(var i = 0; i < valObjs.length; i++)
    {
        if( _proxy_jslib_handle(valObjs, (i), 0, 0).type === valType)
        {
            valObj =  _proxy_jslib_handle(valObjs, (i), 0, 0);
            break;
        }
    }
    
    if(errEle && valObj)
    {
        updateErrLists(errEle.id, {id:errEle.id, msg: _proxy_jslib_handle(valObj, 'body', '', 0, 0), head:valObj.head, style: valObj.style}, false);
    }
    
    return isValid;
}


// setting the webservice path
// This method also sets the handler that will be invoked before making reqests
// Sets handler to unload the eventhandlers
function setServicePath(wsPath) {
	MySpace.Web.Modules.Signup.Services.SignupService.set_path(wsPath);
} ;
_proxy_jslib_flush_write_buffers() ;