﻿// JScript File

///////////////////////////////////////////////////////////////////////////////
//
// Author   :      Lala lajpathrai.Y
// Date     :      23 July 07
// Description:    Validation for Aztecrose
// Modified by:    Ganesh.K
// Modified Date:  24 July 07
// Description:    function of Registration form Validations for Covalense are added
///////////////////////////////////////////////////////////////////////////////////

function validatesearch()
{
    if(trim(document.frmsearch.txtsearch.value)=="")
   {
        alert("Please enter Keyword to search");
        document.frmsearch.txtsearch.focus();
        return false;
   } 
}
function viewpreview(id)
{
    var windowproperties = "width=170, height=470, left=400,top=100,scrollbars=0,toolbar=0";
    var path =  'preview.php?id='+id;
    window.open(path, name, windowproperties);
}

function Closewindow()
{
    window.close();
}

function SendMessage(name, desc, price)
{
    var windowproperties = "width=400, height=220, left="+ ((screen.width - 400) / 2) +",top="+ ((screen.height - 200) / 2) +",scrollbars=0,toolbar=0";
    var path =  'sendmail.php?name='+name+'&desc='+desc+'&price='+price
    //window.open(path, name, windowproperties);
     window.open(path, "new", windowproperties);
}

function validateRefer()
{
    var email = trim(document.frmRefer.fromemail.value);
    if(email=="")
    {
        alert("Please enter your email id");
        document.frmRefer.fromemail.focus();
        return false;
    }
   else if(checkemail(email)==false )
    {
        alert("Please enter correct email id");
        document.frmRefer.fromemail.focus();
        return false;
    }
   var name = trim(document.frmRefer.friendname.value); 
    if(name=="")
    {
        alert("Please enter your friend name");
        document.frmRefer.friendname.focus();
        return false;
    }  
   var frdemail = trim(document.frmRefer.friendemail.value); 
    if(frdemail =="")
    {
        alert("Please enter your friend email");
        document.frmRefer.friendemail.focus();
        return false;
    } 
   else if(checkemail(frdemail)==false )
    {
        alert("Please enter correct email id");
        document.frmRefer.friendemail.focus();
        return false;
    }
   var msg = trim(document.frmRefer.message.value); 
    if(msg=="")
    {
        alert("Please enter message");
        document.frmRefer.message.focus();
        return false;
    }   
   return true; 
}

// Start.. payment. credit card validations
function validateCreditcard()
{
    if(trim(document.frmpayment.ddlCardtype.value)=="0")
    {
        alert("Please select card type");
        document.frmpayment.ddlCardtype.focus();
        return false;
    }
   if(trim(document.frmpayment.txtName.value)=="")
    {
        alert("Please enter name");
        document.frmpayment.txtName.focus();
        return false;
    } 
   var  number=trim(document.frmpayment.txtNumber.value);
   if(number=="")
    {
        alert("Please enter card number");
        document.frmpayment.txtNumber.focus();
        return false;
    }
   else if(number!="")
   {
        if(number.length!=16)
        {
            alert("Please enter correct card number");
            document.frmpayment.txtNumber.focus();
            return false;
        }        
   }
   if(trim(document.frmpayment.ddlMonth.value)=="0")
    {
        alert("Please select card expiry month");
        document.frmpayment.ddlMonth.focus();
        return false;
    }
   if(trim(document.frmpayment.ddlYear.value)=="0")
    {
        alert("Please select card expiry year");
        document.frmpayment.ddlYear.focus();
        return false;
    }    
   return true; 
}
// end
// START... the following are the validation for delivery address
function validatereferaddress()
{
    if(document.frmDelivery.rbDeliver[1].checked == true)
   {
        if(trim(document.frmDelivery.txtAddress.value)=="")
        {
            alert("Please enter street address");
            document.frmDelivery.txtAddress.focus();
            return false;
        }
        if(trim(document.frmDelivery.ddlCountries.value)=="0")
        {
            alert("Please select country");
            document.frmDelivery.ddlCountries.focus();
            return false;
        }
        if(trim(document.frmDelivery.txtCity.value)=="")
        {
            alert("Please enter city");
            document.frmDelivery.txtCity.focus();
            return false;
        }
        if(trim(document.frmDelivery.txtState.value)=="")
        {
            alert("Please enter state");
            document.frmDelivery.txtState.focus();
            return false;
        }
   }
   return true;
}

// END

function validatequantity(frmname, itemid, qtyname, sessionid, size)
{
    var frm = document.getElementById(frmname);
    var txtqty= document.getElementById(qtyname);
    var selsize= document.getElementById(size); 
    var selected = selsize.value;
    var qty = trim(txtqty.value);
    if(qty=="" || qty=="0")
    {
        alert("Please enter quantity");
        txtqty.focus();
        return false;
    }
    else if(IntegerCheck(qty)==false)
    {
        alert("Please enter quantity in numerics only");
        txtqty.focus();
        return false;
    } 
    else
    {
        var name = "Success";
        var width = 400; // popup width
        var height = 200; // popup height
        var left = (screen.width - width) / 2 ;
        var top = (screen.height - height) / 2;
        var windowproperties = "width="+ width +",height="+ height +",left="+ left +",top="+ top +",scrollbars=0,toolbar=0";
        var urluser='add.php?qty='+qty+'&sess='+sessionid+'&id='+itemid+'&size='+selected;
        window.open(urluser, name, windowproperties);
    }
}


function validateuserform()
{  
//   var salutation=document.frmuser.rdsalutation;
//   if(getCheckedValue(salutation)== "")
//   {
//        alert("Please select a title");        
//        return false; 
//   }   
   
   var first=trim(document.frmuser.txtfirst.value);
   if(first== "")
   {
        alert("Please enter first name");
        document.frmuser.txtfirst.focus();
        return false; 
   }
   var surname=trim(document.frmuser.txtsurname.value);
   if(surname== "")
   {
        alert("Please enter surname");
        document.frmuser.txtsurname.focus();
        return false; 
   }     
  
   
   //var address1=trim(document.frmuser.txtaddress1.value);
   //if(address1== "")
   //{
   //     alert("Please enter street address");
   //     document.frmuser.txtaddress1.focus();
   //     return false; 
  // }   
  // var suburb=trim(document.frmuser.txtsuburb.value);
  // if(suburb== "")
  // {
  //      alert("Please enter your suburb");
  //      document.frmuser.txtsuburb.focus();
  //      return false; 
  // }
   
   var postcode=trim(document.frmuser.txtpostcode.value);
   if(postcode != "")
   {
     if(PinCodeDigits(postcode) == false)
     {
        alert("Please enter valid postcode");
        document.frmuser.txtpostcode.focus();
        return false; 
     }        
   }   
      
   //var country=trim(document.frmuser.ddlcountry.value);
   //if(country == "0")
   //{
    //    alert("Please select country name");
      //  document.frmuser.ddlcountry.focus();
     //   return false; 
  // }
  
     var email=trim(document.frmuser.txtemail.value);
       if(email != "")
       {
          if(checkemail(email) == false)
          {
            alert("Please enter valid email address");
            document.frmuser.txtemail.focus();
            return false;     
          }        
       }
   
    var dobday=trim(document.frmuser.txtday.value);
    var dobmonth=trim(document.frmuser.txtmonth.value);
    var dobyear=trim(document.frmuser.txtyear.value);
    var dobdate = dobmonth +'/'+ dobday +'/'+dobyear;    
    var currentTime = new Date()  
    var year = currentTime.getFullYear()        
        
   if(dobday!= "")
   {
        if(PinCodeDigits(dobday) == false)
        {
            alert("Please enter numerics only for day ");
            document.frmuser.txtday.focus();
            return false; 
        }    
   }    
   
   if(dobmonth!= "")
   {
         if(PinCodeDigits(dobmonth) == false)
        {
            alert("Please enter numerics only for month");
            document.frmuser.txtmonth.focus();
            return false; 
         }   
   }     
   
   if(dobyear!= "")
   {
        if(PinCodeDigits(dobyear) == false)
       {
            alert("Please enter numerics only for year");
            document.frmuser.txtyear.focus();
            return false; 
       }
       else if(dobyear >= year)
       {
            alert("Please enter valid year");
            document.frmuser.txtyear.focus();
            return false; 
       }          
        
   }
      
    if(dobday!= "" || dobmonth!= "" || dobyear!= "")
    {
       if(isDate(dobdate) == false)
           {
                alert("Please enter valid date");
                document.frmuser.txtday.focus();
                return false; 
           }
     }
        
            
   var username=trim(document.frmuser.txtusername.value);
   if(username== "")
   {
        alert("Please enter username");
        document.frmuser.txtusername.focus();
        return false; 
   }
   else if(Maxlength(username,6) == false)
   {
        alert("Username should not be less than six characters");
        document.frmuser.txtusername.focus();
        return false; 
   }  
       
   var password=trim(document.frmuser.txtpassword.value);   
   var confirmpassword=trim(document.frmuser.txtconfirmpassword.value);
   if(password== "")
   {
        alert("Please enter password");
        document.frmuser.txtpassword.focus();
        return false; 
   }
   else if(Maxlength(password,6) == false)
   {
        alert("Password should not be less than six characters");
        document.frmuser.txtpassword.focus();
        return false; 
   }
   if(confirmpassword== "")
   {
        alert("Please enter confirm password");
        document.frmuser.txtconfirmpassword.focus();
        return false; 
   }    
    else if(Maxlength(confirmpassword,6) == false)
   {
        alert("Confirm password should not be less than six characters");
        document.frmuser.txtconfirmpassword.focus();
        return false; 
   }   
   else if(password != confirmpassword)
   {
        alert("Password and confirm password are different");
        document.frmuser.txtconfirmpassword.focus();
        return false; 
   }       
   return true;
}

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
// Login page validations
function validateuser()
{ 
  var username=trim(document.frmlogin.txtusername.value);
   if(username== "")
   {
        alert("Please enter username");
        document.frmlogin.txtusername.focus();
        return false; 
   }
   
   var password=trim(document.frmlogin.txtpassword.value);      
   if(password== "")
   {
        alert("Please enter password");
        document.frmlogin.txtpassword.focus();
        return false; 
   }
  return true;
}
function PhoneDigits(PhoneNumber)
{     
	var ValidChars = "1234567890-";
	for(i=0;i<PhoneNumber.length;i++)
	{
		if(ValidChars.indexOf(PhoneNumber.charAt(i)) == -1)
			return false;
	}
	return true;
}

function IsNumericData(UserData)
{
	var ValidChars = "0123456789.";
	for (i = 0; i < UserData.length; i++) 
	{ 
	    if (ValidChars.indexOf(UserData.charAt(i)) == -1) 
			return false;	    
	}
	return true;
}
function AcceptNumbers()
{	
	if (event.keyCode > 47 && event.keyCode <= 57) 
		event.returnValue = true; 
	else 
		event.returnValue = false; 
}


function checkemail(UserEmail)
{
	var at="@" ;
	var dot="." ;
	var lat=UserEmail.indexOf(at);
	var lstr=UserEmail.length;
	var ldot=UserEmail.indexOf(dot);
	
	if (UserEmail.indexOf(at)==-1)
		return false;

	if (UserEmail.indexOf(at)==-1 || UserEmail.indexOf(at)==0 || UserEmail.indexOf(at)==lstr)
		return false;

	if (UserEmail.indexOf(dot)==-1 || UserEmail.indexOf(dot)==0 || UserEmail.indexOf(dot)==lstr)
		return false;


	if (UserEmail.indexOf(at,(lat+1))!=-1)
		return false;


	if (UserEmail.substring(lat-1,lat)==dot || UserEmail.substring(lat+1,lat+2)==dot)
		return  false;

	if (UserEmail.indexOf(dot,(lat+2))==-1)
		return  false;
	
	if (UserEmail.indexOf(" ")!=-1)
		return  false;
		
	return true	;
}


function PasswordChars(sText)
{
	var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
	var Char;
	var j=0;
	
	for(i=0;i<sText.length;i++)
	{
		Char = sText.charAt(i);
		if(ValidChars.indexOf(Char) == -1)
		{
			return false;
		}
	}
		
	return true;
	
}

function PinCodeDigits(PostalCode)
{
	var ValidChars = "1234567890";
	for(i=0;i<PostalCode.length;i++)
	{
		if(ValidChars.indexOf(PostalCode.charAt(i)) == -1)
		{
			return false;
		}
	}
	return true;
}


function PassportDigits(sText)
{
	var ValidChars = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	var Char;
		
	for(i=0;i<sText.length;i++)
	{
		Char = sText.charAt(i);
		if(ValidChars.indexOf(Char) == -1)
		{
			return false;
		}
	}
		
	return true;
}

function RequiredField(sText)
{
	if(sText.length == 0)
		 return  false;
		 
	 return  true;
}


function Check4Chars(sText)
{
	if(sText.length < 4)
		return false;
		
	return true;	
}

function CompareValid(FirstData, SecondData)
{
	if(FirstData.length != SecondData.length)
		return false;
	
	if(FirstData != SecondData)
		return false;	
		
		
	return true;	
}


function DropDownListSelect(sText)
{
	if(sText == 0)
		return false;
		
	return true;
}

function Maxlength(sText, iLength)
{   
	if(sText.length < iLength)
		return false;
		
	return true;	
}
	
	
function ltrim(sValue)
{
	while(1)
	{

		if(sValue.substring(0, 1) != " ")
			break;

		sValue = sValue.substring(1, sValue.length);
	}

	return sValue;
}

function rtrim(sValue)
{
	while(1)
	{
		if(sValue.substring(sValue.length - 1, sValue.length) != " ")
			break;
		sValue = sValue.substring(0, sValue.length - 1);
	}

	return sValue;
}

function trim(sValue)
{
	var sTemp = ltrim(sValue);
	return rtrim(sTemp);
}		

function IntegerCheck(sText)
{
	var Char;
	var ValidChars = "0123456789";
	
	if(sText == 0)
		return false;
		
	for (i = 0; i < sText.length; i++) 
	{ 
		Char = sText.charAt(i); 
													
		if (ValidChars.indexOf(Char) == -1) 
		{
			 return false;
		}
	}
	
	return true;
}

function isDate(dateStr)
 {

        var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
        var matchArray = dateStr.match(datePat); // is the format ok?

        if (matchArray == null)
         {
             //alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
             return false;
         }

           month = matchArray[1]; // p@rse date into variables
           day = matchArray[3];
           year = matchArray[5];

        if (month < 1 || month > 12)
         { // check month range
            //alert("Month must be between 1 and 12.");
            return false;
         }

        if (day < 1 || day > 31)
         {
            //alert("Day must be between 1 and 31.");
            return false;
         }

        if ((month==4 || month==6 || month==9 || month==11) && day==31)
         {
            //alert("Month "+month+" doesn`t have 31 days!")
            return false;
         }

        if (month == 2)
         { // check for february 29th
            var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
            if (day > 29 || (day==29 && !isleap)) 
            {
              //alert("February " + year + " doesn`t have " + day + " days!");
               return false;
           }
        }
    return true; // date is valid
  }

// www.covalense.com  online application

function  validateResumes()
{
      var name = trim(document.frmOnline.txtName.value); 
    if(name=="")
    {
        alert("Please enter your name");
        document.frmOnline.txtName.focus();
        return false;
    } 
   
   
    var email = trim(document.frmOnline.txtEmail.value);
    if(email=="")
    {
        alert("Please enter your email id");
        document.frmOnline.txtEmail.focus();
        return false;
    }
   else if(checkemail(email)==false )
    {
        alert("Please enter correct email id");
        document.frmOnline.txtEmail.focus();
        return false;
    }
    
    var fileUploadValue = document.getElementById('flUpload').value;
    if(fileUploadValue == "")
    {
        alert("Please attach your resume");
        document.getElementById('flUpload').focus();
        return false;
    }
    
     return true;
     
     
}



