// JavaScript Document
var GlobalCounter = 0;
var ImgNo=0;
// arrays for setting image path and text for Mustmat Tour
var MusTourImages = new Array("/images/Step1.gif","/images/Step2.gif","/images/Step3.gif","/images/Step4.gif","/images/Step5.gif");

var MusTourHrefPaths = new Array("/Introduction/MusmatConnects.asp","/Introduction/MusmatMatchMaking.asp","/Introduction/MusmatPromise.asp","/Introduction/MusmatConnects.asp","/Help/faq.asp");

var MusTourContents = new Array("Musmat 2.0 Technology and Innovation.<br>Combining the latest technology with the best support in the industry.",
								"13 Years of Dedicated MatchMaking.	One of the worlds older matrimonial services trusted since 1995.",
								"The Musmat.com Promise",
								"MusMag - Musmat's Unique Monthly Marriage Listing publication No regular internet access ?, Get MusMag, a published magazine by courier to your door every month.",
								"Using Musmat.com to get married.");

var TourImag = 0;


// arrays for setting image path and the text for the Success Stories 
var imgArray = new Array("/images/Success13.gif","/images/Success12.gif", "/images/Success11.gif","/images/Success14.gif", "/images/Success15.gif","/images/Success8.gif", "/images/Success2.gif", "/images/Success3.gif", "/images/Success4.gif", "/images/Success5.gif","/images/Success6.gif", "/images/Success7.gif", "/images/Success9.gif", "/images/Success1.gif", "/images/Success10.gif");
var imgDescArray = new Array("10/01/2010 <br /> Thanks a lot for your service, it took a bit longer than I had hoped for, but was successful in the end...",
							 "15/12/2009 <br /> I had almost given up hope, when I found Alina on the site, after receiving an expression of interest,...",
							 "01/10/2009 <br /> Thank you so much for helping us find each other. Alia and Nazir....",
							 "15/08/2009 <br /> I was a bit disappointed after having talked to some persons who I felt were not suitable, I nearly was ...",
 							 "01/06/2009 <br /> I have found my mustmat match. thanks musmat.",
							 "27/09/2008 <br /> I have met a lovely women and inshallah we are getting  married soon...",
							 "21/01/2008 <br />I would like to thank everyone involved with your service. As a result of placing an ....",
							 "15/04/2008 <br />meeting a suitable partner has only been possible through the new avenues which ... ",
							 "22/09/2008 <br />Assalam U Alaikum, great site, thanks for helping us to find each other. We would like to invite...",
							 "25/09/2008 <br />Abdul Karim and Zahida I was very hesitant to use the internet, because I was worried it may be ..",
							 "27/09/2008 <br />Hi there, just wanted to drop a line, with a pic, thanks guys we are now happily married..",
							 "21/1/2008 <br />Dear Musmat, Thank you so much for helping me find Khizar, my granddaughter put my ...",
							 "15/10/2008 <br />Jazak Allah, after searching for many months, we finally met in August, and pray  ...",
							 "22/09/2007 <br />Hamid and Misbah  After trying 3 sites, I had given up finding my dream mate. I suppose this ...",
							 "25/09/2008 <br />I met Arif through your site, and now we are getting married soon insha Allah. Thanks very....");
/********** varables to initialize that tell the position of the image from one of three on success stories. **********/
var image1=0;
var image2=1;
var image3=2;
//*****************************************************
function onRequiredPoint(imageNo)
{
	var i;
	for(i=0; i<=4; i++)
	{
		if (i==imageNo)
			document.getElementById("Nav"+i).src = "/images/point_click.gif";
		else
			document.getElementById("Nav"+i).src = "/images/point_mv.gif";
	}
}
function changeMusmatTourContents(TourImag)
{
	if (navigator.appName != "Netscape")
	{
		// following code works for IE, Opera and others
		document.frames("framMusDesc").document.getElementById("ContentImage").src = MusTourImages[TourImag];
		document.frames("framMusDesc").document.getElementById("MusTourLink").href = MusTourHrefPaths[TourImag];
	}
	else
	{
		// following code works for firefox and safari
		document.getElementById("framMusDesc").contentDocument.getElementById("ContentImage").src = MusTourImages[TourImag];
		document.getElementById("framMusDesc").contentDocument.getElementById("MusTourLink").href = MusTourHrefPaths[image1];
	}
}

function changeMusTourContents(Direction)
{ 
	if (Direction.id == "PreviousSlide")
	{
		TourImag--;
		if(TourImag == -1)
		{
			TourImag = 0;
		}
		changeMusmatTourContents(TourImag);
		onRequiredPoint(TourImag);
	}
	else if(Direction.id == "NextSlide")
	{
		TourImag++;
		if(TourImag == 5)
		{
			TourImag = 4;
		}
		changeMusmatTourContents(TourImag);
		onRequiredPoint(TourImag);
	}
}

function changeSuccessStoryImage(image1, image2, image3)
{
	if(navigator.appName!="Netscape")
	{
		document.frames("framMusDesc").document.getElementById("img1").src = imgArray[image1];
		document.frames("framMusDesc").document.getElementById("SuccessAdvert1").innerHTML = imgDescArray[image1];
		
		document.frames("framMusDesc").document.getElementById("img2").src = imgArray[image2];
		document.frames("framMusDesc").document.getElementById("SuccessAdvert2").innerHTML = imgDescArray[image2];
		
		document.frames("framMusDesc").document.getElementById("img3").src = imgArray[image3];
		document.frames("framMusDesc").document.getElementById("SuccessAdvert3").innerHTML = imgDescArray[image3];
	}
	else
	{
		document.getElementById("framMusDesc").contentDocument.img1.src = imgArray[image1];
		document.getElementById("framMusDesc").contentDocument.getElementById("SuccessAdvert1").innerHTML= imgDescArray[image1];
		
		document.getElementById("framMusDesc").contentDocument.img2.src = imgArray[image2];
		document.getElementById("framMusDesc").contentDocument.getElementById("SuccessAdvert2").innerHTML= imgDescArray[image2];
		
		document.getElementById("framMusDesc").contentDocument.img3.src = imgArray[image3];
		document.getElementById("framMusDesc").contentDocument.getElementById("SuccessAdvert3").innerHTML= imgDescArray[image3];
	}
}

function changeImageContents(Direction)
{
	if(navigator.appName!="Netscape")
	{
		if (document.frames("framMusDesc").document.getElementById("img1") == null)
		{ 	changeMusTourContents(Direction); 
			return false;
		}
	}
	else
	{
		if (document.getElementById("framMusDesc").contentDocument.getElementById("img1") == null)
		{ changeMusTourContents(Direction); 
			return false;}
	}
	if (Direction.id == "PreviousSlide")
	{
		image1-=3;
		image2-=3;
		image3-=3;

		if (image1 <= 0)
		{
			image1 = 1;
			image2 = 2;
			image3 = 3;
		}

		changeSuccessStoryImage(image1, image2, image3);
		
		GlobalCounter-=3;
		if (GlobalCounter<=0)
		{	
			GlobalCounter=0;
		}
		ImgPoint=GlobalCounter/3;
		if(GlobalCounter%3==0)
		{
			ImgNo=ImgPoint;
			onRequiredPoint(ImgNo);
		}
		//alert(GlobalCounter + ' ' + ImgNo);
	}
	else if(Direction.id == "NextSlide")
	{
		image1+=3;
		image2+=3;
		image3+=3;

		if (image3 >= 15)
		{
			image1=12;
			image2=13;
			image3=14;
		}
		
		changeSuccessStoryImage(image1, image2, image3);
		GlobalCounter+=3;

		if (GlobalCounter>=15)
		{	
			GlobalCounter=12;
		}
		ImgPoint=GlobalCounter/3;		
		if(GlobalCounter%3==0)
		{
			ImgNo=ImgPoint;
			onRequiredPoint(ImgNo);
		}
		//alert(GlobalCounter + ' ' + ImgNo);
	}
}

function changeImage(sImageName)
{
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		// if browser is IE then it will use GIf images as it does not supports the png file type.
		if(document.getElementById(sImageName).id == "imgRegistration")
		{
			document.getElementById(sImageName).src = "/images/Registration_Click.gif";
			document.getElementById('imgSearch').src = "/images/q_search.gif";
		}
		else if(document.getElementById(sImageName).id == "imgSearch")
		{
			document.getElementById(sImageName).src = "/images/q_search_click.gif";
			document.getElementById('imgRegistration').src = "/images/Registration.gif";
		}
	}
	else
	{
		if(document.getElementById(sImageName).id == "imgRegistration")
		{
			document.getElementById(sImageName).src = "/images/Registration_Click.png";
			document.getElementById('imgSearch').src = "/images/q_search.png";
		}
		else if(document.getElementById(sImageName).id == "imgSearch")
		{
			document.getElementById(sImageName).src = "/images/q_search_click.png";
			document.getElementById('imgRegistration').src = "/images/Registration.png";
		}
	}
}
function changeTourStoriesImage(sImageName)
{
	if(document.getElementById(sImageName).id == "imgTour")
	{
		document.getElementById(sImageName).src = "/images/musmatTour_click.gif";
		document.getElementById('imgStories').src = "/images/success.gif";
		document.getElementById('PreviousSlide').enabled = false;
		document.getElementById('NextSlide').enabled = false;
		onRequiredPoint(0);
		GlobalCounter = 0;
		ImgNo=0;
		TourImag=0;
	}
	else if(document.getElementById(sImageName).id == "imgStories")
	{
		document.getElementById(sImageName).src = "/images/success_click.gif";
		document.getElementById('imgTour').src = "/images/musmatTour.gif";
		document.getElementById('PreviousSlide').enabled = true;
		document.getElementById('NextSlide').enabled = true;
		onRequiredPoint(0);
		GlobalCounter = 0;
		ImgNo=0;
		TourImag=0;
	}
}

function selectFieldText(field)
{
	field.select();
}

function ClearTextField(field)
{
	if(field.value == "Email Address")	
	field.value = "";
	else
	{		
		field.value = "";
	}
}
function RestoreText(field)
{
	if (field.id == "username")
	{		
		if (field.value == "")
		{
			field.value = "Email Address";
		}
	}
	else
	{
		if (field.value == "")
		{
			field.value = "########";
		}
	}
}

function spaceInEmail(e)
{	
	// handles the space of passed field
	if(navigator.appName!="Netscape")
	{
		if (e.keyCode == 32)
		{	return false;	}
		else
		{	return true;	}
	}
	else
	{
		if (e.which == 32)
		{	return false;	}
		else
		{	return true;	}
	}
}

function isEmail(email)
{
//Regular Expression for validating email	
var regExp = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if(regExp.test(email) == false)
	return false;
else
	return true;
}

function ValidateRegStep1(frm)
{
	var regExp=/[A-Za-z]/

	var err;
	err = "";

	if (frm.txtFirstName.value == "" || frm.txtPassword.value == "" || frm.txtPasswordCon.value == "" || frm.txtEmail.value == "" || frm.CountryOfResidence.value == "" || (frm.Female.checked == false && frm.Male.checked == false))
	{
		if (frm.txtFirstName.value == "")
		{	err += "\n- Please enter First Name."; }
		if(frm.txtEmail.value == "")
		{	err += "\n- Please enter Email Address."; }
		if(frm.txtPassword.value == "")
		{	err += "\n- Please enter Password."; }
		if(frm.txtPasswordCon.value == "")
		{	err += "\n- Please Re-enter Password."; }
		if(frm.CountryOfResidence.value == "")
		{	err += "\n- Please select Country."; }
		if (frm.Female.checked == false && frm.Male.checked == false)
		{	err += "\n- Please select Gender."; }
	}
	else
	{
		if(regExp.test(frm.txtFirstName.value) == false)
		{
			err += "\n- Please use only alphabets for First Name.";
		}
		if (frm.txtLastName.value != "")
		{
			if(regExp.test(frm.txtFirstName.value) == false)
			{
				err += "\n- Please use only alphabets for Last Name.";
			}
		}
		if(frm.txtPassword.value != frm.txtPasswordCon.value)
		{
			err += "\n- Password is not consistent.";
		}
		else if(frm.txtPassword.value.length <= 5)
		{
			err += "\n- Length of password must be greater than 5 characters.";
		}
		
		var email;
     	email=frm.txtEmail.value;
			
		if (!isEmail (email)) 
		{
			err += "\n- Not a valid email address";	
		}
		
		if (email.indexOf("musmat")!=-1)
		{
			err += "\n- Musmat.com is not a valid email domain.";
		}
			
	}
	

	if (err != "")
	{
		alert(err);
		return false;
	}
}

function ValidateLogin(frm)
{
	if (frm.username.value == "" || frm.password.value == "" || frm.password.value == "########" || frm.username.value == "Email Address")
	{
		alert("Please enter username/password");
		return false;
	}
	else
	{
		
	}
}