
function getCalendarDate()
{
   var months = new Array(13);
   months[0]  = "01";
   months[1]  = "02";
   months[2]  = "03";
   months[3]  = "04";
   months[4]  = "05";
   months[5]  = "06";
   months[6]  = "07";
   months[7]  = "08";
   months[8]  = "09";
   months[9]  = "10";
   months[10] = "11";
   months[11] = "12";
   var now         = new Date();
   var monthnumber = now.getMonth();
   var monthname   = months[monthnumber];
   var monthday    = now.getDate();
   if (monthday   < 10) { monthday   = "0" + monthday;   }
   var year        = now.getYear();
   if(year < 2000) { year = year + 1900; }
   var dateString = monthname +
                    '/' +
                    monthday +
                    '/' +
                    year;
   return dateString;
} // function getCalendarDate()

function getClockTime()
{
   var now    = new Date();
   var hour   = now.getHours();
   var minute = now.getMinutes();
   var second = now.getSeconds();
   var ap = "AM";
   if (hour   > 11) { ap = "PM";             }
   if (hour   > 12) { hour = hour - 12;      }
   if (hour   == 0) { hour = 12;             }
   if (hour   < 10) { hour   = "0" + hour;   }
   if (minute < 10) { minute = "0" + minute; }
   if (second < 10) { second = "0" + second; }
   var timeString = hour +
                    ':' +
                    minute +
                    ':' +
                    second +
                    " " +
                    ap;
   return timeString;
} // function getClockTime()

function CalculateOrder(form) {
 var coup1="GOLD10";
 var coup2="GOLD15";
 var coup3="GOLD20";

 var calendarDate = getCalendarDate();
 var clockTime = getClockTime();
 var calanderNow = calendarDate + ' ' + clockTime;
 var beginDate;
 var endDate;
 var b,e,c;
 
 if (form.text1.value == coup1)
 {
 beginDate = "05/12/2010 12:00:00 AM";
 endDate = "06/12/2010 12:00:00 AM";

 b = Date.parse(beginDate);

 e = Date.parse(endDate);

 c = Date.parse(calanderNow);

 if((c <= e && c >= b)) {

 form.discount_rate.value = "10";
 form.discount_rate2.value = "10";
 form.on0.value = "Coupon";
 form.os0.value = "GOLD10 - Discount 10%";

 }
 }

 if (form.text1.value == coup2)
 {
 beginDate = "04/12/2010 12:00:00 AM";
 endDate = "05/12/2010 12:00:00 AM";

 b = Date.parse(beginDate);

 e = Date.parse(endDate);

 c = Date.parse(calanderNow);

 if((c <= e && c >= b)) {

 form.discount_rate.value = "15";
 form.discount_rate2.value = "15";
 form.on0.value = "Coupon";
 form.os0.value = "GOLD15 - Discount 15%";

 }
 }

 if (form.text1.value == coup3)
 {
 beginDate = "04/13/2010 12:00:00 AM";
 endDate = "05/13/2010 12:00:00 AM";

 b = Date.parse(beginDate);

 e = Date.parse(endDate);

 c = Date.parse(calanderNow);

 if((c <= e && c >= b)) {

 form.discount_rate.value = "20";
 form.discount_rate2.value = "20";
 form.on0.value = "Coupon";
 form.os0.value = "GOLD20 - Discount 20%";

 }
 }
//alert (b + " : " + e + " : " + c);

}


//function to check empty fields

function isEmpty(strfield1, strfield2, strfield3, strfield4, strfield5, strfield6) {


  //firstname field
    if (strfield1 == "" || strfield1 == null || !isNaN(strfield1) || strfield1.charAt(0) == ' ')
    {
    alert("\"First Name\" is a mandatory field.\nPlease amend and retry.");
    return false;
    }

  //lastneme field 
    if (strfield2 == "" || strfield2 == null || strfield2.charAt(0) == ' ')
    {
    alert("\"Last Name\" is a mandatory field.\nPlease amend and retry.");
    return false;
    }

  //area code field 
    if (strfield3 == "" || strfield3 == null || strfield3.charAt(0) == ' ')
    {
    alert("\"Area Phone Code\" is a mandatory field.\nPlease amend and retry.");
    return false;
    }
 //city code field 
    if (strfield4 == "" || strfield4 == null || strfield4.charAt(0) == ' ')
    {
    alert("\"City Phone Code\" is a mandatory field.\nPlease amend and retry.");
    return false;
    }
//phone no field 
    if (strfield5 == "" || strfield5 == null || strfield5.charAt(0) == ' ')
    {
    alert("\"Phone No\" is a mandatory field.\nPlease amend and retry.");
    return false;
    }

    return true;
}


//function to check valid email address
function isValidEmail(strEmail){
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;

   // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1) 
   {
      alert('A valid e-mail address is required.\nPlease amend and retry');
      return false;
    } 
    return true; 
}


function validatePhone(field1, field2, field3) {


if (field1.length!=3) {
alert("Please enter your 3 digit area phone code.");
return false;
}

if (field2.length!=3) {
alert("Please enter your 3 digit city phone code.");
return false;
}

if (field3.length!=4) {
alert("Please enter your 4 digit phone no.");
return false;
}

return true;

}


function ValidateOrder(form) {
if (isEmpty(form.strFirstName.value, form.strLastName.value, form.strPhoneA.value, form.strPhoneB.value, form.strPhoneC.value, form.strEmail.value)){
	    if (validatePhone(form.strPhoneA.value, form.strPhoneB.value, form.strPhoneC.value)){
		  var answer = confirm  ("Please click on OK if you got Discount Coupon, or CANCEL to make Payment.");
		  if (answer){
		  form.strRedirect.value="No";
		  }
		  else
		  {
		  form.strRedirect.value="Go";

		  }

		  return true;
	    }
}
return false;
}

function Trim(str)
{

  return LTrim(RTrim(str));

}

function LTrim(str)
{

  for (var i=0; str.charAt(i)==" "; i++)
  {
    str =  str.substring(i,str.length-1);
  }
  return str;
}

function RTrim(str)
{

  for (var i=str.length-1; str.charAt(i)==" "; i--)
  {
    str = str.substring(0,i);
  }
  return str;
}

function GetElementsByPrefix(inPrefix,inRoot){
var elem_array = new Array;
if(typeof inRoot.firstChild!= 'undefined'){
var elem = inRoot.firstChild;
while (elem!= null){
if(typeof elem.firstChild!= 'undefined'){
elem_array = elem_array.concat(GetElementsByPrefix(inPrefix,elem));
}
if(typeof elem.id!= 'undefined'){
var reg = new RegExp ( '^'+inPrefix+'.*' );
if(elem.id.match(reg)){
elem_array.push(elem);
}
}
elem = elem.nextSibling;
}
}
return elem_array;
}

function CompareDates(str1, str2)
{
    var date1 = Date.parse(str1);
    var date2 = Date.parse(str2);

    if(date2 > date1)
    {
        return false;
    }
    else
    {
	return true;
    }
} 

function DisplayElements(in_elem_array){
var months = new Array(13);
months[0]  = "01";
months[1]  = "02";
months[2]  = "03";
months[3]  = "04";
months[4]  = "05";
months[5]  = "06";
months[6]  = "07";
months[7]  = "08";
months[8]  = "09";
months[9]  = "10";
months[10] = "11";
months[11] = "12";
var compareDate;
var now         = new Date();
var monthnumber = now.getMonth();
var monthname   = months[monthnumber];
var monthday    = now.getDate();
if (monthday   < 10) { monthday   = "0" + monthday;   }
var year        = now.getYear();
if(year < 2000) { year = year + 1900; }
var clockTime = getClockTime();
var newDate = monthname +
                    '/' +
               monthday +
                    '/' +
                   year + 
                    ' ' + 
               clockTime;

if(in_elem_array.length){
for(var c=0; c<in_elem_array.length; c++){
compareDate = Trim(in_elem_array[c].id).substring((Trim(in_elem_array[c].id).length-10),Trim(in_elem_array[c].id).length) + ' 08:30:00 AM';

  if (CompareDates(newDate, compareDate)){
      document.getElementById(in_elem_array[c].id).innerHTML = "<span class='style35'>&nbsp;</span>";
      //alert(newDate + " : " + compareDate);
  }
}
}
}

