// ------------------------------------------------

function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value==""||value==" ")
  {alert(alerttxt);return false}
else {return true}
}
}

function validate_registration_form(thisform)
{

with (thisform)
{
if (validate_required(name,"Please enter your name")==false)
  {name.focus();return false}
}

with (thisform)
{
if (echeck(document.regform.email.value)==false)
  {email.focus();return false}
}

with (thisform)
{
if (validate_required(comments,"Please enter your comment")==false)
  {comments.focus();return false}
}


}


// check email starts here
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){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function ValidateForm(){
	var emailID=document.regform.email
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }


// check email ends here

// mobile number check here 
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 8;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidateMobile(){
	var Phone=document.regform.mobile
	
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Mobile Number")
		Phone.focus()
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Mobile Number, do not include special characters or spaces' ")
		Phone.value=""
		Phone.focus()
		return false
	}
	return true
 }
// mobile check ends here

// phone check starts here

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 8;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidatePhone(){
	var Phone=document.regform.phone
	
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Phone Number")
		Phone.focus()
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Phone Number, do not include special characters or spaces' ")
		Phone.value=""
		Phone.focus()
		return false
	}
	return true
 }

// phone check ends here

// radio button checker

function radio_button_checker()
{
// set var radio_choice to false
var radio_choice = false;

// Loop from zero to the one minus the number of radio button selections
for (counter = 0; counter < regform.user_title.length; counter++)
{
// If a radio button has been selected it will return true
// (If not it will return false)
if (regform.user_title[counter].checked)
radio_choice = true; 
}

if (!radio_choice)
{
// If there were no selections made display an alert box 
alert("Please fill the required fields marked with *")
return (false);
}
return (true);
}


// radio button checker ends here
// login content javascript ends here 


// recent or coming div hide show 

function showrecentdiv() {
var showdiv;
 showdiv = document.getElementById("recentdiv");
 showdiv.style.display = "block";
 document.regform.coming_date.value = "";
 hidecomingdiv();
	}
	
function hiderecentdiv() {
var hidediv;
 hidediv = document.getElementById("recentdiv");
 hidediv.style.display = "none";
 document.regform.recently_date.value = "";
	
	}

function showcomingdiv() {
var showdiv;
 showdiv = document.getElementById("comingdiv");
 showdiv.style.display = "block";
 document.regform.recently_date.value = "";
 hiderecentdiv();
	}
	
function hidecomingdiv() {
var hidediv;
 hidediv = document.getElementById("comingdiv");
 hidediv.style.display = "none";
 document.regform.coming_date.value = "";
	}

function hidealldivs() {
 	document.getElementById("comingdiv").style.display = "none";
	document.regform.coming_date.value = "";
	document.getElementById("recentdiv").style.display = "none";
	document.regform.recently_date.value = "";
	}
// recent or coming div hide show ends here


function deleteconfirm() {
return confirm("Are you sure you want to delete?");
}

function sortby(fieldvalue)
{
	window.location = "allproducts.php?sort_by="+fieldvalue;
}


function playlist()
{
	if (document.getElementById("playlist").style.display == "block")
	{
	document.getElementById("playlist").style.display = "none";
	}
	else 
	{
	document.getElementById("playlist").style.display = "block";
	}
}

function playaudio(audiolink) { 
document.getElementById("audioplayer").innerHTML = '<embed src="http://www.goodlife.com.ng/audioplayer.swf" quality="high" width="220" height="20" name="mp3player" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="width=220&height=20&autostart=yes&bg=0x000000&leftbg=0xFFBF00&border=0xFFBF00&text=0x333333&soundFile='+audiolink+'" wmode="transparent" style="margin:0; padding:0;"></embed>';
playlist();
}