// JavaScript Document

<!-- Copyright 2006,2007 Bontrager Connection, LLC
// http://bontragerconnection.com/ and http://www.willmaster.com/
// Version: July 28, 2007
var cX = 0; var cY = 0; var rX = 0; var rY = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }
function AssignPosition(d) {
if(self.pageYOffset) {
	rX = self.pageXOffset;
	rY = self.pageYOffset;
	}
else if(document.documentElement && document.documentElement.scrollTop) {
	rX = document.documentElement.scrollLeft;
	rY = document.documentElement.scrollTop;
	}
else if(document.body) {
	rX = document.body.scrollLeft;
	rY = document.body.scrollTop;
	}
if(document.all) {
	cX += rX; 
	cY += rY;
	}
//d.style.left = (cX+10) + "px";
//d.style.top = (cY+10) + "px";
//alert(cY);
d.style.left = "30%";
d.style.top =  document.documentElement.scrollTop+15;

}
function HideContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd);
dd.style.display = "block";
}
function ReverseContentDisplay(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd);
if(dd.style.display == "none") { dd.style.display = "block"; }
else { dd.style.display = "none"; }
}


function validate_email(field,alerttxt)
{
	with (field)
	{
	apos=value.indexOf("@");
	dotpos=value.lastIndexOf(".");
	if (apos<1||dotpos-apos<2) 
	  {alert(alerttxt);return false;}
	else {return true;}
	}
}

function isPhoneNum(str) {

  if (str.length != 12) { 
    return false }
  for (j=0; j<str.length; j++) {
    if ((j == 3) || (j == 7)) {
      if ((str.charAt(j) != "-") && (str.charAt(j) != "/")) { return false }
    } else {
      if ((str.charAt(j) < "0") || (str.charAt(j) > "9")) { return false }
    }
  }
  return true;
}

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 validateContactForm(thisform)
{
  with (thisform)
  {	  
  
      if (nombre.value.length == 0) {
		 alert('El nombre no puede ser nulo!')
		 nombre.focus();
		 return false;
	  }	
	  
	  if (isPhoneNum(telefono.value)==false) {
		 alert('Numero telefonico incorrecto!')
		 telefono.focus();
		 return false;
	  }
	  
	  if (asunto.value.length == 0) {
		 alert('Favor de poner asunto del correo.')
		 asunto.focus();
		 return false;
	  }
	  
      if (validate_email(email,"Correo electronico incorrecto!")==false)
        {email.focus();return false;}
		 
	  
	  if (comments.value.length == 0) {
		 alert('Poner un comentario porfavor!')
		 comments.focus();
		 return false;
	  } 
 
 
   }
}

function queryMembers() 
{
   window.open("../query.php" ,"mywindow","location=1,status=1,scrollbars=1,width=950,height=500");
	 
}
function display_video2(video)
{
  strurl = "<embed src=\"http://www.elimperiolatino.net/videos/" + video + "\" loop=\"false\" autoplay=\"true\" width=\"470\" height=\"320\"></embed>"
  videodisplay.innerHTML=strurl;
}

function queryValue()
{
   var repid = document.all.repid.value;
   var url = "php/querymember.php?repid="+repid;
   var queryurl = document.getElementById("querymember");
   queryurl.src = url;
  
}

function validateMemberForm(thisform, action)
{
	
  if (action) {

	  with (thisform)
	  {
		
	  
		  if (repid.value.length == 0 || isInteger(repid.value)==false) {
			 alert('Numero de representante invalido!')
			 repid.focus();
			 return false;
		  } 
		  
		  if (name.value.length == 0) {
			 alert('El nombre no puede ser nulo!')
			 name.focus();
			 return false;
		  }
		  
		  if (validate_email(email,"Correo electronico incorrecto!")==false)
			{email.focus();return false;}
	
	
		  
		  if (isDate(StDate.value)==false){
			  StDate.focus()
			  return false
		  }
 
		 
		  if (areacode.value.length == 0 || prefix.value.length == 0 || phone.value.length == 0) {
			 alert('El numero telefonico esta incorrecto!')
			 areacode.focus();
			 return false;
		  }	 
	   }
   }
}

function display_video(video, divspace) {
	
   //var s1 = new SWFObject('http://www.elimperiolatino.net/js/player.swf','single','470','320','9');
   //var s2 = 'file=' + 'http://www.elimperiolatino.net/videos/' + video; 
   
   //s1.addParam('allowfullscreen','true');
   //s1.addParam('allowscriptaccess','always');
   //s1.addParam('wmode','opaque');
   //s1.addParam('flashvars',s2);
   //s1.addVariable('autostart','true');
    //s1.write(divspace);
   
   var s1 = '<object width="425" height="344">';
   s1+= '<param name="movie" value="http://www.elimperiolatino.net/videos/'+video+'"></param>';
   s1+= '<param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param>';
   s1+= '<embed src="http://www.elimperiolatino.net/videos/'+video+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344">';
   s1+= '</embed>';
   s1+= '</object>';
   document.getElementById(divspace).innerHTML = s1;
}
function youtubevideo(video,divspace) {
	 
	var s2='<object width="425" height="344"><param name="movie" value="'+video+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="' + video +'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>';
	document.getElementById(divspace).innerHTML = s2;
	
}

function display_video2(video, divspace) {
	
   var s1 = new SWFObject('http://www.elimperiolatino.net/js/player.swf','single','470','320','9');
   var s2 = 'file=' + 'http://www.elimperiolatino.net/videos/' + video; 
   
   s1.addParam('allowfullscreen','true');
   s1.addParam('allowscriptaccess','always');
   s1.addParam('wmode','opaque');
   s1.addParam('flashvars',s2);
   s1.addVariable('autostart','true');
   s1.write(divspace);
 
}

function display_audio(audio, divspace, speaker, tema) {
 
  var s1;
  s1 = speaker + ' - ' + tema + "<br>" +
       '<object width="300" height="42">' +
       '<param name="autoplay" value="true">' +
       '<param name="controller" value="true">' +
       '<embed src="' + audio + '" autostart="true" loop="false" width="300" height="42" controller="true" autoplay="true"></embed>' +
       '</object>' ;

   document.getElementById('mediaspace').innerHTML = s1;
}

function display_block(part) {
	
  var currPart = document.getElementById(part).style.display;
  
  for (i = 1; i < 4; i++) {   
 	 var partX = "part" + i ;
	 document.getElementById(partX).style.display = "none";
  }
  
  if (currPart == "block") {
     document.getElementById(part).style.display = "none";
  }
  else {
     document.getElementById(part).style.display = "block";
  }
	
}
	   
 
var dtCh= "/";
var minYear=1900;
var maxYear=2100;


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++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}


 
var Pic = new Array()

Pic[0] = '../images/DSC_0080_01.jpg'
Pic[1] = '../images/DSC_0155_01.jpg'
Pic[2] = '../images/DSC_0213_01.jpg'
Pic[3] = '../images/DSC_0268_01.jpg'
Pic[4] = '../images/DSC_0006_01.jpg'
Pic[5] = '../images/DSC_0009_01.jpg'
Pic[6] = '../images/lucy2.jpg'
Pic[7] = '../images/daniel2.jpg'
Pic[8] = '../images/lex2.jpg'
Pic[9] = '../images/erick2.jpg'
Pic[10] = '../images/jorgevicky2.jpg'

// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 5000

// Duration of crossfade (seconds)
var crossFadeDuration = 3

// No need to edit
var t
var j = 0
var p = Pic.length

var preLoad = new Array()
for (i = 0; i < p; i++){
   preLoad[i] = new Image()
   preLoad[i].src = Pic[i]
}
function runSlideShow(){

   if (document.all){
      document.images.SlideShow.style.filter="blendTrans(duration=2)"
      document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)"
      document.images.SlideShow.filters.blendTrans.Apply()      
   }
   document.images.SlideShow.src = preLoad[j].src
   if (document.all){
      document.images.SlideShow.filters.blendTrans.Play()
   }
   j = j + 1
   if (j > (p-1)) j=0
   t = setTimeout('runSlideShow()', slideShowSpeed)
}



 
