// JavaScript Document naeem bhatt naeembhatti@gmail.com
function theDate() {
	  dat = new Date();
	  month = dat.getMonth();
	  monthname = new Array();
	  monthname[0] = "January";
	  monthname[1] = "February";
	  monthname[2] = "March";
	  monthname[3] = "April";
	  monthname[4] = "May";
	  monthname[5] = "June";
	  monthname[6] = "July";
	  monthname[7] = "August";
	  monthname[8] = "September";
	  monthname[9] = "October";
	  monthname[10] = "November";
	  monthname[11] = "December";
	  day = dat.getDate();
	  if (day == 1) {dayadd = "st";}
	  else if (day == 21) {dayadd = "st";}
	  else if (day == 31) {dayadd = "st";}
	  else if (day == 2) {dayadd = "nd";}
	  else if (day == 22) {dayadd = "nd";}
	  else if (day == 3) {dayadd = "rd";}
	  else if (day == 23) {dayadd = "rd";}
	  else {dayadd = "th";}
	  year = dat.getFullYear();
  	document.write ('<span>' + monthname[month] + ' ' + day + '<span style="font-size:9px; position:relative; top:-4px; left:1px;">' + dayadd + '</span></sup>, ' + year + '</span>');
		}
		function navOn(idName) {
			if (document.getElementById(idName)) {
				document.getElementById(idName).className="on";
			}
		}
		function navOff(idName) {
			if (document.getElementById(idName)) {
				document.getElementById(idName).className="off";
			}
		}	
//=================================		
function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}
/*
var testString = '1,2,3,4,5,5';

alert('Before: ' + testString);

testString = replace(replace(testString,',','@'),',','@');

alert('After: ' + testString);*/

function showForm_through() {
if(document.getElementById){
	   document.getElementById('d_rb').innerHTML='<form action="http://newswm.bbc.co.uk/cgi-bin/change_edition.pl" name="ifhForm" method="get"><input type="hidden" name="qs" value="http://news.bbc.co.uk/1/hi/country_profiles/default.stm" /><input type="hidden" name="content" value="nol" /><input name="dest" type="radio" value="Domestic" onclick="submitForm();" id="dfh" checked /><label for="dfh" class="uk" style="font-weight:bold;">UK version</label><input name="dest" type="radio" value="International"  onclick="submitForm();"  id="ifh" /><label for="ifh" class="int">International version</label></form>';}
}
var site;
function submitForm_through() {
			document.ifhForm.submit();
}

//to remove html tags
function stripHTML(){
var re= /<\S[^><]*>/g
for (i=0; i<arguments.length; i++)
	arguments[i].value=arguments[i].value.replace(re, "")
}

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					
	}
//=====================================trimminggggggggggggggggggggggggggggg	
function leftTrim(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	return sString;
}
function rightTrim(sString)
{
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
	sString = sString.substring(0,sString.length-1);
	}
	return sString;
}


function trimAll(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}
//====================================
function show_error(str,div_id){ 
	document.getElementById(div_id).style.display = "block";
	document.getElementById(div_id).innerHTML = str;
}
function hide_error(div_id){ 

			 document.getElementById(div_id).style.display = "none";
}
//start form======================================================================================
function ValidateNewsLetterEmail()
	{
		if(document.NewsLetterForm.NewsLetterEmail.value==''){
			  show_error("<font class='error'>Please enter your email.</font>",'NewsLetterEmailError');
			  document.NewsLetterForm.NewsLetterEmail.focus();
			  return false;			  
		}else if (echeck(document.NewsLetterForm.NewsLetterEmail.value)==false) {
						show_error("<font class='error'>Invalid email.</font>",'NewsLetterEmailError');
						document.NewsLetterForm.NewsLetterEmail.focus();
		                return false;
					
		} else {
				 	open_window('SubscribeToNewsLetter.php?email='+document.NewsLetterForm.NewsLetterEmail.value);
					return false;
		}
	}
function checkfield()
{

		var myflage=true;
		if(document.registration_form.user_name.value=='')
		{
			show_error("<font class='error'>Pleae enter your username </font>",'div_user_name');
			myflage=false;
			  
		}else{
			 check_user_name('check_user_name.php?user_name='+document.registration_form.user_name.value);
			// alert(document.registration_form.naeem.value);
			if(document.registration_form.naeem.value==1){
				myflage=false;
			}
			 // alert(newtext);
			  hide_error('div_user_name');			  
			  
		}
		
		// for email
		if(document.registration_form.txt_email.value=='')
		{
		  show_error("<font class='error'>Please enter your email.</font>",'div_email');
		  myflage=false;
		  
		}
		else if(document.registration_form.txt_email.value!='')
		{
			 if (echeck(document.registration_form.txt_email.value)==false) {
						show_error("<font class='error'>Invalid email.</font>",'div_email');
		                myflage=false;
						
			 } else {
				//  check_email('check_email.php?email='+document.registration_form.txt_email.value);
					if(document.registration_form.temp.value==1){
						myflage=false;
					}
				hide_error('div_email');			 
			 }
		}
		//for re-type email
		if((document.registration_form.txt_email.value!='')&&(document.registration_form.txt_email.value!=document.registration_form.txt_email_confirm.value)){
			show_error("<font class='error'>We’re sorry, emails do not match.</font>",'div_email_confirm');
            myflage=false;
		}else{
			hide_error('div_email_confirm');			 	
		}		
		
		//for password
		if(document.registration_form.txt_password.value==''){
			show_error("<font class='error'>Pleae enter your password.</font>",'div_password');
            myflage=false;
		}else if(document.registration_form.txt_password.value.length<6){
			show_error("<font class='error'>Passwords should be minimum of 6 characters</font>",'div_password');
            myflage=false;			
		}else{
			hide_error('div_password');			 	
		}		
		
		//agree

		 if(document.registration_form.agree.checked == false){
			 show_error("<font class='error'>Please read the Terms of Use and check the box to indicate your acceptance.</font>",'div_agree');
			 myflage=false;		
		}else{
			hide_error('div_agree');			 	
		}

		
		//if all errors true
		if(myflage==true){
		 document.registration_form.submit();
		}
	
}//end form===========================================================================================

function makeObject()
{
	var x; 
	var browser = navigator.appName; 
	//detect the client browser
	if(browser == "Microsoft Internet Explorer"){
	x = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
	x = new XMLHttpRequest();
	}
	return x;
}

//call the function makeObject()
var request = makeObject();
var new_request = makeObject();
var rate_request = makeObject();
var group_request = makeObject();
var request_interest = makeObject();
var request_linked_profile = makeObject();
var request_requested_deals = makeObject();

//function send request
function CheckAvailUser(url){
		if(document.registration_form.UserName.value==''){
			show_error('<font color="red">Username is empty!</font>','CheckUserMsg');
		}else{
				hide_error('ExecuteErrorUserName');
				hide_error('CheckUserMsg');
				document.getElementById('CheckUser').style.display = "block";
				request.open('POST', url);	
				request.onreadystatechange = function () {
				if (request.readyState == 4) {
						responsestring = request.responseText;
						var msg = responsestring.split("=");
					if (msg[1] == 'sorry') {
							document.getElementById('CheckUser').style.display = "none";
							show_error('<font color="red">We’re sorry it’s already taken.</font>','CheckUserMsg');
							
					}else {				
							document.getElementById('CheckUser').style.display = "none";
							show_error('<font color="blue">Available.</font>','CheckUserMsg');
					}		
		
				}	
			}		
			request.send('');
		}
			

	
}
//function send request
function CheckAvailEmail(url){
		if(document.registration_form.UserEmail.value==''){
			show_error('<font color="red">Email is empty!</font>','CheckEmailMsg');
		}else if (echeck(document.registration_form.UserEmail.value)==false) {
			show_error("<font color='red'>Invalid email.</font>",'CheckEmailMsg');		     	
		}else{
				hide_error('ExecuteErrorEmail');
				hide_error('CheckEmailMsg');
				document.getElementById('CheckEmail').style.display = "block";
				request.open('POST', url);	
				request.onreadystatechange = function () {
				if (request.readyState == 4) {
						responsestring = request.responseText;
						var msg = responsestring.split("=");
					if (msg[1] == 'sorry') {
							document.getElementById('CheckEmail').style.display = "none";
							show_error('<font color="red">We’re sorry it’s already taken.</font>','CheckEmailMsg');
							
					}else {				
							document.getElementById('CheckEmail').style.display = "none";
							show_error('<font color="blue">Available.</font>','CheckEmailMsg');
					}		
		
				}	
			}		
			request.send('');
		}
}
function CheckAllFields()
	{
		var ReturnValue 	= true;	
		
		if(document.registration_form.UserName.value==''){
			show_error('<font color="red">Username is empty!</font>','CheckUserMsg');
			ReturnValue		= false; 			
		}else{
			hide_error('CheckUserMsg');	
		}
		
		if(document.registration_form.UserEmail.value==''){
			show_error('<font color="red">Email is empty!</font>','CheckEmailMsg');
			ReturnValue		= false; 			
		}else if (echeck(document.registration_form.UserEmail.value)==false) {
			show_error("<font color='red'>Invalid email.</font>",'CheckEmailMsg');		     	
			ReturnValue		= false; 			
		}else{
			hide_error('CheckEmailMsg');	
		}
		
		if(document.registration_form.UserPassword.value==''){
			show_error('<font color="red">Password is empty!</font>','CheckPassMsg');
			ReturnValue		= false; 			
		}else{
			hide_error('CheckPassMsg');	
		}

		if((document.registration_form.UserPasswordConfirm.value!=document.registration_form.UserPassword.value)&&(document.registration_form.UserPassword.value!='')){
			show_error('<font color="red">Confirm Your Password.</font>','CheckPassConfMsg');
			ReturnValue		= false; 			
		}else{
			hide_error('CheckPassConfMsg');	
		}


		
		return ReturnValue;

	}
	
function ValidateForm()
	{
		var ReturnValue 	= true;	
		var l_CountryNameSelection = document.getElementById('Country').options[document.getElementById('Country').selectedIndex].text;


		if(document.registration_form.Name.value==''){
			show_error('<font color="red">Name is empty!</font>','CheckUserMsg');
			ReturnValue		= false; 			
		}else{
			hide_error('CheckUserMsg');	
		}
		
		if(document.registration_form.Email.value==''){
			show_error('<font color="red">Email is empty!</font>','CheckEmailMsg');
			ReturnValue		= false; 			
		}else if (echeck(document.registration_form.Email.value)==false) {
			show_error("<font color='red'>Invalid email.</font>",'CheckEmailMsg');		     	
			ReturnValue		= false; 			
		}else{
			hide_error('CheckEmailMsg');	
		}
		
		if(document.registration_form.Company.value==''){
			show_error('<font color="red">Company is empty!</font>','CheckCompanyMsg');
			ReturnValue		= false; 			
		}else{
			hide_error('CheckCompanyMsg');	
		}		
		if(l_CountryNameSelection=='(Select a Country)'){
			show_error('<font color="red">Country is empty!</font>','CheckDeliveryCountryMsg');
			ReturnValue		= false; 			

		}else{
			hide_error('CheckDeliveryCountryMsg');	
		}
		if(document.registration_form.Phone.value==''){
			show_error('<font color="red">Business Phone is empty!</font>','CheckPhoneMsg');
			ReturnValue		= false; 			
		}else{
			hide_error('CheckPhoneMsg');	
		}
		//alert(document.registration_form.DeliveryCountry.value+'@@');
		/*if(document.registration_form.DeliveryCountry.value==''){
			show_error('<font color="red">Country is empty!</font>','CheckDeliveryCountryMsg');
			ReturnValue		= false; 			
		}else{
			hide_error('CheckDeliveryCountryMsg');	
		}*/
		return ReturnValue;

	}

//end tags=========================================================================================
function NumericCheck(fl)
 {
   var checkOK = "0123456789.";
   var checkStr;
   var allValid;
   var decPoints;
   var allNum;

   checkStr = fl
   allValid = true;
   decPoints = 0;
   allNum = "";

   for (k = 0;  k < checkStr.length;  k++)
   {
    ch = checkStr.charAt(k);
    for (l = 0;  l < checkOK.length;  l++)
      if (ch == checkOK.charAt(l)) break;
      if (l == checkOK.length)
      {
        allValid = false;
        break;
      }
      if (ch != ",") allNum += ch;
    }

   if (!allValid)
   {
  //  alert("Please enter only digit characters in the \"Numeric\" field.");
    return (false);
   }
   
   return (true);
}
function PlayAudio(file)
{
		window.open('PlayAudio.php?file='+file,"mywindow","menubar=1,resizable=1,width=440,height=190,location=0");
}
function DownloadFile(file)
{
		//alert(file);
		window.open('DownloadFile.php?file='+file,"mywindow","menubar=1,resizable=1,width=440,height=190,location=0");
}


function PlayVideo(file)
{
	//alert(file);
		window.open('PlayVideo.php?file='+file,"mywindow","menubar=1,resizable=1,width=440,height=390,location=0");
}

//open pop up==============================================
function open_window(page){
	 window.open (page, "dealarmy", "location=0,status=1,menubar=no,resizable=yes,scrollbars=1");
	}
//random image display==================================================
								
 var img_rnd = new Array("images/011 BANER 9X3.JPG", 
								 "images/002 BANER 9X3.JPG",
								 "images/003 BANER 9X3.JPG",								 
								 "images/004 BANER 9X3.JPG",
								 "images/005 BANER 9X3.JPG",
								 "images/006 BANER 9X3.JPG",
								 "images/007 BANER 9X3.JPG",
								 "images/008 BANER 9X3.JPG",
								 "images/009 BANER 9X3.JPG",
								 "images/010 BANER 9X3.JPG",
								 "images/011 BANER 9X3.JPG"								 
								 );
 var i = Math.round(4*Math.random());
 var img_rnd = new Array("images/011 BANER 9X3.JPG", 
								 "images/002 BANER 9X3.JPG",
								 "images/003 BANER 9X3.JPG",								 
								 "images/004 BANER 9X3.JPG",
								 "images/005 BANER 9X3.JPG",
								 "images/006 BANER 9X3.JPG",
								 "images/007 BANER 9X3.JPG",
								 "images/008 BANER 9X3.JPG",
								 "images/009 BANER 9X3.JPG",
								 "images/010 BANER 9X3.JPG",
								 "images/011 BANER 9X3.JPG"								 
								 );
var i = Math.round(4*Math.random());



		
		/*function check()
		{
		var img_name = new Array("images/011 BANER 9X3.JPG", 
								 "images/002 BANER 9X3.JPG",
								 "images/003 BANER 9X3.JPG",								 
								 "images/004 BANER 9X3.JPG",
								 "images/005 BANER 9X3.JPG",
								 "images/006 BANER 9X3.JPG",
								 "images/007 BANER 9X3.JPG",
								 "images/008 BANER 9X3.JPG",
								 "images/009 BANER 9X3.JPG",
								 "images/010 BANER 9X3.JPG",
								 "images/011 BANER 9X3.JPG"								 
								 );
		
		var l = img_name.length;
		
		var rnd_no = Math.round((l-1)*Math.random());
		
		document.r_img.src = img_name[rnd_no];
	}*/

								
