

function refreshCaptica(id){
	var obj = document.getElementById(id);
		var src = obj.src;
		var pos = src.indexOf('?');
   if (pos >= 0) {
      src = src.substr(0, pos);
   }
   var date = new Date();
   obj.src = src + '?v=' + date.getTime();
   return false;
}




function textCounter(field,counter,maxlimit,linecounter) {
	// text width//
	var fieldWidth =  parseInt(field.offsetWidth);
	var charcnt = field.value.length;        

	// trim the extra text
	if (charcnt > maxlimit) { 
		field.value = field.value.substring(0, maxlimit);
	}

	else { 
	// progress bar percentage
	var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
	document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
	document.getElementById(counter).innerHTML="Limit: "+percentage+"%"
	// color correction on style from CCFFF -> CC0000
	setcolor(document.getElementById(counter),percentage,"background-color");
	}
}

function setcolor(obj,percentage,prop){
	obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}
var xmlHttp;
function createXmlHttpObject(){
if (window.XMLHttpRequest){     // Object of the current windows
    xmlHttp = new XMLHttpRequest();     // Firefox, Safari, ...
   } 
   else if (window.ActiveXObject){   // ActiveX version
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");  // Internet Explorer 
    } 
  return xmlHttp;
 }

xmlHttp=createXmlHttpObject();


function callMethod(obj)
{

	var countryID=obj.value;
	if(countryID != 2){	
		document.getElementById('hr').style.display='none';
		document.getElementById('hr1').style.display='inline';
	}	
	else
	{
		document.getElementById('hr1').style.display='none';
		document.getElementById('hr').style.display='inline';
	}
}
function notValidEmail( str ){
    mailRE = new RegExp( );
    mailRE.compile( '^[\._a-z0-9-]+@[\.a-z0-9-]+[\.]{1}[a-z]{2,4}$', 'gi' );
    return !(mailRE.test( str.value ));
}
var flag = 1;
var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
var iInt = "0123456789";
function validateRegistrationForm()
{
	 document.getElementById("wholeDiv").style.backgroundColor="";
	document.getElementById("overlayuserID1").style.backgroundColor="";
	document.getElementById("overlayuserID2").style.backgroundColor="";
	document.getElementById("overlaypassword2").style.backgroundColor="";
	document.getElementById("overlaypassword1").style.backgroundColor="";
    document.getElementById("rePassword1").style.backgroundColor="";
    document.getElementById("rePassword2").style.backgroundColor="";
    document.getElementById("fullName1").style.backgroundColor="";
	document.getElementById("fullName2").style.backgroundColor="";
	document.getElementById("legalName1").style.backgroundColor="";
	document.getElementById("legalName2").style.backgroundColor="";
	document.getElementById("dob1").style.backgroundColor="";
	document.getElementById("hr1").style.backgroundColor="";
	document.getElementById("DOBDate").style.backgroundColor="";
	document.getElementById("DOBMonth").style.backgroundColor="";
	document.getElementById("dob1").style.backgroundColor="";
	document.getElementById("DOBYear").style.backgroundColor="";
    document.getElementById("dob1").style.backgroundColor="";
    document.getElementById("sex2").style.backgroundColor="";
	document.getElementById("sex1").style.backgroundColor="";
	document.getElementById("location2").style.backgroundColor="";
    document.getElementById("location1").style.backgroundColor="";
    document.getElementById("location2").style.backgroundColor="";
	document.getElementById("hr").style.backgroundColor="";
	document.getElementById("City").style.backgroundColor="";
    document.getElementById("captcha").style.backgroundColor="";
	document.getElementById("captcha1").style.backgroundColor="";
	document.getElementById("agreement").style.backgroundColor="";
	document.getElementById("verifyImageText").style.backgroundColor="";
	document.getElementById("zipCode").style.backgroundColor="";
	
   if(document.getElementById('userIDRegistration').value=="" || document.getElementById('userIDRegistration').value=="abc@xyz.com")
	{
	
	    document.getElementById('errorBox').innerHTML = 'Please specify userID';
	    document.getElementById("overlayuserID1").style.backgroundColor="#e7ea9c";
	    document.getElementById("overlayuserID2").style.backgroundColor="#e7ea9c";
		document.userMaster.userID.focus();
		
		return false;
	}
	else{
		if(iInt.indexOf(document.getElementById('userIDRegistration').value.charAt(0)) == 1){
			document.getElementById('errorBox').innerHTML = "First character can't numeric in UserID";
			document.getElementById("overlayuserID1").style.backgroundColor="#e7ea9c";
			document.getElementById("overlayuserID2").style.backgroundColor="#e7ea9c";
		//alert("First character can't numeric in UserID");
		document.userMaster.userID.focus();
		return false;
		 }
		if(document.getElementById('userIDRegistration').value.indexOf(" ") >= 0){
		//alert("Spaces not Allowed in UserID");
		document.getElementById('errorBox').innerHTML = "Spaces not Allowed in UserID";
		document.userMaster.userID.focus();
		document.getElementById("overlayuserID1").style.backgroundColor="#e7ea9c";
		document.getElementById("overlayuserID2").style.backgroundColor="#e7ea9c";
		return false;
		}
	
		/*	for (var i = 0; i < document.userMasterBean.userID.value.length; i++) {
			  	if (iChars.indexOf(document.userMasterBean.userID.value.charAt(i)) != -1) {
			  		document.getElementById("overlayuserID1").style.backgroundColor="#e7ea9c";
					document.getElementById("overlayuserID2").style.backgroundColor="#e7ea9c";
					document.getElementById('errorBox').innerHTML = "Your username has special characters. \nThese are not allowed.\n Please remove them and try again.";
			  	//alert ("Your username has special characters. \nThese are not allowed.\n Please remove them and try again.");
			  	document.userMasterBean.userID.focus();
			  	return false;
			  	}
		  }  */
	}
   if(notValidEmail(document.getElementById('userIDRegistration'))){
       //alert( "<bean:message key="errorMsg.emailAddress"/>");
       document.getElementById('errorBox').innerHTML = "EMail Address is not Valid.";
       document.getElementById("overlayuserID1").style.backgroundColor="#e7ea9c";
		document.getElementById("overlayuserID2").style.backgroundColor="#e7ea9c";
       document.userMaster.userID.focus();
       return false;
   }
   if(document.getElementById('userIDRegistration').value.length > 50)
   {
	   document.getElementById('errorBox').innerHTML = "EMail Address can not be more than 50 characters.";
       document.getElementById("overlayuserID1").style.backgroundColor="#e7ea9c";
		document.getElementById("overlayuserID2").style.backgroundColor="#e7ea9c";
       document.userMaster.userID.focus();
       return false;
   }


	if(document.getElementById('userPassword').value=="" || document.getElementById('userPassword').value=="**********")
	{
		//alert("Please enter password.");
		  document.getElementById('errorBox').innerHTML = "Please enter password.";
		 document.getElementById("overlaypassword2").style.backgroundColor="#e7ea9c";
		document.getElementById("overlaypassword1").style.backgroundColor="#e7ea9c";
		
		document.getElementById('userPassword').focus();
		return  false;
	}
	
	if(document.getElementById('userPassword').value.length < 6)
	{
		document.getElementById('errorBox').innerHTML = "Password should be more then six charactors";
		//alert("Password should be more then six charactor");
		document.getElementById("overlaypassword2").style.backgroundColor="#e7ea9c";
		document.getElementById("overlaypassword1").style.backgroundColor="#e7ea9c";
		document.getElementById('userPassword').focus();

		return  false;
	}
       
	 if(document.getElementById('userPassword').value.length > 20)
	   {
		 document.getElementById('errorBox').innerHTML = "Password should be not more then Twenty charactors";
			//alert("Password should be more then six charactor");
			document.getElementById("overlaypassword2").style.backgroundColor="#e7ea9c";
			document.getElementById("overlaypassword1").style.backgroundColor="#e7ea9c";
			document.getElementById('userPassword').focus();
			return  false;
	   }
	
	if(document.getElementById('userRePassword').value=="" || document.getElementById('userRePassword').value=="**********")
	{
		//alert('Please confirm password')
	  document.getElementById('errorBox').innerHTML = "Please confirm password";
	 document.getElementById("rePassword1").style.backgroundColor="#e7ea9c";
	document.getElementById("rePassword2").style.backgroundColor="#e7ea9c";
			
	  document.getElementById('userRePassword').focus();
	  return false;
	 }
	if(document.getElementById('userRePassword').value != document.getElementById('userPassword').value)
	{
        //alert("Re-typed Password doesn't match with the Password.")
		document.getElementById('errorBox').innerHTML = "Re-typed Password doesn't match with the Password.";
		
		 document.getElementById("rePassword1").style.backgroundColor="#e7ea9c";
			document.getElementById("rePassword2").style.backgroundColor="#e7ea9c";
		document.getElementById('userRePassword').focus();
		return false;
	}
	if(document.getElementById('fullName').value=="" || document.getElementById('fullName').value=='Full Name')
	{
		//alert("Please enter Full Name.")
	  document.getElementById('errorBox').innerHTML = "Please enter Full Name.";
		document.getElementById("fullName1").style.backgroundColor="#e7ea9c";
		document.getElementById("fullName2").style.backgroundColor="#e7ea9c";
	 document.getElementById('fullName').focus();
	  return false;
	 }

    if(document.getElementById('fullName').value > 50)
    {
    	 document.getElementById('errorBox').innerHTML = "Full Name can not be more than 50 characters.";
 		 document.getElementById("fullName1").style.backgroundColor="#e7ea9c";
 		 document.getElementById("fullName2").style.backgroundColor="#e7ea9c";
 	     document.getElementById('fullName').focus();
 	     return false;
    }

	


	if(document.getElementById('legalName').value > 50)
	{
		document.getElementById('errorBox').innerHTML = "Screen Name can not be more than 50 characters.";
	    document.getElementById("legalName1").style.backgroundColor="#e7ea9c";
		document.getElementById("legalName2").style.backgroundColor="#e7ea9c";
	    document.getElementById('legalName').focus();
	    return false;
	}
    if(!isString(document.getElementById('fullName')))
    {
    	 document.getElementById('errorBox').innerHTML = "Please enter Valid Name.";
 		document.getElementById("fullName1").style.backgroundColor="#e7ea9c";
 		document.getElementById("fullName2").style.backgroundColor="#e7ea9c";
 	  document.getElementById('fullName').focus();
 	  return false;
    }
  //  alert('Hi...' + isString(document.userMasterBean.legalName))
	 
	if(document.getElementById('DOBDate').value==-1)
	{
		//alert("Please select date")
	  document.getElementById('errorBox').innerHTML = "Please select date";
		document.getElementById("dob1").style.backgroundColor="#e7ea9c";
		document.getElementById("DOBDate").style.backgroundColor="#e7ea9c";
		
	  document.getElementById('DOBDate').focus();
	  return false;
	 }
	if(document.getElementById('DOBMonth').value==-1)
	{
		//alert("Please select month of Birth")
	  document.getElementById('errorBox').innerHTML = "Please select month of Birth";
		document.getElementById("DOBMonth").style.backgroundColor="#e7ea9c";
		document.getElementById("dob1").style.backgroundColor="#e7ea9c";
	  document.getElementById('DOBMonth').focus();
	  return false;
	 }
	if(document.getElementById('DOBYear').value==-1)
	{
		 document.getElementById('errorBox').innerHTML = "Please select year of Birth";
		 //alert("Please select year of Birth")
		 
		 document.getElementById("DOBYear").style.backgroundColor="#e7ea9c";
		 document.getElementById("dob1").style.backgroundColor="#e7ea9c";
	  document.getElementById('DOBYear').focus();
	  return false;
	 }

	 if(!isDate(document.getElementById('DOBMonth').value+'/'+document.getElementById('DOBDate').value+'/'+document.getElementById('DOBYear').value))
	 {
		 
		 document.getElementById("dob1").style.backgroundColor="#e7ea9c";
		 document.getElementById("wholeDiv").style.backgroundColor="#e7ea9c";
		/* document.getElementById("DOBDate").style.backgroundColor="#e7ea9c";
		 document.getElementById("DOBYear").style.backgroundColor="#e7ea9c";
		 document.getElementById("DOBMonth").style.backgroundColor="#e7ea9c";*/
		 document.getElementById('errorBox').innerHTML = "Please enter Valid Date.";
		
		 
		 return false;
	 }
	if(document.getElementById('male').value ==false && document.getElementById('female').value==false)
	{
		//alert("Please select Sex")
		 document.getElementById('errorBox').innerHTML = "Please select Sex";
		document.getElementById("sex2").style.backgroundColor="#e7ea9c";
		 document.getElementById("sex1").style.backgroundColor="#e7ea9c";
		  return false;
	}
    // alert(document.getElementById('location1').value)
	if(document.getElementById('location1').value==0)
	{
		//alert('Please select Country')
	  document.getElementById('errorBox').innerHTML = "Please select Country";
		document.getElementById("location2").style.backgroundColor="#e7ea9c";
		 document.getElementById("location1").style.backgroundColor="#e7ea9c";
	  document.getElementById('location1').focus();
	  return false;
	 }
	if((document.getElementById('hr1').style.display=='none' && document.getElementById('hr').style.display=='none') && document.getElementById('location1').value !=-1)
	{
		document.getElementById('errorBox').innerHTML = "Please Enter State.";
		document.getElementById("location2").style.backgroundColor="#e7ea9c";
		 document.getElementById("hr1").style.backgroundColor="#e7ea9c";
		//alert("Please Enter State.")
		document.getElementById('hr1').focus();
		return false;
	 }
	
	if(document.getElementById('hr').style.display=='inline')
	{
		if(document.getElementById('hr').value==0)
		{
			//alert('Please Select State.')
			
			document.getElementById("location2").style.backgroundColor="#e7ea9c";
			 document.getElementById("hr").style.backgroundColor="#e7ea9c";
			document.getElementById('errorBox').innerHTML = "Please Select State.";
			return false;
		}
	}
		
   if(document.getElementById('City').value.length >= 1)
   {
	   for (var i = 0; i < document.getElementById('City').value.length; i++) {
		  	if (iChars.indexOf(document.getElementById('City').value.charAt(i)) != -1) {
		  		document.getElementById("City").style.backgroundColor="#e7ea9c";
		  	document.getElementById('errorBox').innerHTML ="City has special characters. Please remove them and try again.";
		  	return false;
		  	}
	   }
   }
	if(document.getElementById('City').value.length > 30)
	{
		//alert("Please enter City.")
		document.getElementById('errorBox').innerHTML = "City Name can not be more than 30 characters.";
		document.getElementById("City").style.backgroundColor="#e7ea9c";
		// document.getElementById("city1").style.backgroundColor="#e7ea9c";
		 document.getElementById('City').focus();
		 return false;
	}
	if(document.getElementById('zipCode').value.length >= 1 && document.getElementById('zipCode').value != 'Pin Code')
	{
     	if(!isNumeric(document.getElementById('zipCode').value))
	    {
		//alert("Please enter numeric digits.")
	     	document.getElementById('errorBox').innerHTML = "Please enter numeric digits.";
		    document.getElementById("zipCode").style.backgroundColor="#e7ea9c";
		    document.userMasterBean.zipCode.focus();
		    return false;
	    }
	    if(document.getElementById('zipCode').value.length > 6)
	    {
		//alert("Please enter Pin Code.")
		      document.getElementById('errorBox').innerHTML = "Pin Code can not be more than six digits.";
	        	document.getElementById("zipCode").style.backgroundColor="#e7ea9c";
		     document.getElementById('zipCode').focus();
		      return false;
	     }
	}
	if(document.getElementById('verifyImageText').value=='' || document.getElementById('verifyImageText').value=='Verification Code')
	{
		//alert("Please select Verification Code");
		document.getElementById("captcha").style.backgroundColor="#e7ea9c";
		 document.getElementById("captcha1").style.backgroundColor="#e7ea9c";
		 document.getElementById("verifyImageText").style.backgroundColor="#e7ea9c";
		 
	
		
		document.getElementById('errorBox').innerHTML = 'Please enter the correct verification code';  
		document.getElementById('verifyImageText').focus();
		 return false;
	}

	if(document.getElementById('agree').checked == true)
	{
		if(document.getElementById('legalName').value == 'Screen Name')
			document.getElementById('legalName').value = document.getElementById('fullName').value;

		
		verifyCaptcha(document.getElementById('userMasterBean'));
		
		
		
		
	/*	if(boolCheckCaptcha() == 'OK')
		{
		     if(document.getElementById('flag').value == "SET")
		     {  
			       document.getElementById('methodName').value = 'checkCaptchaNdUserId';
			       document.userMasterBean.action="/firststep.do";
		           document.getElementById('userMasterBean').submit();
		     }
		     else
		     {
			       document.getElementById('methodName').value = 'newRegister';
			       document.userMasterBean.action="/newLogin.do";
		          document.getElementById('userMasterBean').submit();
		     }
		}*/
	}
	else
	{
		
		document.getElementById("agreement").style.backgroundColor="#e7ea9c";
		//alert('Please accept the terms and condition.')
		document.getElementById('errorBox').innerHTML = "Please accept the terms and condition.";
	}
}

function isNumeric(value) {
	  if (value != null && !value.toString().match(/^[-]?\d*\.?\d*$/)) return false;
	  return true;
	}


function isString(textObj) {
	   var newValue = textObj.value;
	   var newLength = newValue.length;
	   var extraChars=". -,";

	   var search;
	   for(var i = 0; i != newLength; i++) {
	      aChar = newValue.substring(i,i+1);
	      aChar = aChar.toUpperCase();
	      search = extraChars.indexOf(aChar);
	      if(search == -1 && (aChar < "A" || aChar > "Z") ) {
	         return false;
	      }
	   }
	   return true;
	}


function isDate(txtDate) {
    var objDate,  // date object initialized from the txtDate string
        mSeconds, // txtDate in milliseconds
        day,      // day
        month,    // month
        year;     // year
    // date length should be 10 characters (no more no less)
    if (txtDate.length !== 10) {
        return false;
    }
    // third and sixth character should be '/'
    if (txtDate.substring(2, 3) !== '/' || txtDate.substring(5, 6) !== '/') {
        return false;
    }
    // extract month, day and year from the txtDate (expected format is mm/dd/yyyy)
    // subtraction will cast variables to integer implicitly (needed
    // for !== comparing)
    month = txtDate.substring(0, 2) - 1; // because months in JS start from 0
    day = txtDate.substring(3, 5) - 0;
    year = txtDate.substring(6, 10) - 0;
    // test year range
    if (year < 1000 || year > 3000) {
        return false;
    }
    // convert txtDate to milliseconds
    mSeconds = (new Date(year, month, day)).getTime();
    // initialize Date() object from calculated milliseconds
    objDate = new Date();
    objDate.setTime(mSeconds);
    // compare input date and parts from Date() object
    // if difference exists then date isn't valid
    if (objDate.getFullYear() !== year ||
        objDate.getMonth() !== month ||
        objDate.getDate() !== day) {
        return false;
    }
    // otherwise return true
    return true;
}

function logoutFromGS1() {
	
    gigya.services.socialize.logout(conf, {/*no required params*/}); // logout from Gigya platform
}




 function onLoadGigya() {
		   
	        // get user info
	        gigya.services.socialize.getUserInfo(conf, { callback: renderUILogin1 });

	        // register for connect status changes
	        gigya.services.socialize.addEventHandlers(conf,
                            { onConnectionAdded: renderUILogin1, onConnectionRemoved: renderUILogin1 });

	    }
  
        function renderUILogin1(res) {
		if (res.user != null && res.user.isConnected) {
		    document.getElementById('Method').value = "checkUserExistence";
		    document.getElementById('userID').value = res.user.email;
		    document.getElementById('password').value = ''; 
		    document.loginForm.submit();
		}          
        }	    
	

    function onLoad() {
            // register for login event
            gigya.services.socialize.addEventHandlers(conf, {
					context: { str: 'congrats on your' }
					, onLogin: onLoginHandler 
					, onLogout: onLogoutHandler
					});
              
               if(i==1)
               {
                   i++;
                   onLoad();
               }
               
               document.getElementById('lightnew').style.display = 'block';
           	document.getElementById('fade').style.display = 'block';
          
            
        }

        function renderUI(res) {
           
            i=0;
         
            //alert(res.user.gender)
            if (res.user != null && res.user.isConnected) {
               // document.getElementById("name").innerHTML = res.user.nickname;
               document.getElementById("flag").value = "SET";
                document.getElementById("fullName").value = res.user.nickname;
                document.getElementById("legalName").value = res.user.nickname;
                
             //   document.getElementById("gender").innerHTML = res.user.gender;
                
                if(res.user.gender=='m' || res.user.gender=='M')
                	document.getElementById("male").checked = true;
                else
                	document.getElementById("female").checked = true;
                	
             //   document.getElementById("age").innerHTML = res.user.age;
                
           //     document.getElementById("birthDay").innerHTML = res.user.birthDay;
                document.getElementById("DOBDate").value = res.user.birthDay;
                
         //       document.getElementById("birthMonth").innerHTML = res.user.birthMonth;
                document.getElementById("DOBMonth").value = res.user.birthMonth;
                
        //        document.getElementById("birthYear").innerHTML = res.user.birthYear;
                document.getElementById("DOBYear").value = res.user.birthYear;
                
          //      document.getElementById("email").innerHTML = res.user.email;
                document.getElementById("userIDRegistration").value = res.user.email;
               
                
        //        document.getElementById("country").innerHTML = res.user.country;

                
        //        document.getElementById("state").innerHTML = res.user.state;
                
                
      //          document.getElementById("city").innerHTML = res.user.city;
                document.getElementById("City").value = res.user.city;

              
         //       document.getElementById("zip").innerHTML = res.user.zip;
                document.getElementById("zipCode").value= res.user.zip;
                
               // Hiding the div when user is from social site
                document.getElementById('lightnew').style.display = 'none';
                
                document.getElementById('methodName').value = 'saveUserFromSocialSite';
			       document.userMasterBean.action="/newLogin.do";
		           document.userMasterBean.submit();
    
              
                //document.getElementById("profile").style.display = "block";
            } 

            //alert('elements in form are========'+document.forms[0].length)
        }	  


function onload1()
{// alert(document.referrer);
//alert(window.history.previous);
//alert(window.history.next);
	
	document.getElementById('lightnew').style.display='block';
	document.getElementById('fade').style.display='block';
	
}



function validateLogIn(formObj)
{
	
	  var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
       var iInt = "0123456789";
                   document.getElementById("userID1").style.backgroundColor="";
			document.getElementById("userID2").style.backgroundColor="";

	 if(document.getElementById('userIDLogin').value == "" || document.getElementById('userIDLogin').value == "abc@xyz.com")
		{
			//alert('Please specify userID')
			document.getElementById('errorText').innerHTML = 'Please specify userID';
			document.getElementById("userID1").style.backgroundColor="#e7ea9c";
			document.getElementById("userID2").style.backgroundColor="#e7ea9c";
			document.getElementById('userIDLogin').focus();
			return false;
		}
	 else{
			if(iInt.indexOf(document.getElementById('userIDLogin').value.charAt(0)) == 1){
				document.getElementById('errorText').innerHTML = "First character can't numeric in UserID";
				document.getElementById("userID1").style.backgroundColor = "#e7ea9c";
				document.getElementById("userID2").style.backgroundColor = "#e7ea9c";
			//alert("First character can't numeric in UserID");
			document.getElementById('userIDLogin').focus();
			return false;
			 }
			if(document.getElementById('userIDLogin').value.indexOf(" ") >= 0){
			//alert("Spaces not Allowed in UserID");
			document.getElementById('errorText').innerHTML = "Spaces not Allowed in UserID";
			document.getElementById('userIDLogin').focus();
			document.getElementById("userID1").style.backgroundColor = "#e7ea9c";
			document.getElementById("userID2").style.backgroundColor = "#e7ea9c";
			return false;
			}
		
			
	   
		if(document.getElementById('loginPassword').value=="" || document.getElementById('loginPassword').value=="**********")
		{
			//alert("Please enter password.");
			  document.getElementById('errorText').innerHTML = "Please enter password.";
			 document.getElementById("password2").style.backgroundColor="#e7ea9c";
			document.getElementById("password1").style.backgroundColor="#e7ea9c";
			
			document.getElementById('loginPassword').focus();
			return  false;
		}
		
		/*if(flag == '')
		{
			document.getElementById('loginForm').submit();
		}*/
		
			  var url = '/newLogin.do?'
             for(var i = 0 ; i < formObj.length ; i++)
             {
	              url = url + formObj.elements[i].name + '=' + formObj.elements[i].value;
	              url = url + '&';
	         }
			
			
			newLoginFromAjax(url);
		
    }
}
function newLoginFromAjax(url) {	
	
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	req.open("POST", url, true);
	
	req.onreadystatechange = getResponseOfNewLogin;
	
	req.send(null);	
	
 }

function getResponseOfNewLogin() {
	
	if (req.readyState == 4) {
		
		if (req.status == 200) {
			
			var text = req.responseText;
			
			
			if(text=='true'){
				
				
				
				var sitename=document.location.href;
              var words=sitename.indexOf(".shtml");
              if(words > 0 )
          {
    	  words = sitename.substring(sitename.lastIndexOf("/")+1,sitename.lastIndexOf("."));
    	 
    	  checkUserCommentForArticle(words);
          }
				
				if(document.getElementById('overlayFlag') != null)
				{
					document.getElementById('overlayFlag').value = 'true';
/*					if(document.getElementById('collegeValue') != null)
						 verifyCollege(document.getElementById('collegeValue').value);  */
				}
				

				document.getElementById('light2').style.display = 'none';
				document.getElementById('fade2').style.display = 'none';
				document.getElementById('signIn').style.display = 'none';
				document.getElementById('signOut').style.display = 'block';
				// getLoginCJPoints();
			}
			else
			{
				document.getElementById('errorText').innerHTML = 'Username and Password is incorrect.'
			}
			
		}
	}
}
function getLoginCJPoints() {	
	var url = "/newLogin.do?Method=getLoginCJPoints";
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	req.open("POST", url, true);
	req.onreadystatechange = userPointsStatus;
	req.send(null);	
	
 }

function userPointsStatus() {
	if (req.readyState == 4) {
		if (req.status == 200) {
			if(req.responseText != 'false')
			{
				if(document.getElementById('pointId') != null)
				{
				    document.getElementById('pointId').style.display='block';
				    document.getElementById('pointId').innerHTML = req.responseText;
				}
			}	
		}
	}
}
function isUserLogin() {	
	var url = "/newLogin.do?Method=isUserLogin";
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	req.open("POST", url, true);
	req.onreadystatechange = userLoginStatus;
	req.send(null);	
	
 }

function userLoginStatus() {
	
	if (req.readyState == 4) {
		
		if (req.status == 200) {
			if(req.responseText == 'true')
			{
				document.getElementById('signOut').style.display='block';
			    document.getElementById('signIn').style.display='none';
			}	
			else
			{
				document.getElementById('signOut').style.display='none';
			    document.getElementById('signIn').style.display='block';
			}
		}
	}
}
function verifyCollege(collegeID) {	
	
	var url = "/newLogin.do?Method=isCjOfThisCollege&collegeId=" + collegeID;
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	req.open("POST", url, true);
	
	req.onreadystatechange = getCollege;
	
	req.send(null);	
	
 }


function getCollege() {
		
		if (req.readyState == 4) {
			
			if (req.status == 200) {
				var text = req.responseText;
				
				if(text=='true'){
					document.getElementById('isCjOfCollegeFlag').value = 'true';
				    document.getElementById('light13').style.display='block';
		    	    document.getElementById('fade13').style.display='block';
				}
				else
				{
					document.getElementById('isCjOfCollegeFlag').value = 'false';
				}
			}
		}
}


function checkUserCommentForArticle(articleId) {	
	
	var url = "/commentSave.do?method=checkUserExistInComment&articleId="+articleId;

	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	req.open("POST", url, true);
	
	req.onreadystatechange = newCommentForArticle;
	
	req.send(null);	
	
 }


function newCommentForArticle() {
		
		if (req.readyState == 4) {
			
			if (req.status == 200) {
				var text = req.responseText;				
				
				var words=text.split("??") 
				for (i=0; i<(words.length-1); i++)			{ 
					
						
						document.getElementById(words[i]).style.display='none';
				}
				
				
				
			}
		}
}

function notValidEmail( str ){
    mailRE = new RegExp( );
    mailRE.compile( '^[\._a-z0-9-]+@[\.a-z0-9-]+[\.]{1}[a-z]{2,4}$', 'gi' );
    return !(mailRE.test( str.value ));
}

// Gigya Code............
var i = 1;

var conf=
{
	APIKey: '2_cGGdB4SGj6qs5RmWGaOSbQtlqt-rdBico0QvaVjbW21LOW3_lM4i2EBBA8OYo2eF'
	,enabledProviders: 'facebook,yahoo,google'
}

 function onLoad() {
            gigya.services.socialize.addEventHandlers(conf, {
					context: { str: 'congrats on your' }
					, onLogin: onLoginHandler 
					, onLogout: onLogoutHandler
					});
              
               if(i==1)
               {
                   i++;
                   onLoad();
               }
               
               document.getElementById('lightnew').style.display = 'block';
           	document.getElementById('fade').style.display = 'block';
          
            
        }

        function renderUI(res) {
            i=0;
            if (res.user != null && res.user.isConnected)
            {
                 document.getElementById("flag").value = "SET";
                 document.getElementById("fullName").value = res.user.nickname;
                 document.getElementById("legalName").value = res.user.nickname;
                 
                 if(res.user.gender=='m' || res.user.gender=='M')
                	document.getElementById("male").checked = true;
                else
                	document.getElementById("female").checked = true;
                	
                document.getElementById("DOBDate").value = res.user.birthDay;
                document.getElementById("DOBMonth").value = res.user.birthMonth;
                document.getElementById("DOBYear").value = res.user.birthYear;
                document.getElementById("userIDRegistration").value = res.user.email;
                document.getElementById("City").value = res.user.city;
                document.getElementById("zipCode").value= res.user.zip;
                document.getElementById('lightnew').style.display = 'none';
                document.getElementById('methodName').value = 'saveUserFromSocialSite';
			    document.getElementById('userMasterBean').action="/newLogin.do";
		        document.getElementById('userMasterBean').submit();
             } 
           }	  

        function onLoginHandler(eventObj) {	
            document.getElementById('socialSiteName').value = eventObj.provider;
            verifyTheSignature(eventObj.UID, eventObj.timestamp, eventObj.signature);
            var newUser = true; 
            if (newUser) {
                 var dateStr = Math.round(new Date().getTime()/1000.0); 
			     var siteUID = 'uTtCGqDTEtcZMGL08w'; 
                 var yourSig = createSignature(siteUID, dateStr);
                 var params = {
                    siteUID: siteUID, 
                    timestamp:dateStr,
					cid:'',
                    signature:yourSig
                 };
                 gigya.services.socialize.notifyRegistration(conf, params);
            }

			document.getElementById('lightnew').style.display='block';
			document.getElementById('fade').style.display='block' ;
			gigya.services.socialize.getUserInfo(conf, { callback: renderUI });
            gigya.services.socialize.addEventHandlers(conf,
                            { onConnectionAdded: renderUI, onConnectionRemoved: renderUI });
	 }

        function createSignature(UID, timestamp) {
			encodedUID = encodeURIComponent(UID); // encode the UID parameter before sending it to the server.
												// On server side use decodeURIComponent() function to decode an encoded UID
            return '';
        }
		

        function verifyTheSignature(UID, timestamp, signature) {
			encodedUID = encodeURIComponent(UID); // encode the UID parameter before sending it to the server.
												// On server side use decodeURIComponent() function to decode an encoded UID
           
        }
         
		function logoutFromGS() {
			
            gigya.services.socialize.logout(conf, {/*no required params*/}); // logout from Gigya platform
        }
		
		// onLogout Event handler
        function onLogoutHandler(eventObj) {
			document.getElementById('status').style.color = "red";
			document.getElementById('status').innerHTML = "Status: You are now signed out";
		}
        
       function onload1()
       {
	        document.getElementById('lightnew').style.display='block';
	        document.getElementById('fade').style.display='block';	
       }


       function getPrevious()
       {
	        if(document.referrer==null || document.referrer=="")
	        {
	        	document.forms[0].action="/index.shtml";
	        	document.forms[0].submit();
	        }
	        else
	        {
	        	document.forms[0].action=document.referrer;
	        	document.forms[0].submit();
	        }
       }
       
       
    // Gigya Code For Login 

       
       function onLoadGigya() {
	        // get user info
	        gigya.services.socialize.getUserInfo(conf, { callback: renderUILogin });

	        // register for connect status changes
	        gigya.services.socialize.addEventHandlers(conf,
                           { onConnectionAdded: renderUILogin, onConnectionRemoved: renderUILogin });

	    }
   
       function renderUILogin(res) {
    	  
		if (res.user != null && res.user.isConnected) {
			
		    document.getElementById('Method').value = "checkUserExistence";
		   document.getElementById('userIDLogin').value = res.user.email;
		    document.getElementById('loginPassword').value = ''; 
		    var url = '/newLogin.do?'
		    var formObj =document.getElementById('loginForm');
	             for(var i = 0 ; i < formObj.length ; i++)
	             {
		              url = url + formObj.elements[i].name + '=' + formObj.elements[i].value;
		              url = url + '&';
		         }				
				newLoginFromAjax(url);
		}          
       }	    

