// JavaScript Document

//---------- function to show swap menu item ----------
function swapMenu(menuId){
	var submenu=document.getElementById(menuId);
	//alert(submenu.className);
	if(submenu.className=='submenu-hide')
		submenu.className='submenu-show';
	else
		submenu.className='submenu-hide';
}

//------------ function to verify empty field -----------
function verifyEmptyField(){
	var length=verifyEmptyField.arguments.length;
	var theForm="document."+"forms['"+verifyEmptyField.arguments[0]+"'].";
	for(i=1; i<length;i++){
		var theField=eval(theForm + "elements['"+arguments[i]+"']");
		if(theField.value==''){
			var theText=theField.alt;
			alert("Please enter "+theText+" ; Fields marked with * can not be empty!");
			theField.focus();
			theField.select();
			return false;
		}
	}
	return true;
}

//------------ function to verify if two values are the same -----------
function verifyEqual(){
	var theVal1=eval("document.forms['"+arguments[0]+"'].elements['"+arguments[1]+"']");
	var theVal2=eval("document.forms['"+arguments[0]+"'].elements['"+arguments[2]+"']");
	if(theVal1.value==theVal2.value){
		return true;
	}
	else{
		alert('The new passwords entered are not the same, please enter again!');
		theVal1.focus();
		theVal2.select();
		return false;
	}
}

//------------ function to file formats allowed for upload -----------
//------------ 1st argument: formname, 2nd argument: filefield name, other arguments: file extensions ---------------
function verifyFileFormat(){
	var length=verifyFileFormat.arguments.length;
	var theFile=eval("document."+"forms['"+verifyFileFormat.arguments[0]+"'].elements['"+arguments[1]+"']");
	var theFilename=theFile.value;
	
	//return true if there is no file selected
	if(theFilename.length==0)
		return true;
	
	var thePos=theFilename.lastIndexOf('.');
	var ext=theFilename.substr(thePos+1).toLowerCase();
	for(i=2; i<length;i++){
		if(arguments[i].toLowerCase()==ext){
			return true;
		}
	}
	alert("The file you selected can not be uploaded, please check if the file format meets the requirements!");
	return false;
}

//-------------- function to write image or flash movie file ---------------
function writeMedia(mediaUrl, width, height){
	//simple test to see
	var pos=mediaUrl.lastIndexOf(".");
	var ext=mediaUrl.substr(pos+1);
	if(ext=='swf'){
		document.write(	"<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\""+width+"\" height=\""+height+"\" >"+
                		"<param name=\"movie\" value=\""+mediaUrl+"\">"+
                	    "<param name=\"quality\" value=\"high\">"+
						"<param name=\"wmode\" value=\"transparent\" >" +
                		"<embed src=\""+mediaUrl+"\" wmode=\"transparent\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+width+"\" height=\""+height+"\" ></embed>"+
  		    			"</object>");
	}else{
		document.write("<img src=\""+mediaUrl+"\" />");
	}
}

var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

// JavaScript helper required to detect Flash Player PlugIn version information
function getSwfVersion(){
      var thePlugins=new Object();
	  if(isIE){
		  var pos=navigator.userAgent.indexOf('MSIE ');
		  if(parseInt(navigator.userAgent.substr(pos+5,1))>=6)
		  	return flashVer=7; //temporary solution, assume ie  install Flash Player 7 and above. replace it with VBScript detection later
	  }
	  else
		  thePlugins=navigator.plugins;

	  
      if (thePlugins != null && thePlugins.length > 0) {
            if (thePlugins["Shockwave Flash 2.0"] || thePlugins["Shockwave Flash"]) {
                  var swVer2 = thePlugins["Shockwave Flash 2.0"] ? " 2.0" : "";
                  var flashDescription = thePlugins["Shockwave Flash" + swVer2].description;
                  descArray = flashDescription.split(" ");
                  tempArrayMajor = descArray[2].split(".");
                  versionMajor = tempArrayMajor[0];
                  if ( descArray[3] != "" ) {
                        tempArrayMinor = descArray[3].split("r");
                  } else {
                        tempArrayMinor = descArray[4].split("r");
                  }
                  versionMinor = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
                  flashVer = parseFloat(versionMajor + "." + versionMinor);
            } else {
                  flashVer = -1;
            }
      }
      // MSN/WebTV 2.6 supports Flash 4
      else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
      // WebTV 2.5 supports Flash 3
      else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
      // older WebTV supports Flash 2
      else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
      // Can't detect in all other cases
      else {
            
            flashVer = -1;
      }
	  
      return flashVer;
}

//-------------- function to advert loader ---------------
function writeAdvert(sectionId,seconds){
	if(getSwfVersion()>=7){
		document.write(	"<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"270\" height=\"120\" >"+
                		"<param name=\"movie\" value=\"images/advert-loader.swf?webpageName=advert.php&sectionId="+sectionId+"&theInterval="+seconds+"\" >"+
                	    "<param name=\"quality\" value=\"high\">"+
						"<param name=\"wmode\" value=\"transparent\" >" +
                		"<embed src=\"images/advert-loader.swf?webpageName=advert.php&sectionId="+sectionId+"&theInterval="+seconds+"\" wmode=\"transparent\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"270\" height=\"120\" ></embed>"+
  		    			"</object>");
	}else{
		switch(sectionId){
			   case 1: mediaUrl='images/v_tour.gif'; break;
			   case 2: mediaUrl='images/newsletter.gif'; break;
			   case 3: mediaUrl='images/veejet.gif'; break;
			   default: mediaUrl='images/v_tour.gif';
			   }
		document.write("<img src=\""+mediaUrl+"\" width=\"270\" height=\"120\" />");
	}
}


//--------------- output quicktime movie in IE7 --------------
function outputQuickTime(movieName, width, height){
	document.write("<object width=\""+width+"\" height=\""+height+"\" classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\">"+
				   "<param name=\"src\" value=\""+movieName+"\"/><param name=\"AutoPlay\" value=\"false\" />"+
				   "<embed width=\""+width+"\" height=\""+height+"\" autoplay=\"false\" src=\""+movieName+"\" /></object>");
}