	
function preloadimages()
	{
		for (i = 0; i < preloadimages.arguments.length; i++)
			{
				myimages[i] 		= new Image();
				myimages[i].src 	= preloadimages.arguments[i];
			}
	}
	
function ravi(GiftId,image_name,mystyle,giftname,giftmagepadd)
	{
	
	if(document.getElementById("IsRegister").value == "Yes")
	{
	
	if(headerchange == "Yes")
		{
			var i = 1;
			while(i <= headersplits)
				{
					document.getElementById('header_'+i).src = "images/header_"+i+"_"+giftmagepadd+".jpg";
					
					i++;
				}
			
			if(document.getElementById('MyCustID').value < 1)
				document.getElementById('submit').src = "images/button_"+giftmagepadd+".jpg";	
			else
				{
					document.getElementById('submit').src = "images/button_update_"+giftmagepadd+".jpg";
					$("#submit").attr("disabled",false).css('opacity', 1);
				}
		}
							
		document.getElementById('MyGiftID').value = GiftId;
		document.getElementById('formHeading').innerHTML = giftname;
		prevContent = document.getElementById('middle_right').innerHTML;
		
		
		/*document.getElementById('middle_right').innerHTML = '<a onclick="back_to_default_images()" style=color:red>back</a><img src="'+image_name+'">';*/
		document.getElementById('middle_right').innerHTML = '<input type="button" value="Back" onclick="back_to_default_images()" id="back_button"/><img src="'+image_name+'"><div id="gift_description"></div>';
		document.getElementById('gift_description').innerHTML = document.getElementById('hid_gift_desc_'+GiftId).value;
		document.getElementById('default').href = "styles/"+mystyle;
		
	}
	else
	{
		alert("Cannot select Gift\n\nYou can select Gift only from registration page");	
	}
	}

function back_to_default_images()
	{	
		
		if(headerchange == "Yes")
		{
			var i = 1;
			while(i <= headersplits)
				{
					document.getElementById('header_'+i).src = "images/header_"+i+".jpg";
					i++;
				}
			document.getElementById('submit').src = "images/button.jpg";	
		}
		
		document.getElementById('MyGiftID').value = "";
		document.getElementById('formHeading').innerHTML = "Select the prize and enter the draw";
		document.getElementById('middle_right').innerHTML = prevContent;
		document.getElementById('default').href = "styles/homepage.css";
	
	
	}
	



function Login_Now()
	{
		var Email 			=	$("input#LoginEmail").val();
		var Password 		=	$("input#LoginPassword").val();
		var posturl			=	"process_login.php";
		
				$.ajax({
				  type:"POST", 
				  url:posturl,
				  data:{Email:Email,Password:Password},
				  dataType:"html",
				  success:function ( data ) { 
					
					if(data.indexOf("Sorry:") == -1)
						{
							$("div#div_my_form_head").html("Welcome");		 
							$("div#div_my_form").html( data );
							document.getElementById('submit').src = "images/button_update.jpg";
						}
					else
						$("#Login_error_mesage").html( data ); 
				  
				  } ,
				  
				  error:function(xhr,err,e){ alert( "Error: " + err ); }
				}); // $.ajax()
	}
	

function my_submit()
{
	
	$("#submit").attr("disabled",true).css('opacity', 0.4);
	
	if(document.getElementById('MyGiftID').value == "")
		{
			alert("Please select a Gift");
			$("#submit").attr("disabled",false).css('opacity', 1);
			return false;
		}	
	else
	{
			
			if(validate() == false)
				{
					$("#submit").attr("disabled",false).css('opacity', 1);
					return false;
				}
			
			var posturl 		= "process_index.php";
			var Title 			=	$("select#Title").val();
			var FirstName 		=	$("input#FirstName").val();
			var LastName 		=	$("input#LastName").val();
			var Email 			=	$("input#Email").val();
			var Password 		=	$("input#Password").val();
			var Gender 			=	$("select#Gender").val();
			var Year 			=	$("select#Year").val();
			var Month 			=	$("select#Month").val();
			var Day 			=	$("select#Day").val();
			var Address1 		=	$("input#Address1").val();
			var Address2 		=	$("input#Address2").val();
			var City 			=	$("input#City").val();
			var State 			=	$("input#State").val();
			var Country 		=	$("input#Country").val();
			var PostCode 		=	$("input#PostCode").val();
			var GiftID 			=	$("input#MyGiftID").val();
			var HomePhone		=	$("input#HomePhone").val();
			var MaritalStatus	=	$("input#MaritalStatus").val();
			var MyCustID		=	$("input#MyCustID").val();
			
				$.ajax({
				  type:"POST", 
				  url:posturl,
				  data:{Title:Title,FirstName:FirstName,LastName:LastName,Password:Password,Email:Email,Gender:Gender,Year:Year,Month:Month,Day:Day,Address1:Address1,Address2:Address2,City:City,State:State,Country:Country,GiftID:GiftID,PostCode:PostCode,HomePhone:HomePhone,MaritalStatus:MaritalStatus,MyCustID:MyCustID},
				  dataType:"html",
				  success:function ( data ) { 
				  
				if(data == "Done")
					{
						window.location.href = "index1.php";
					}
				else
					{	
					  
					  $("div#submit_result").html( data ); 
					  $("#submit").attr("disabled",false).css('opacity', 1);
					}								  
				  
				  } ,
				  
				  error:function(xhr,err,e){ alert( "Error: " + err ); }
				}); // $.ajax()
		
		}
		

}


function email_check()
	{
		
		var posturl = "check_email.php";
		var Email 	=	$("input#Email").val();
			$.ajax({
			  type:"POST", 
			  url:posturl,
			  data:{ Email:Email},
			  dataType:"html",
			  success:function ( data ) { 
			  if(data == "Available")
				$("#submit").attr("disabled",false).css('opacity', 1);
				
			  $("div#div_email").html( data ); } ,
			  error:function(xhr,err,e){ alert( "Error: " + err ); }
			}); // $.ajax()

	
	}
	
	
function click_options(choice)	
	{
		
		$("#back_button").attr("disabled",true).css('opacity', 0.4);
		
		if(choice == "Login")
				{
									   
					var posturl = "login.php";
				
					$.ajax({
					  type:"POST", 
					  url:posturl,
					  data:{},
					  dataType:"html",
					  success:function ( data ) { 
					  $("div#div_my_form").html( data ); } ,
					  error:function(xhr,err,e){ alert( "Error: " + err ); }
					}); // $.ajax()
				}
			else if(choice == "Register")
				{
					$("#back_button").attr("disabled",false).css('opacity', 1);
					var posturl = "registration_form1.php?fromlogin=yes";
				
					$.ajax({
					  type:"POST", 
					  url:posturl,
					  data:{},
					  dataType:"html",
					  success:function ( data ) { 
					  $("div#div_my_form").html( data ); } ,
					  error:function(xhr,err,e){ alert( "Error: " + err ); }
					}); // $.ajax()
				}
				
			else if(choice == "forget")
				{
						var posturl			=	"forget_password.php";
					$.ajax({
						  type:"POST", 
						  url:posturl,
						  data:{},
						  dataType:"html",
						  success:function ( data ) { 
							
								$("div#div_my_form").html( data ); 
						  
						  } ,
						  
						  error:function(xhr,err,e){ alert( "Error: " + err ); }
						}); // $.ajax()	
				}	
			
	}
	
	
	function validate()
		{
		

				if(document.getElementById('Email'))
				{
					if(document.getElementById('Email').value=="")
					   {
						 alert("Please enter Email");
						 document.getElementById('Email').focus();
						 return false;
					   }
				}
				
				if(document.getElementById('Title'))
				{
					if(document.getElementById('Title').value=="~Select")
					   {
						 alert("Please enter Title");
						 document.getElementById('Title').focus();
						 return false;
					   }
				}
				
				if(document.getElementById('FirstName'))
				{
				   if(document.getElementById('FirstName').value=="")
					   {
						 alert("Please enter FirstName");
						 document.getElementById('FirstName').focus();
						 return false;
					   }
				}
				
	
				if(document.getElementById('LastName'))
				{
					if(document.getElementById('LastName').value=="")
					   {
						 alert("Please enter LastName");
						 document.getElementById('LastName').focus();
						 return false;
					   }
				}
				
				if(document.getElementById('Gender'))
				{
					 if(document.getElementById('Gender').value=="~Select")
					   {
						 alert("Please select gender");
						 document.getElementById('Gender').focus();
						 return false;
					   }
					   
					   
					 if(document.getElementById('Gender').value=="M" && document.getElementById('Title').value!="Mr")
				   {
					 alert("Gender and Title  do not match");
					 document.getElementById('Gender').focus();
					 return false;
				   }
				   
					if(document.getElementById('Gender').value=="F" && document.getElementById('Title').value=="Mr")
				   {
					 alert("Gender and Title  do not match");
					 document.getElementById('Gender').focus();
					 return false;
				   } 
					   
				}
				 
				 
				
				 
				 
				if(document.getElementById('Address1'))
				{
					 if(document.getElementById('Address1').value=="")
					   {
						 alert("Please enter address1");
						 document.getElementById('Address1').focus();
						 return false;
					   }
				}
				
				if(document.getElementById('City'))
				{
					 if(document.getElementById('City').value=="")
					   {
						 alert("Please enter city");
						 document.getElementById('City').focus();
						 return false;
					   }
				}
				
				if(document.getElementById('State'))
				{
					if(document.getElementById('State').value=="")
					   {
						 alert("Please enter State");
						 document.getElementById('State').focus();
						 return false;
					   }
				}
				
				
				
	
			var toCheck = document.getElementById('PostCode').value;
			
			if(checkPostCode (toCheck) == false)
				{
						alert("Invalid Post Code");
						document.getElementById('PostCode').focus();
						return false;
					
				}
	
				
				
				if(document.getElementById('Year'))
				{
					 if(document.getElementById('Year').value=="~Select")
					   {
						 alert("Please enter Year");
						 document.getElementById('Year').focus();
						 return false;
					   }
				}
				
				if(document.getElementById('Month'))
				{
					 if(document.getElementById('Month').value=="~Select")
					   {
						 alert("Please enter Month");
						 document.getElementById('Month').focus();
						 return false;
					   }
				}
				
				if(document.getElementById('Day'))
				{
					 if(document.getElementById('Day').value=="~Select")
					   {
						 alert("Please enter Day");
						 document.getElementById('Day').focus();
						 return false;
					   }
				}
				
			
			//******************home phone **************************


      if(document.getElementById('HomePhone').value=="")
		 {
			 alert("Please enter home HomePhone");
			 document.getElementById('HomePhone').focus();
			 return false;
		 }
	 
	  else if(isNaN(document.getElementById('HomePhone').value))
	    {
			 alert("Please enter home HomePhone in number ");
			 document.getElementById('HomePhone').focus();
			 return false;
		}
	  else 	
	     {
			// alert(" This is value of home HomePhone " + document.frmWeb.HomePhone.value);
			 var str_value	=	document.getElementById('HomePhone').value;
			 str	=	document.getElementById('HomePhone').value;
             str	=	str.length;
             // alert("fdfsdfjkkdfjjkdfdk  "+str);
             var i=0;
			 var flage=0;
			 $f_2=0;
			 while(i < 2)
			  {
			
				 if(i==0 && str_value.charAt(i)==0)
				 {
					$f_2=1;
					// break;
				 }
				  
				if($f_2==1 && i==1 && (str_value.charAt(i)==7  || str_value.charAt(i)==8 || str_value.charAt(i)==9))
				 {
					//alert ("vcxvcxjklvcxvckvlcjklllc  vkxcklvxcklj cvlkc ") ;
				   	flage=1;
					break;
				 }
 
				i++;
			  }
			  
			  if(flage==1 || str < 10)
			   {
				 alert("Your HomePhone number is invalid");
                 document.getElementById('HomePhone').focus();
			     return false;
 
			   }
         }
		 
		 
	
	
	
				if(document.getElementById('HomeStatus'))
				{
					 if(document.getElementById('HomeStatus').value=="~Select")
					   {
						 alert("Please enter HomeStatus");
						 document.getElementById('HomeStatus').focus();
						 return false;
					   }
				}
				
				if(document.getElementById('MaritalStatus'))
				{
					 if(document.getElementById('MaritalStatus').value=="~Select")
					   {
						 alert("Please enter MaritalStatus");
						 document.getElementById('MaritalStatus').focus();
						 return false;
					   }
				}
				
				if(document.getElementById('Occupation'))
				{
					 if(document.getElementById('Occupation').value=="~Select")
					   {
						 alert("Please enter Occupation");
						 document.getElementById('Occupation').focus();
						 return false;
					   }
				}
				
				if(document.getElementById('PeopleLiving'))
				{
					 if(document.getElementById('PeopleLiving').value=="~Select")
					   {
						 alert("Please enter PeopleLiving");
						 document.getElementById('PeopleLiving').focus();
						 return false;
					   }
				}
				
				if(document.getElementById('UnderEighteen'))
				{
					 if(document.getElementById('UnderEighteen').value=="~Select")
					   {
						 alert("Please enter UnderEighteen");
						 document.getElementById('UnderEighteen').focus();
						 return false;
					   }
				}
				
				if(document.getElementById('MaritalStatus'))
				{
					 if(document.getElementById('MaritalStatus').value=="~Select")
					   {
						 alert("Please enter MaritalStatus");
						 document.getElementById('MaritalStatus').focus();
						 return false;
					   }
				}
				
		
		}
		

 function checkPostCode (toCheck) {

  // Permitted letters depend upon their position in the postcode.
  var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1
  var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2
  var alpha3 = "[abcdefghjkstuw]";                                // Character 3
  var alpha4 = "[abehmnprvwxy]";                                  // Character 4
  var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5
  
  // Array holds the regular expressions for the valid postcodes
  var pcexp = new Array ();

  // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Expression for postcodes: ANA NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));

  // Expression for postcodes: AANA  NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Exception for the special postcode GIR 0AA
  pcexp.push (/^(GIR)(\s*)(0AA)$/i);
  
  // Standard BFPO numbers
  pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
  
  // c/o BFPO numbers
  pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);
  
  // Overseas Territories
  pcexp.push (/^([A-Z]{4})(\s*)(1ZZ)$/i);

  // Load up the string to check
  var postCode = toCheck;

  // Assume we're not going to find a valid postcode
  var valid = false;
  
  // Check the string against the types of post codes
  for ( var i=0; i<pcexp.length; i++) {
    if (pcexp[i].test(postCode)) {
    
      // The post code is valid - split the post code into component parts
      pcexp[i].exec(postCode);
      
      // Copy it back into the original string, converting it to uppercase and
      // inserting a space between the inward and outward codes
      postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
      
      // If it is a BFPO c/o type postcode, tidy up the "c/o" part
      postCode = postCode.replace (/C\/O\s*/,"c/o ");
      
      // Load new postcode back into the form element
      valid = true;
      
      // Remember that we have found that the code is valid and break from loop
      break;
    }
  }
  
  // Return with either the reformatted valid postcode or the original invalid 
  // postcode
  if (valid) {return postCode;} else return false;
}		