﻿window.onload=bindoldimage;
function bindoldimage()
{
    if(document.getElementById('ctl00_c_NewUserResistration1_HidToBindimgOldID')!=null)
    {
    if(document.getElementById('ctl00_c_NewUserResistration1_HidToBindimgOldID').value!="-1")
    {
     $get('imgNewID').value=document.getElementById('ctl00_c_NewUserResistration1_HidToBindimgOldID').value;
     $get('imgOldID').value=document.getElementById('ctl00_c_NewUserResistration1_HidToBindimgOldID').value;
      $get('imageVal').src='UploadedFiles/UserImage/Thumbnail/'+$get('imgNewID').value;
        $get('imageVal').style.display='block';       
        $get('imageButton').style.display='none';
        $get('cancelImage').style.display='block';
    }
    }
}


function CancelFile1(path)
{
    var file = $get('imgNewID').value;
    var URL="MainWebservice.cs/SingleCancelFile?tm="+new Date().getTime();
    var values= '{"path":"'+path+'","file":"'+file+'"}';
    AjaxCall(URL,values,ONS_CancelFile1);

//admin/adminservice.SingleCancelFile(path,file,ONS_CancelFile1);
}
function ONS_CancelFile1()
{
    $get('imageVal').src='';
    $get('imageVal').style.display='none';
    $get('imgNewID').value='-1';
    $get('imageButton').style.display='block';
    $get('cancelImage').style.display='none';
}
function UploadFile1(path)
{
  var type=1;
 
 
    $get('ifd').src= 'ImageUploader.aspx?path='+path+'&type='+type;
   
    $get('imgUploadDiv').style.display='block';
}

function showLoader()
  {
    document.getElementById('loaddiv').style.display="block";
  }
  function HideLoader()
  {
    document.getElementById('loaddiv').style.display="none";
  }
  var usernme;
  var pass;
function UserRegistration()
{
var val=""
showLoader();
val=ValidteRegistration()
if (val==0)
{
    var firstName=document.getElementById('FnameText').value;
    var secondName=document.getElementById('SnameText').value;
    var userName=document.getElementById('UserNameText').value;
    var password=document.getElementById('Password').value;
    var email=document.getElementById('EmailText').value;
    var phone=document.getElementById('ctl00_c_NewUserResistration1_PhoneText').value;
    var country=document.getElementById('ctl00_c_NewUserResistration1_CountryDropDownList').value;
    var Adderess=document.getElementById('TextArea1').value;    
    usernme=userName;
    pass=password;
    var URL = 'MainWebservice.asmx/UserRegistration?tm='+new Date().getTime();
    var values= '{"firstName":"'+firstName+'","secondName":"'+secondName+'","userName":"'+userName+'","password":"'+password+'","email":"'+email+'","phone":"'+phone+'","country":"'+country+'","Adderess":"'+Adderess+'"}';
    AjaxCall(URL,values,ONS_UserRegistration);
 }
 else
 {
    HideLoader();
    return false;
 }
 }
       
function ONS_UserRegistration()
{
if (xmlhttp.readyState == 4)
    {
        if (xmlhttp.status == 200)
        {
            var data = eval('('+xmlhttp.responseText+')');
            if(data.d != null)
            {
                HideLoader();
                 document.getElementById('FnameText').value="";
                document.getElementById('SnameText').value="";
                document.getElementById('UserNameText').value="";
                document.getElementById('Password').value="";
                document.getElementById('CPassword').value=="";
                document.getElementById('EmailText').value="";
                document.getElementById('cross').style.display="none";
                document.getElementById('tick').style.display="none";
                document.getElementById('ctl00_c_NewUserResistration1_PhoneText').value="";                
                document.getElementById('TextArea1').value="";  
                window.location="login.aspx";
                //PageMethods.SetLogin(usernme,pass,OnS_SetLogin)
            }
         }
     }       
}
function OnS_SetLogin()
{
}
function CheckUserName()
{
    var userName=document.getElementById('UserNameText').value;
    var URL = 'MainWebservice.asmx/CheckUserName?tm='+new Date().getTime();
    var values= '{"userName":"'+userName+'"}';
    AjaxCall(URL,values,ONS_CheckUserName);
}

function ONS_CheckUserName()
{
 if (xmlhttp.readyState == 4)
    {
        if (xmlhttp.status == 200)
        {
            var data = eval('('+xmlhttp.responseText+')');
            if(data.d != null)
            {
                if(data.d=="0")
                {
                    if(document.getElementById('UserNameText').value=="")
                    {
                        document.getElementById('cross').style.display="block";
                        document.getElementById('tick').style.display="none";
                    }
                    else
                    {
                        document.getElementById('tick').style.display="block";
                        document.getElementById('cross').style.display="none";
                    }
                
                }
                else
                {
                document.getElementById('cross').style.display="block";
                document.getElementById('tick').style.display="none";
                }
            }
         }
     }       
}

function ValidteRegistration()
{
    var result=0;
    if(document.getElementById('FnameText').value=="")
    {
        document.getElementById("FnameText").style.backgroundColor="#FF9999";  
        result=1;     
    }
    else
    {
    document.getElementById("FnameText").style.backgroundColor="#FFFFFF"; 
    }
    if(document.getElementById('UserNameText').value=="")
    {
        document.getElementById("FnameText").style.backgroundColor="#FF9999";  
        result=1; 
        document.getElementById('cross').style.display="block";
        document.getElementById('tick').style.display="none";
    }
    
    if(document.getElementById('EmailText').value=="")
    {
        document.getElementById("EmailText").style.backgroundColor="#FF9999";  
        result=1; 
    }
    else
    {
    document.getElementById("EmailText").style.backgroundColor="#FFFFFF"; 
    }
    if(document.getElementById('EmailText').value!="")
    {
        if (echeck(document.getElementById("EmailText").value)==0)
	    {
		    document.getElementById("EmailText").style.backgroundColor="#FF9999";
		              
		    result=1;		 
	    }
	 }	
	 else
    {
    document.getElementById("EmailText").style.backgroundColor="#FFFFFF"; 
    }
    if(document.getElementById('ctl00_c_NewUserResistration1_PhoneText').value=="")
    {
        document.getElementById("ctl00_c_NewUserResistration1_PhoneText").style.backgroundColor="#FF9999";  
        result=1; 
    }
    else
    {
    document.getElementById("ctl00_c_NewUserResistration1_PhoneText").style.backgroundColor="#FFFFFF"; 
    }
    if(document.getElementById('TextArea1').value=="")
    {
        document.getElementById("TextArea1").style.backgroundColor="#FF9999";  
        result=1; 
    }
    else
    {
    document.getElementById("TextArea1").style.backgroundColor="#FFFFFF"; 
    }
    
    if(document.getElementById('Password').value=="")
    {
     document.getElementById("Password").style.backgroundColor="#FF9999";  
        result=1; 
    }
    else
    {
    document.getElementById("Password").style.backgroundColor="#FFFFFF"; 
    }
    if(document.getElementById('CPassword').value=="")
    {
     document.getElementById("CPassword").style.backgroundColor="#FF9999";  
        result=1; 
    }
    else
    {
    document.getElementById("CPassword").style.backgroundColor="#FFFFFF"; 
    }
    if(document.getElementById('Password').value!="" && document.getElementById('CPassword').value!="")
    {
        if(document.getElementById('Password').value!=document.getElementById('CPassword').value)
        {
            document.getElementById("Password").style.backgroundColor="#FF9999";
            document.getElementById("CPassword").style.backgroundColor="#FF9999";
            document.getElementById("passcheck").style.display="block";     
            result=1;
        }
        else
        {
        document.getElementById("Password").style.backgroundColor="#FFFFFF";
        document.getElementById("CPassword").style.backgroundColor="#FFFFFF";
        document.getElementById("passcheck").style.display="none";     
        }
     }   
    
    return result;
}
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //document.getElementById("EmailText").style.backgroundColor="#FF9999";
		   return 0;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		    //document.getElementById("EmailText").style.backgroundColor="#FF9999";
		   return 0;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		     //document.getElementById("EmailText").style.backgroundColor="#FF9999";
		    return 0;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		     //document.getElementById("EmailText").style.backgroundColor="#FF9999";
		    return 0;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		     //document.getElementById("EmailText").style.backgroundColor="#FF9999";
		    return 0;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		     //document.getElementById("EmailText").style.backgroundColor="#FF9999";
		    return 0;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    // document.getElementById("EmailText").style.backgroundColor="#FF9999";
		    return 0;
		 }

 		 return 1;					
	}


function EditProfile()
{
var val=""
showLoader();
val=ValidteUpdation()
if (val==0)
{
    
    var firstName=document.getElementById('ctl00_c_EditProfile1_FnameText').value;
    var secondName=document.getElementById('ctl00_c_EditProfile1_SnameText').value;    
    var email=document.getElementById('ctl00_c_EditProfile1_EmailText').value;
    var phone=document.getElementById('ctl00_c_EditProfile1_PhoneText').value;
    var country=document.getElementById('ctl00_c_EditProfile1_CountryDropDownList').value;
    var Adderess=document.getElementById('ctl00_c_EditProfile1_TextArea1').value;    
    var URL = 'MainWebservice.asmx/EditUserProfile?tm='+new Date().getTime();
    var values= '{"firstName":"'+firstName+'","secondName":"'+secondName+'","email":"'+email+'","phone":"'+phone+'","country":"'+country+'","Adderess":"'+Adderess+'"}';
    AjaxCall(URL,values,ONS_EditUserProfile);
 }
 else
 {
    HideLoader();
    return false;
 }
}
function ONS_EditUserProfile()
{
    if (xmlhttp.readyState == 4)
    {
        if (xmlhttp.status == 200)
        {
            var data = eval('('+xmlhttp.responseText+')');
            if(data.d != null)
            {
                HideLoader();
                 document.getElementById('ctl00_c_EditProfile1_FnameText').value="";
                document.getElementById('ctl00_c_EditProfile1_SnameText').value="";                
                document.getElementById('ctl00_c_EditProfile1_EmailText').value="";                
                document.getElementById('ctl00_c_EditProfile1_PhoneText').value="";                
                document.getElementById('ctl00_c_EditProfile1_TextArea1').value="";  
            }
         }
     }       
}
function ValidteUpdation()
{

    var result=0;
    if(document.getElementById('ctl00_c_EditProfile1_FnameText').value=="")
    {
        document.getElementById("ctl00_c_EditProfile1_FnameText").style.backgroundColor="#FF9999";  
        result=1;     
    }
    else
    {
    document.getElementById("ctl00_c_EditProfile1_FnameText").style.backgroundColor="#FFFFFF"; 
    }
    
    if(document.getElementById('ctl00_c_EditProfile1_EmailText').value=="")
    {
        document.getElementById("ctl00_c_EditProfile1_EmailText").style.backgroundColor="#FF9999";  
        result=1; 
    }
    else
    {
    document.getElementById("ctl00_c_EditProfile1_EmailText").style.backgroundColor="#FFFFFF"; 
    }
    
    if(document.getElementById('ctl00_c_EditProfile1_EmailText').value!="")
    {
        
        if (echeck(document.getElementById("ctl00_c_EditProfile1_EmailText").value)==0)
	    {
		    document.getElementById("ctl00_c_EditProfile1_EmailText").style.backgroundColor="#FF9999";
		              
		    result=1;		 
	    }
	 }	
	 
    if(document.getElementById('ctl00_c_EditProfile1_PhoneText').value=="")
    {
        document.getElementById("ctl00_c_EditProfile1_PhoneText").style.backgroundColor="#FF9999";  
        result=1; 
    }
    else
    {
    document.getElementById("ctl00_c_EditProfile1_PhoneText").style.backgroundColor="#FFFFFF"; 
    }
    if(document.getElementById('ctl00_c_EditProfile1_TextArea1').value=="")
    {
        document.getElementById("ctl00_c_EditProfile1_TextArea1").style.backgroundColor="#FF9999";  
        result=1; 
    }
    else
    {
    document.getElementById("ctl00_c_EditProfile1_TextArea1").style.backgroundColor="#FFFFFF"; 
    }    
    return result;
}
