//general functions

var isMinIE5 = (navigator.appVersion.indexOf("5.")) >= 0 ? 1 : 0;
var isDOM = (document.getElementById) ? 1 : 0;
	
function changeColor(objId,color) {
		if (isMinIE5||isDOM) {
			document.getElementById(objId).style.color=color;
		} else {
			return;
		}
}
	
function changeBgColor(objId,color) {
		//if (window.document && window.document.bgColor) {
		//document.bgColor = newBgColor;
		//}
		//document.getElementById(objId).style.backgroundColor=color;
		document.getElementById(objId).style.background=color;
}

function changeFilmBandwidth(type,playlisthq,playlistlq) {
        if(type == "lowchapter"){
        document.getElementById("bandwidth").innerHTML = "<a href=\"#\" onclick=\"changeFilmBandwidth('highchapter','" +playlisthq+ "','" +playlistlq+ "'); return false;\">High bandwidth</a> &nbsp;|&nbsp; <b>LOW BANDWIDTH</b>";
				var s1 = new SWFObject("/jwplayer/player.swf","ply","320","300","9","#FFFFFF");
                s1.addParam('allowfullscreen','true');
                s1.addParam('allowscriptaccess','always');
                s1.addParam('wmode','transparent');
               	s1.addParam('flashvars','file=/videos/' +playlistlq+ '&playlist=bottom&playlistsize=100&fullscreen=true&');
				s1.write("container");
        }
        else if(type == "highchapter"){
        document.getElementById("bandwidth").innerHTML = "<b>HIGH BANDWIDTH</b> &nbsp;|&nbsp; <a href=\"#\" onclick=\"changeFilmBandwidth('lowchapter','" +playlisthq+ "','" +playlistlq+ "'); return false;\">Low bandwidth</a>";
        		var s1 = new SWFObject("/jwplayer/player.swf","ply","544","426","9","#FFFFFF");
                s1.addParam('allowfullscreen','true');
                s1.addParam('allowscriptaccess','always');
                s1.addParam('wmode','transparent');
               	s1.addParam('flashvars','file=/videos/' +playlisthq+ '&playlist=bottom&playlistsize=100&fullscreen=true&');
				s1.write("container");
        }
        else if(type == "low"){
        document.getElementById("bandwidth").innerHTML = "<a href=\"#\" onclick=\"changeFilmBandwidth('high','" +playlisthq+ "','" +playlistlq+ "'); return false;\">High bandwidth</a> &nbsp;|&nbsp; <b>LOW BANDWIDTH</b>";
				var s1 = new SWFObject("/jwplayer/player.swf","ply","320","200","9","#FFFFFF");
                s1.addParam('allowfullscreen','true');
                s1.addParam('allowscriptaccess','always');
                s1.addParam('wmode','transparent');
               	s1.addParam('flashvars','file=/videos/' +playlistlq+ '&fullscreen=true&');
				s1.write("container");
        }
        else if(type == "high"){
        document.getElementById("bandwidth").innerHTML = "<b>HIGH BANDWIDTH</b> &nbsp;|&nbsp; <a href=\"#\" onclick=\"changeFilmBandwidth('low','" +playlisthq+ "','" +playlistlq+ "'); return false;\">Low bandwidth</a>";
        		var s1 = new SWFObject("/jwplayer/player.swf","ply","544","326","9","#FFFFFF");
                s1.addParam('allowfullscreen','true');
                s1.addParam('allowscriptaccess','always');
                s1.addParam('wmode','transparent');
               	s1.addParam('flashvars','file=/videos/' +playlisthq+ '&fullscreen=true&');
				s1.write("container");
        }
}

function formfocus(ido,valo,org)
// syntax: formfocus|formblur(this.id,this.value,'original field value');
{
if (valo == org)
	{
		document.getElementById(ido).value = '';
	}
	else
	{
		return;
	}
}
function formblur(ido,valo,org) 
{
if (valo == '')
	{
		document.getElementById(ido).value = org;
	}
	else
	{
		return;
	}
}
	
function popup(filename,w,h)
	{
    	var wl = (screen.width - w) / 2;
		var wt = (screen.height - h) / 2;
		var size = ("resizable=0,scrollbars=yes,left=" + wl + ",top=" + wt +",width=" + w + ",height=" + h);
		popupwindow=window.open(filename,"popup",size);
		setTimeout('popupwindow.focus();',250);
}

function show(object) {
    if (document.getElementById && document.getElementById(object) != null)
	 node = document.getElementById(object).style.display='block';
    else if (document.layers && document.layers[object] != null)
	document.layers[object].display='block';
    else if (document.all)
	document.all[object].style.display='block';
}

function hide(object) {
    if (document.getElementById && document.getElementById(object) != null)
	 node = document.getElementById(object).style.display='none';
    else if (document.layers && document.layers[object] != null)
	document.layers[object].display='none';
    else if (document.all)
	 document.all[object].style.display='none';
}

// thanks to http://www.mister-pixel.com/
// fixes the ie6 image flicker bug
/*@cc_on @*/
/*@if (@_jscript_version >= 4)
document.execCommand("BackgroundImageCache", false, true);
/*@end @*/

//form validation from http://www.webcheatsheet.com/javascript/form_validation.php

function validateFormOnSubmit(theForm) {
var reason = "";

  reason += validateUsername(theForm.firstname);
  reason += validateUsername(theForm.lastname);
  reason += validateEmail(theForm.email);
  reason += validateEmpty(theForm.company);
  reason += validateEmpty(theForm.comment);
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  document.theForm.submit();
  return false;
}
function validateEmpty(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.border = '2px solid #ea6900';
        error = "Please fill out all required fields.\n"
    } else {
        fld.style.border = '1px dotted #333;';
    }
    return error;  
}
function validateUsername(fld) {
    var error = "";
    var illegalChars = /[\(\)\@\<\>\,\;\:\\\"\[\]]/ ;
 
    if (fld.value == "") {
        fld.style.border = '2px solid #ea6900'; 
        error = "Please enter your name.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow'; 
        error = "Your name contains incorrect characters. Please correct.\n";
    } else {
        fld.style.border = '1px dotted #333;';
    }
    return error;
}
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}
function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.border = '2px solid #ea6900'; 
        error = "Please enter your e-mail address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.border = '2px solid #ea6900'; 
        error = "Please enter a valid e-mail address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.border = '2px solid #ea6900'; 
        error = "The e-mail address contains incorrect characters. Please correct.\n";
    } else {
        fld.style.border = '1px dotted #333;';
    }
    return error;
}

// javascript e-mail protection. derived from: http://www.csarven.ca/hiding-email-addresses#javascript
function welovespam(){
	var string1 = direction;
	var string2 = "@";
	var string3 = "vnl.in";
	var string4 = string1 + string2 + string3;
	document.write("<a href=" + "mail" + "to:" + string1 + string2 + string3 + ">" + description + "</a>" + endgame);
}

function welovespamtoo(){
	var string1 = person;
	var string2 = "@";
	var string3 = company;
	var string4 = string1 + string2 + string3;
	document.write("<a href=" + "mail" + "to:" + string1 + string2 + string3 + ">" + string4 + "</a>" + endgame);
}

// -------------------------------------------------------------------
// Ajax XML Ticker (txt file source)
// Author: Dynamic Drive (http://www.dynamicdrive.com)
// -------------------------------------------------------------------

////////////No need to edit beyond here//////////////

function createAjaxObj(){
var httprequest=false
if (window.XMLHttpRequest){ // if Mozilla, Safari etc
httprequest=new XMLHttpRequest()
if (httprequest.overrideMimeType)
httprequest.overrideMimeType('text/xml')
}
else if (window.ActiveXObject){ // if IE
try {
httprequest=new ActiveXObject("Msxml2.XMLHTTP");
} 
catch (e){
try{
httprequest=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){}
}
}
return httprequest
}

// -------------------------------------------------------------------
// Main Ajax Ticker Object function
// ajax_ticker(xmlfile, divId, divClass, delay, optionalfadeornot)
// -------------------------------------------------------------------

function ajax_ticker(xmlfile, divId, divClass, delay, fadeornot){
this.xmlfile=xmlfile //Variable pointing to the local ticker xml file (txt)
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over ticker (and pause it if it is)
this.pointer=0
this.opacitystring=(typeof fadeornot!="undefined")? "width: 100%; filter:progid:DXImageTransform.Microsoft.alpha(opacity=100); -moz-opacity: 1" : ""
if (this.opacitystring!="") this.delay+=500 //add 1/2 sec to account for fade effect, if enabled
this.opacitysetting=0.2 //Opacity value when reset. Internal use.
this.messages=[] //Arrays to hold each message of ticker
this.ajaxobj=createAjaxObj()
document.write('<div id="'+divId+'" class="'+divClass+'"><div style="'+this.opacitystring+'"><p>Initializing ticker...</p></div></div>')
this.getXMLfile()
}

// -------------------------------------------------------------------
// getXMLfile()- Use Ajax to fetch xml file (txt)
// -------------------------------------------------------------------

ajax_ticker.prototype.getXMLfile=function(){
if (this.ajaxobj){
var instanceOfTicker=this
var url=this.xmlfile+"?bustcache="+new Date().getTime()
this.ajaxobj.onreadystatechange=function(){instanceOfTicker.initialize()}
this.ajaxobj.open('GET', url, true)
this.ajaxobj.send(null)
}
}

// -------------------------------------------------------------------
// initialize()- Initialize ticker method.
// -Gets contents of xml file and parse it using JavaScript DOM methods 
// -------------------------------------------------------------------

ajax_ticker.prototype.initialize=function(){ 
if (this.ajaxobj.readyState == 4){ //if request of file completed
if (this.ajaxobj.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful
this.contentdiv=document.getElementById(this.tickerid).firstChild //div of inner content that holds the messages
var xmldata=this.ajaxobj.responseText
this.contentdiv.style.display="none"
this.contentdiv.innerHTML=xmldata
if (this.contentdiv.getElementsByTagName("div").length==0){ //if no messages were found
this.contentdiv.innerHTML="<b>Error</b> fetching remote ticker file!"
return
}
var instanceOfTicker=this
document.getElementById(this.tickerid).onmouseover=function(){instanceOfTicker.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){instanceOfTicker.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){instanceOfTicker.contentdiv=instanceOfTicker.ajaxobj=null})
//Cycle through XML object and store each message inside array
for (var i=0; i<this.contentdiv.getElementsByTagName("div").length; i++){
if (this.contentdiv.getElementsByTagName("div")[i].className=="message")
this.messages[this.messages.length]=this.contentdiv.getElementsByTagName("div")[i].innerHTML
}
this.contentdiv.innerHTML=""
this.contentdiv.style.display="block"
this.rotatemsg()
}
}
}

// -------------------------------------------------------------------
// rotatemsg()- Rotate through ticker messages and displays them
// -------------------------------------------------------------------

ajax_ticker.prototype.rotatemsg=function(){
var instanceOfTicker=this
if (this.mouseoverBol==1) //if mouse is currently over ticker, do nothing (pause it)
setTimeout(function(){instanceOfTicker.rotatemsg()}, 100)
else{ //else, construct item, show and rotate it!
this.fadetransition("reset") //FADE EFFECT- RESET OPACITY
//this.contentdiv.innerHTML=this.messages[this.pointer]
// NEW addition that randomizes content display
maruti=(Math.round(Math.random()*(this.messages.length-1)))
// alert to test current array position - alert(maruti)
this.contentdiv.innerHTML=this.messages[maruti]
// END new addition
this.fadetimer1=setInterval(function(){instanceOfTicker.fadetransition('up', 'fadetimer1')}, 100) //FADE EFFECT- PLAY IT
this.pointer=(this.pointer<this.messages.length-1)? this.pointer+1 : 0
setTimeout(function(){instanceOfTicker.rotatemsg()}, this.delay) //update container periodically
}
}

// -------------------------------------------------------------------
// fadetransition()- cross browser fade method for IE5.5+ and Mozilla/Firefox
// -------------------------------------------------------------------

ajax_ticker.prototype.fadetransition=function(fadetype, timerid){
var contentdiv=this.contentdiv
if (fadetype=="reset")
this.opacitysetting=0.2
if (contentdiv.filters && contentdiv.filters[0]){
if (typeof contentdiv.filters[0].opacity=="number") //IE6+
contentdiv.filters[0].opacity=this.opacitysetting*100
else //IE 5.5
contentdiv.style.filter="alpha(opacity="+this.opacitysetting*100+")"
}
else if (typeof contentdiv.style.MozOpacity!="undefined" && this.opacitystring!=""){
contentdiv.style.MozOpacity=this.opacitysetting
}
else
this.opacitysetting=1
if (fadetype=="up")
this.opacitysetting+=0.1
if (fadetype=="up" && this.opacitysetting>=1)
clearInterval(this[timerid])
}