var SITE_URL      = 'http://www.europashoes.co.za/';
var SITE_SWFU     = SITE_URL+'SWFU/iyona/';
//============================================================================// date formate functuion from @ http://blog.stevenlevithan.com/archives/date-time-format
var dateFormat = function () {
   var	token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
   timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
   timezoneClip = /[^-+\dA-Z]/g,
   pad = function (val, len) {
      val = String(val);
      len = len || 2;
      while (val.length < len) val = "0" + val;
      return val;
   };

   // Regexes and supporting functions are cached through closure
   return function (date, mask, utc) {
      var dF = dateFormat;

      // You can't provide utc if you skip other args (use the "UTC:" mask prefix)
      if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
         mask = date;
         date = undefined;
      }

      // Passing date through Date applies Date.parse, if necessary
      date = date ? new Date(date) : new Date;
      if (isNaN(date)) throw SyntaxError("invalid date");

      mask = String(dF.masks[mask] || mask || dF.masks["default"]);

      // Allow setting the utc argument via the mask
      if (mask.slice(0, 4) == "UTC:") {
         mask = mask.slice(4);
         utc = true;
      }

      var	_ = utc ? "getUTC" : "get",
      d = date[_ + "Date"](),
      D = date[_ + "Day"](),
      m = date[_ + "Month"](),
      y = date[_ + "FullYear"](),
      H = date[_ + "Hours"](),
      M = date[_ + "Minutes"](),
      s = date[_ + "Seconds"](),
      L = date[_ + "Milliseconds"](),
      o = utc ? 0 : date.getTimezoneOffset(),
      flags = {
         d:    d,
         dd:   pad(d),
         ddd:  dF.i18n.dayNames[D],
         dddd: dF.i18n.dayNames[D + 7],
         m:    m + 1,
         mm:   pad(m + 1),
         mmm:  dF.i18n.monthNames[m],
         mmmm: dF.i18n.monthNames[m + 12],
         yy:   String(y).slice(2),
         yyyy: y,
         h:    H % 12 || 12,
         hh:   pad(H % 12 || 12),
         H:    H,
         HH:   pad(H),
         M:    M,
         MM:   pad(M),
         s:    s,
         ss:   pad(s),
         l:    pad(L, 3),
         L:    pad(L > 99 ? Math.round(L / 10) : L),
         t:    H < 12 ? "a"  : "p",
         tt:   H < 12 ? "am" : "pm",
         T:    H < 12 ? "A"  : "P",
         TT:   H < 12 ? "AM" : "PM",
         Z:    utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
         o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
         S:    ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
      };

      return mask.replace(token, function ($0) {
         return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
      });
   };
}();

// Some common format strings
dateFormat.masks = {
   "default":      "ddd mmm dd yyyy HH:MM:ss",
   shortDate:      "m/d/yy",
   mediumDate:     "mmm d, yyyy",
   longDate:       "mmmm d, yyyy",
   fullDate:       "dddd, mmmm d, yyyy",
   shortTime:      "h:MM TT",
   mediumTime:     "h:MM:ss TT",
   longTime:       "h:MM:ss TT Z",
   isoDate:        "yyyy-mm-dd",
   isoTime:        "HH:MM:ss",
   isoDateTime:    "yyyy-mm-dd'T'HH:MM:ss",
   isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
};

// Internationalization strings
dateFormat.i18n = {
   dayNames: [
   "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
   "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
   ],
   monthNames: [
   "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
   "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
   ]
};

// For convenience...
Date.prototype.format = function (mask, utc) {
   return dateFormat(this, mask, utc);
};
//get the week number
Date.prototype.getWeek = function () {
   // Create a copy of this date object
   var target  = new Date(this.valueOf());

   // ISO week date weeks start on monday
   // so correct the day number
   //var dayNr   = (this.getDay() + 6) % 7; //if monday is the start of the week
   var dayNr   = this.getDay();
   // Set the target to the thursday of this week so the
   // target date is in the right year
   //target.setDate(target.getDate() - dayNr + 3);  //if week start with monday
   target.setDate(target.getDate() - dayNr + 4);

   // ISO 8601 states that week 1 is the week
   // with january 4th in it
   var jan4    = new Date(target.getFullYear(), 0, 4);

   // Number of days between target date and january 4th
   var dayDiff = (target - jan4) / 86400000;

   // Calculate week number: Week 1 (january 4th) plus the
   // number of weeks between target date and january 4th
   //var weekNr = 1 + Math.ceil(dayDiff / 7);
   var weekNr = Math.ceil(dayDiff / 7);

   return weekNr;
}
Date.prototype.getWeekYear = function ()
{
   // Create a new date object for the thursday of this week
   var target  = new Date(this.valueOf());
   //target.setDate(target.getDate() - ((this.getDay() + 6) % 7) + 3);  //mionday week start
   target.setDate(target.getDate() - this.getDay() + 4);

   return target.getFullYear();
}
//============================================================================// calculate the numbr of days in a month
cal_days_in_month = function (iMonth, iYear) {
   return 32 - new Date(iYear, iMonth, 32).getDate();
}//endfunction
//============================================================================// Move to a specific date of the week in a month
moveToDayOfWeek = function (tmp_date, cnt_week, option, loop){

   option= (!option)?1:option;
   cnt   = 0;
   do {
      target_date = tmp_date.setDate(tmp_date.getDate()+option);
      cnt++;
   //$('#debug').append(dateFormat(target_date,'yyyy mm d')+' tmp='+loop+cnt+"<br/>");
   } while (dateFormat(target_date,'ddd')!=cnt_week );
   return target_date;
}//endfunction
//============================================================================// pop up did
div_display = function (div_name, setPosition, option, x, y) {
   var div = $(div_name);
   if(!isset(x)) x=0;
   if(!isset(y)) y=0;
   // if the style.display value is blank we try to check it out here

   if(div.css('display')== '' && div.css('width') != undefined && div.css('height') != undefined) {
      div.css('display') = (div.css('width')!=0 && div.css('height')!=0)?'block':'none';
   }
   display = (div.css('display')==''||div.css('display')=='block')?'none':'block';
   div.css('display',display);
       
   if (setPosition==true){
      div.style.left = X+x+'px';
      div.style.top  = Y+y+'px';
   }
   if (setPosition=='custom'){
      div.css('left') = x+'px';
      div.css('top')  = y+'px';
   }
   if (setPosition=='center'){
      height = document.documentElement.clientHeight?document.documentElement.clientHeight:document.body.clientHeight;
      width  = document.documentElement.clientWidth?document.documentElement.clientWidth:document.body.clientWidth;
      div.css('left',(parseFloat(width) / 2) - (400 / 2));
      div.css('top',(parseFloat(height) / 2) - (400 / 2));
   }
}
//============================================================================//
function pop_out(div_name,div_pop,h,w,t,l) {

   div_display(div_name);

   height = document.documentElement.clientHeight?document.documentElement.clientHeight:document.body.clientHeight;
   width  = document.documentElement.clientWidth?document.documentElement.clientWidth:document.body.clientWidth;
   $(div_name).css({'width':width,'height':height});

   if (div_pop) {
      if (!h) h = '680px';
      if (!w) w = '650px';
      if (!t) t = '10%';
      if (!l) l = (parseFloat(width) / 2) - (400 / 2)+'px';

      $(div_pop).style.height  = h;
      $(div_pop).style.width   = w;
      $(div_pop).style.top     = t;
      $(div_pop).style.left    = l;
   }
   return true;
}//endfunction
//============================================================================//
function isset() {
   var a=arguments;
   var l=a.length;
   var i=0;

   if (l==0) {
      throw new Error('Empty isset');
   }//end if

   while (i!=l) {
      if (typeof(a[i])=='undefined' || a[i]===null) {
         return false;
      } else {
         i++;
      }//endif
   }
   return true;
}//end function
//============================================================================//FORM VALIDATION

function isValidEmail(email) {
   var error = 0;

   AtPos    = email.indexOf("@")
   StopPos  = email.lastIndexOf(".")
   if (email == "")                  error = 1;
   if (AtPos == -1 || StopPos == -1) error = 1;
   if (StopPos < AtPos)              error = 1;
   if (StopPos - AtPos == 1)         error = 1;
   if (error == 1) {
      return false;
   } else {
      return true;
   }
} // email chking function called
//============================================================================//
function check_email(field) {
   var msg  = "";

   email    = $(field);
   if (!email.length)            return msg;
   if (email[0].tagName!='INPUT')return msg;
   if (email.val()=='')          return msg;
   if (!isValidEmail(email.val())) {
      msg = msg + 'Invalid email address supplied for '+ email.id+"<br/> \r\n";
   }//endif

   return msg;
}// chk if it is a valid email and calls the funstion to chk if it is an email
//============================================================================//
function check_number(field,name) {
   var msg  = '';

   field    = $(field);
   if (!field.length)            return msg;
   if (field[0].tagName!='SELECT' && field[0].tagName!='INPUT' && field[0].tagName!='TEXTAREA') {return msg};
   
   var str  = field.val().replace(' ','');
   var find = str.search('[^0-9\,\.\t\s\d]');
   if (field.val().length > 0 && find >=0){
      msg = "please enter a numeric value for the flield "+name+"\r\n";
   }//endif
   
   return msg;
}//endfunc
//============================================================================//
function check_required(formobj,array_name, array_name_desc) {
   var fieldRequired    = array_name;
   var fieldDescription = array_name_desc;
   var msg              = "Please complete the following fields:<br/> \r\n";

   var l_Msg = msg.length;
   for (var i = 0; i < fieldRequired.length; i++){
      var obj           = $(fieldRequired[i])[0];
      if (obj){
         switch(obj.type){
            case "select-one":
               if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == "" || obj.options[obj.selectedIndex].value == ''){
                  msg += " - " + fieldDescription[i] + "<br/>  \r\n";
               }//endif
               break;
            case "select-multiple":
               if (obj.selectedIndex == -1){
                  msg += " - " + fieldDescription[i] + "<br/> \r\n";
               }//endif
               break;
            case "text":
            case "password":
            case "textarea":
               exp            = /[0-9a-zA-Z]+/;
               if (obj.value == "" || obj.value == null || !obj.value.match(exp)){
                  msg += " - " + fieldDescription[i] + "<br/> \r\n";
               }//endif
               break;
            default:
               break;
         }//endSwitch
         if (obj.type == undefined){
            var blnchecked = false;
            for (var j = 0; j < obj.length; j++){
               if (obj[j].checked){
                  blnchecked = true;
               }//endif
            }//endofor
            if (!blnchecked){
               msg += " - " + fieldDescription[i] + "<br/> \r\n ";
            }//endif
         }//endif
      }//endif obj
   }//endfor

   if (msg.length == l_Msg){
      return '';
   }else{
      return msg;
   }
}//end function
//============================================================================//
function check_default_value(field,deflt) {

   field = $(field)[0];
   if (!field.value)            return false;
   if (!isset(deflt)) deflt = field.defaultValue;
   if (deflt==field.value) {
      field.value='';
      field.focus();
      //field.className='myfont';
      field.style.color = '#000';
   }
   return true;
}
//============================================================================//
function check_length(field,leng) {   
   var msg  = '';

   field    = $(field)[0];
   if (!field.length)            return false;
   if (field.tagName!='SELECT' && field.tagName!='INPUT' && field.tagName!='TEXTAREA') {return msg;}
   if (field.value.length < leng  ) {
      msg = 'Please enter at least '+leng+' character for the field '+field+'<br/>  \r\n';
   }//end if

   return msg;
}//end function
//============================================================================//
function check_password(field1, field2) {
   var field   = $(field1)[0];
   var confrm  = field2?$(field2)[0]:$('#passConfirm')[0];

   if (!field.length)            return false;
   if (!confrm) $('input:password')[0];
   var msg     = '';

   if (field.tagName!='SELECT' && field.tagName!='INPUT' && field.tagName!='TEXTAREA') {return msg;}   
   var pw1  = field.value;
   pw2 = confrm.value;   

   if (pw1 != pw2) {
      msg   = "Please re-enter your "+field+".<br /> \r\n";
   }
   return msg;
}//end function
////============================================================================//
function verify_password(field1, verify) {
   var field= $(field1)[0];   
   var msg  = '';

   if (field.tagName!='SELECT' && field.tagName!='INPUT' && field.tagName!='TEXTAREA') {return msg;}
   if (field.value != verify) {msg   = "Please verify your "+field.id+".<br /> \r\n";}
   return msg;
}//end function
//============================================================================//
function get_ascii(ascii) {
   switch (ascii) {
      case '0': return '&#48;';case '1': return '&#49;';case '2': return '&#50;';case '3': return '&#51;';case '4': return '&#52;';case '5': return '&#53;';case '6': return '&#54;';case '7': return '&#55;';case '8': return '&#56;';case '9': return '&#57;';
      default : return 0;
   }
}
//============================================================================//
function set_ascii(ascii) {
   switch (ascii) {
      case '&#48;': return '0';case '&#49;': return '1';case '&#50;': return '2';case '&#51;': return '3';case '&#52;': return '4';case '&#53;': return '5';case '&#54;': return '6';case '&#55;': return '7';case '&#56;': return '8';case '&#57;': return '9';
   }
}
////============================================================================//
function secure_verification() {
   var belmondo= $('#iyona_number').html();
   var jeanpaul= $('#iyona_second').html();
   var reply   = $('#cantTouchThis').val();
   
   if ((parseInt(belmondo)+parseInt(jeanpaul))==reply) return '';
   else {return 'The security equation is wrong';};

}//end function
////============================================================================//
function secure_generated() {
   var belmondo= get_ascii($('#the_first_voyageur').text().charAt(5));//alert($('#the_first_voyageur').text().charAt(5)+'--'+belmondo);
   var jeanpaul= get_ascii($('#the_second_voyageur').text().charAt(5));
   $('#iyona_number').html(belmondo);
   $('#iyona_second').html(jeanpaul);
   
}//end function
$(document).ready(function(){secure_generated();});
//============================================================================//
var submitcount=0;
function check_submit(){
   if (submitcount == 0)      {
      submitcount++;
      return '';
   } else {
      return "This form has already been submitted.  Thanks!<br/> \r\n";

   }
}//end function
//============================================================================//
function submit_form(elementId, browser, frm) {

   if(browser=='IE') document.forms[elementId].submit();
   else document.getElementById(elementId).submit();

}
//============================================================================//
function preload_images() { //v3.0
   var doc=document;
   if(doc.images){

      if(!doc.preload_image_object) doc.preload_image_object=new Array();

      var i,j=doc.preload_image_object.length,url=preload_images.arguments;

      for(i=0; i<url.length; i++){
         if (url[i].indexOf("#")!=0){
            doc.preload_image_object[j]=new Image;
            doc.preload_image_object[j++].src=url[i];//alert(url[i]);
         }
      }
   }
}
//============================================================================//
function detect_browser(){
   var browser = '';
   browser = navigator.appVersion;
   if (browser.indexOf('MSIE 8') != -1) return 'IE8';
   if (browser.indexOf('MSIE') != -1) return 'IE';
}
//============================================================================//
function start_position(){

      if (!document.all) document.captureEvents(Event.MOUSEMOVE)
      document.onmousemove = get_position;
      $('#debug')[0].innerHTML = X+' and '+Y;
}
var X = 0;
var Y = 0;
//============================================================================//
function get_position(args) {

  // Gets IE browser position
  if (document.all)   {
    X = event.clientX + (document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft)
    Y = event.clientY + (document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop)
  }
  // Gets position for other browsers
  else  {
    X = args.pageX
    Y = args.pageY
  }
  if (X < 0) X=0;
  if (Y < 0) Y=0;

}
//============================================================================//
function getHtmlPosition(obj, all,type){
    var topValue= 0,leftValue= 0;
    if (all==true){
       while(obj){
         leftValue+= obj.offsetLeft;
         topValue+= obj.offsetTop;
         obj= obj.offsetParent;
       }
    } else {
       leftValue= obj.offsetLeft;
       topValue = obj.offsetTop;
    }
    if (type=='x') return parseInt(leftValue);
    else return parseInt(topValue);
}
//============================================================================//DATE FUNCTIONS
   var currentDate = new Date();
   var today   = currentDate.getDay();
   var thisyr  = currentDate.getFullYear();

   function jsDelAll(dayID) {

      var dayObj = document.getElementById(dayID);
      var ngLen = dayObj.options.length;

      for (x = ngLen; x >= 0; x--) {
          dayObj.options[x] = null;
      }//next x

      dayObj.options.lenth = 0;
   }//end function

   function createDays(max, dayID) {

      var dayObj = document.getElementById(dayID);
      jsDelAll(dayID);

      for (x = 1; x <= max; x++) {
          dayObj.options[x - 1] = new Option(x, x);
      }//next x
   }//end function

   function updateDays(monID, dayID) {

      var monObj = document.getElementById('month_'+monID);
      var selMon = monObj.value;


      if (selMon == 1 || selMon == 3 || selMon == 5 || selMon == 7 || selMon == 8 || selMon == 10 || selMon == 12) {
         createDays(31, dayID);
      } else if (selMon == 4 || selMon == 6 || selMon == 9 || selMon == 11) {
         createDays(30, dayID);
      } else if (selMon == 2) {
         if (thisyr == 1984 || thisyr == 1988 || thisyr == 1992 || thisyr == 1996 || thisyr == 2000 || thisyr == 2004 || thisyr == 2008 || thisyr == 2012) {
            createDays(29, dayID);
         } else {
            createDays(28, dayID);
         }//end if
      }//end if
      setHiddenDate(monID);
   }//end function

   function setHiddenDate(selName,time){
      var year       = document.getElementById('year_'+selName).value;
      var month      = document.getElementById('month_'+selName).value;
      var day        = document.getElementById('day_'+selName).value;
      var dateChosen = year+'-'+month+'-'+day
      try {
         var hour    = document.getElementById('hour_'+selName).value;
         var minute  = document.getElementById('minute_'+selName).value;
         dateChosen  = dateChosen+' '+hour+':'+minute;
      } catch (err){err;}
      document.getElementById(selName).value = dateChosen;

   }//end function sethideendate

get_time = function(name, set) {
	father	= name.parentNode;
	child		= father.childNodes;
	var field,x,h,m,t;

	for(x=0; x<child.length;x++){
		field = child[x];
		if(field.id == set+'_hours')	h = field.value;
		if(field.id == set+'_min')		m = field.value;
		if(field.id == set)				t = field;
	};
	t.value = h +':'+m;
}//end function
//============================================================================//
//============================================================================//
//============================================================================//
