// JavaScript Document
var xmlDoc;
var globalvar=null;
var globalvarParam=null;
var globalsubMenuParam=null;
var preObj;
var flag1 = 0;
var globalnormalBox=null;
var globalvarflashVersion = null;

if (window.ActiveXObject)
 {// code for IE
	 xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	 xmlDoc.async=false;
	 xmlDoc.load("/eDamanApp/en/xml/data.xml");

 }
else{
	var xmlhttp = new window.XMLHttpRequest();
    xmlhttp.open("GET", "/eDamanApp/en/xml/data.xml", false);
    xmlhttp.send(null);
    xmlDoc = xmlhttp.responseXML.documentElement;

}
  
  var xmlobj = xmlDoc.getElementsByTagName('onlineDemo_module');
  
function showVideo(conf,obj,param){
if(preObj!=null){
preObj.className = "fontNormal";
}
obj.className = "fontBold";
preObj = obj;
//var frameObj = document.getElementsByTagName('embed');
//frameObj[0].src=xmlobj[conf-1].childNodes[0].nodeValue;

for(k=0;k<xmlobj.length;k++){
	if(param==xmlobj[k].getAttribute('name'))
		{
			var videoLink = xmlobj[k].getElementsByTagName('link');
				var srcLink = videoLink[conf-1].childNodes[0].nodeValue;
		}
}
document.getElementById('wrapper').innerHTML='<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" WIDTH="100%" HEIGHT="490" id="myMovieName"><PARAM NAME=movie VALUE="'+srcLink+'"><PARAM NAME=quality VALUE=high><PARAM NAME=bgcolor VALUE=#FFFFFF><param name="wmode" value="transparent"><EMBED src="'+srcLink+'" quality=high bgcolor=#FFFFFF WIDTH="100%" HEIGHT="490" NAME="myMovieName" ALIGN="" TYPE="application/x-shockwave-flash" wmode="opaque" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>';
//document.getElementById('videoHeading').innerHTML = obj.innerHTML;
}

// Set the loged in user name.
function getLoggedInUserName(){
	
	// Ajax call to get the Loged in username from session.
	$.ajax({
                   url: "getLoggedInUserName.action",
                   async: true,
                   success: function(successData){
   			 		 	$('#shareBox input:text')[0].value = successData;
 			      }
    });
	
}
 // Onclick of share video link open a popup.
function shareVideo(){
		//clear error div.
		if($('#msgDiv')[0]) {
					$('#msgDiv')[0].innerHTML = "";
		}
		// Set the loged in userName.
		getLoggedInUserName();
		
		$('#shareBoxOverlay').show();
        $('#shareBoxOverlay').width($('#lightbox-container-image-box').width());
		$('#shareBoxOverlay').height($('#lightbox-container-image-box').height()+1);
		
		$('#shareBoxOverlay').css({
		backgroundColor:	'#000',
		opacity:	'0.8',
		zIndex:	'1'
		});
	
	$('#shareBox').slideDown({
	width:'toggle',
	height:'toggle'
	});
		
	setTimeout(function(){
						$('#shareBox input:text')[0].focus();
						},500);
	
}

// Validate a comma separated email
function validateEmail(recipientEmail) {

	var pattern=/^[A-Z0-9\._%-]+@[A-Z0-9\.-]+\.[A-Z]{2,4}(?:(?:[,][A-Z0-9\._%-]+@[A-Z0-9\.-]+))?$/i;
	
	var splitStr = recipientEmail.split(",");
	var isValidEmail = true;

	for(i = 0; i < splitStr.length; i++){
		isValidEmail = pattern.test(splitStr[i]);
		if(!isValidEmail) {
			break;
		}
    }
	if(isValidEmail){         
		return true; 
    }else{   
		return false;
    }
}
		   
// Submit a values to action to send mail.
function shareVideoToFriend(){
	var senderName = $('#shareBox input:text')[0].value;
	var recipientName = $('#shareBox input:text')[1].value;
	var recipientEmail = $('#shareBox input:text')[2].value;
		
		$('#msgDiv')[0].innerHTML = "";
		$('#msgDiv').css({
		color:	'#ff0000'
		});
		if(senderName=="" || recipientName=="" || recipientEmail=="") {
			$('#msgDiv')[0].innerHTML ="Please enter all fields marked (*)";
			return false;
		} 

		if(validateEmail(recipientEmail)){
				var videoName,videoPath;
				if(navigator.appVersion.indexOf('MSIE')!=-1){
				videoPath = document.getElementById('myMovieName').getElementsByTagName('param')[0].value;
				}
				else{
				videoPath = document.getElementsByTagName('embed')[0].src;
				}
				videoName = escape($('a.fontBold')[0].innerHTML);

				videoPath = escape(videoPath.split("/eDamanApp/")[1]);

				$('#msgDiv')[0].innerHTML = "<div style='text-align:center;'><img src='/eDamanApp/en/images/lightbox-ico-loading.gif'/></div>";
				
				$.ajax({
					 type: "POST",
					 url: "shareVideoToFriend.action",
					 data: "senderName=" + senderName + "&recipientName=" + recipientName + "&recipientEmail=" + recipientEmail + "&videoName=" + videoName + "&videoPath=" + videoPath,
					 success: function(msg){
								 if(msg) {
									$('#msgDiv').css({
										color:	'#009900'
										});
									$('#msgDiv')[0].innerHTML = "Your mail has been sent successfully";
									$('#shareBox input:text').each(
									function(){
										$(this).val('');
									});
								 }
							  },
					 error: function(){ 
								  $('#msgDiv').css({
										color:	'#ff0000'
										});
									$('#msgDiv')[0].innerHTML = "Your mail has not been sent successfully,Please try after sometime";
							  }
				});


		 } 
		 else{
				$('#msgDiv')[0].innerHTML ="Please enter a valid E-mail address";
		 }
}

function closeShareVideo(){
	//$('#shareBoxOverlay').hide();
	//$('#shareBox').hide();

	$('#shareBox').slideUp({
	width:'toggle',
	height:'toggle'
	});

	setTimeout(function(){
						$('#shareBoxOverlay').hide();
						},500);

	$('#shareBox input:text').each(
        function(){
	        $(this).val('');
         });
}


function ___getPageSize() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		}

function ___getPageScroll() {
			var xScroll, yScroll;
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;	
			}
			arrayPageScroll = new Array(xScroll,yScroll);
			return arrayPageScroll;
		}
var Screen, ScreenWidth , ScreenHeight ,ImgTop , ImgLeft , MyWidth , MyHeight;
		function setPos(){
			//var Screen, ScreenWidth , ScreenHeight ,ImgTop , ImgLeft , MyWidth , MyHeight;
                                if (navigator.appVersion.indexOf("MSIE")!=-1){
                                MyHeight = document.body.offsetHeight;
                                MyWidth = document.body.offsetWidth;
                                ScreenHeight = document.body.clientHeight;
                                ScreenWidth = document.body.clientWidth;                                      
                                
                                var contentHeight = 585;
                                var contentWidth = 936;
								

								var arrPageScroll = ___getPageScroll();
								var arrPageSizes = ___getPageSize();
                                ImgTop = arrayPageScroll[1] + ((arrayPageSize[3]+10) - contentHeight) / 2 +'px';
                                ImgLeft = arrayPageScroll[0] + (arrayPageSize[2] - contentWidth)  / 2 +'px';
                               
                                
                }
                else{
                		 		MyHeight = parseInt(document.getElementById('template').scrollHeight) + 'px';
                                MyWidth = document.getElementById('template').scrollWidth + 'px';                    
                                ScreenHeight = window.innerHeight;
                                ScreenWidth = window.innerWidth;
                                
                                var contentHeight = 585;
                                var contentWidth = 936;
                                
								var arrPageScroll = ___getPageScroll();
                                ImgTop = arrayPageScroll[1] + (ScreenHeight-contentHeight) / 2 + 'px';
                                ImgLeft = arrayPageScroll[0] + (ScreenWidth - contentWidth)  / 2 + 'px';		
                                
                }
								//document.getElementById('jquery-lightbox').style.top = ImgTop;
                               // document.getElementById('jquery-lightbox').style.left = ImgLeft;
		}

function showDetail(){
	var arrPageSizes = ___getPageSize();
	var parentDiv = document.getElementById('popupIcon').parentNode;

	var lgtLogo = document.getElementById('headLogo');
	var lgtLftNav = document.getElementById('videoLink');
	var videoObj = document.getElementById('myMovieName');
	var embedObj = document.getElementsByTagName('EMBED');
	var popImg = document.getElementById('popupIcon');

	if(popImg.src.split('images/')[1] == 'full-screen.gif'){
		flag1 = 2;
	lgtLogo.style.display = 'none';
	lgtLftNav.style.display = 'none';
	$('#shareLink').hide();
	//$(lgtLogo).fadeOut("fast");
	//$(lgtLftNav).fadeOut("fast");
	document.getElementById('popDetail').style.display = 'block';
	document.getElementById('lightbox-secNav-btnClose').style.display = 'none';
	document.getElementById('popupIcon').src = '/eDamanApp/en/images/exit.gif';
	document.getElementById('popupIcon').title = 'Exit full screen';

		parentDiv.style.right = '5px';
	
	if(navigator.appVersion.indexOf("MSIE")!=-1){

	$('#jquery-lightbox').animate({
		width: arrayPageSize[2],
		height: arrayPageSize[3],
		left: 0+'px',
		top:document.documentElement.scrollTop
	  }, 500 );
		$('#lightbox-container-image-box').animate({
		width: arrayPageSize[2],
		height: arrayPageSize[3]
	  }, 500 );
		$('#demoTable').animate({
		width: arrayPageSize[2],
		height: arrayPageSize[3]
	  }, 500 );
		
		videoObj.style.height = arrayPageSize[3]+"px";
		videoObj.style.width = (arrayPageSize[2]-50)+"px";
	}

	else{
		$('#jquery-lightbox').css({
		width: arrayPageSize[2],
		height: arrayPageSize[3],
		left: 0+'px',
		top:window.pageYOffset
	  });
		$('#lightbox-container-image-box').css({
		width: arrayPageSize[2],
		height: arrayPageSize[3]
	  });
		$('#demoTable').css({
		width: arrayPageSize[2],
		height: arrayPageSize[3]
	  });
		
	    embedObj[0].style.height = arrayPageSize[3]+"px";
		embedObj[0].style.width = (arrayPageSize[2]-50)+"px";
	}
	
	  

		

	   
	var rgtTd = document.getElementById('demoBox').offsetParent;
	rgtTd.style.padding = '0px';
	document.getElementById('demoBox').style.width="100%";
	document.getElementById('demoBox').style.border='none';
	document.getElementById('cautionTxt').style.display = 'none';
	//popImg.src = 'images/exit.gif'
	//popImg.title = 'Exit Full Screen';
	}
	
	else if(popImg.src.split('images/')[1] == 'exit.gif'){
		flag1 = 3;
		setPos();
		
		$(lgtLogo).fadeIn("slow");
		$(lgtLftNav).fadeIn("slow");
		$('#shareLink').show();
		document.getElementById('popDetail').style.display = '';
		document.getElementById('lightbox-secNav-btnClose').style.display = '';
		document.getElementById('popupIcon').src = '/eDamanApp/en/images/full-screen.gif';
		document.getElementById('popupIcon').title = 'Full Screen';
		videoObj.style.height = 490+"px";
		videoObj.style.width = '100%';
		if(navigator.appVersion.indexOf("MSIE")==-1){
		embedObj[0].style.height = 490+"px";
		embedObj[0].style.width = '100%';
		}

		parentDiv.style.right = '35px';

		/*if(navigator.appVersion.indexOf("MSIE")!=-1){
		$('#jquery-lightbox').animate({
		width: 936,
		height: 580,
		left: ImgLeft,
		top:ImgTop
	  }, 100 );
		}*/

		//else{
		$('#jquery-lightbox').css({
		width: 936,
		height: 580,
		left: ImgLeft,
		top:ImgTop
	  });
		$('#lightbox-container-image-box').css({
		width: 936,
		height: 580
	  } );
		$('#demoTable').css({
		width: 936,
		height: 580
	  });
		//}
		/*$('#lightbox-container-image-box').animate({
		width: 936,
		height: 580
	  }, 500 );
		$('#demoTable').animate({
		width: 936,
		height: 580
	  }, 500 );*/

	  // setTimeout(function(){setData()},10);

 
	var rgtTd = document.getElementById('demoBox').offsetParent;
	rgtTd.style.paddingRight = '10px';
	document.getElementById('demoBox').style.width="100%";
	document.getElementById('demoBox').style.border='1px solid #d6dee1';
	document.getElementById('cautionTxt').style.display = '';
	}
	
}

function setData(){
	document.getElementById('lightbox-container-image-box').style.width = 936+"px";
	  document.getElementById('lightbox-container-image-box').style.height = 580+"px";
	  document.getElementById('demoTable').style.width = 936+"px";
	  document.getElementById('demoTable').style.height = 580+"px";
}

function showsubMenu(){
	$('#subMenu').slideToggle('normal',function() {
        if ($(this).is(':visible')) {
            $('#redImg').attr('src',$('#redImg').attr('src').replace('red-arrow','down-arrow'));
        }
        else {
            $('#redImg').attr('src',$('#redImg').attr('src').replace('down-arrow','red-arrow'));
        }
    });}


function showMembers(){
                 $('#memsubMenu').slideToggle('normal',function() {
        if ($(this).is(':visible')) {
            $('#memredImg').attr('src',$('#memredImg').attr('src').replace('red-arrow','down-arrow'));
        }
        else {
            $('#memredImg').attr('src',$('#memredImg').attr('src').replace('down-arrow','red-arrow'));
        }
    });}


function showpolicyHolders(){
                $('#policysubMenu').slideToggle('normal',function() {
        if ($(this).is(':visible')) {
            $('#policyredImg').attr('src',$('#policyredImg').attr('src').replace('red-arrow','down-arrow'));
        }
        else {
            $('#policyredImg').attr('src',$('#policyredImg').attr('src').replace('down-arrow','red-arrow'));
        }
    });}

function getSample(vId,param,subMenuParam,boxDetail)
{
flag1 = 1;
globalvar=vId;
globalvarParam = param;
globalsubMenuParam = subMenuParam;
globalnormalBox = boxDetail;
checkShockwave();
}

function showNewBox(){
				$("#toolTip").fadeIn("slow");
				//document.getElementById('toolTip').style.display = 'block';
			}
function closeToolTip(){
	$("#toolTip").fadeOut("slow");
}
function downloadFlash(){
	window.open("http://www.adobe.com/support/flashplayer/downloads.html","","");
}

function checkShockwave() {
	var FlashDetect=new function(){var self=this;self.installed=false;self.raw="";self.major=-1;self.minor=-1;self.revision=-1;self.revisionStr="";var activeXDetectRules=[{"name":"ShockwaveFlash.ShockwaveFlash.7","version":function(obj){return getActiveXVersion(obj);}},{"name":"ShockwaveFlash.ShockwaveFlash.6","version":function(obj){var version="6,0,21";try{obj.AllowScriptAccess="always";version=getActiveXVersion(obj);}catch(err){}
	return version;}},{"name":"ShockwaveFlash.ShockwaveFlash","version":function(obj){return getActiveXVersion(obj);}}];var getActiveXVersion=function(activeXObj){var version=-1;try{version=activeXObj.GetVariable("$version");}catch(err){}
	return version;};var getActiveXObject=function(name){var obj=-1;try{obj=new ActiveXObject(name);}catch(err){obj={activeXError:true};}
	return obj;};var parseActiveXVersion=function(str){var versionArray=str.split(",");return{"raw":str,"major":parseInt(versionArray[0].split(" ")[1],10),"minor":parseInt(versionArray[1],10),"revision":parseInt(versionArray[2],10),"revisionStr":versionArray[2]};};var parseStandardVersion=function(str){var descParts=str.split(/ +/);var majorMinor=descParts[2].split(/\./);var revisionStr=descParts[3];return{"raw":str,"major":parseInt(majorMinor[0],10),"minor":parseInt(majorMinor[1],10),"revisionStr":revisionStr,"revision":parseRevisionStrToInt(revisionStr)};};var parseRevisionStrToInt=function(str){return parseInt(str.replace(/[a-zA-Z]/g,""),10)||self.revision;};self.majorAtLeast=function(version){return self.major>=version;};self.minorAtLeast=function(version){return self.minor>=version;};self.revisionAtLeast=function(version){return self.revision>=version;};self.versionAtLeast=function(major){var properties=[self.major,self.minor,self.revision];var len=Math.min(properties.length,arguments.length);for(i=0;i<len;i++){if(properties[i]>=arguments[i]){if(i+1<len&&properties[i]==arguments[i]){continue;}else{return true;}}else{return false;}}};self.FlashDetect=function(){if(navigator.plugins&&navigator.plugins.length>0){var type='application/x-shockwave-flash';var mimeTypes=navigator.mimeTypes;if(mimeTypes&&mimeTypes[type]&&mimeTypes[type].enabledPlugin&&mimeTypes[type].enabledPlugin.description){var version=mimeTypes[type].enabledPlugin.description;var versionObj=parseStandardVersion(version);self.raw=versionObj.raw;self.major=versionObj.major;self.minor=versionObj.minor;self.revisionStr=versionObj.revisionStr;self.revision=versionObj.revision;self.installed=true;}}else if(navigator.appVersion.indexOf("Mac")==-1&&window.execScript){var version=-1;for(var i=0;i<activeXDetectRules.length&&version==-1;i++){var obj=getActiveXObject(activeXDetectRules[i].name);if(!obj.activeXError){self.installed=true;version=activeXDetectRules[i].version(obj);if(version!=-1){var versionObj=parseActiveXVersion(version);self.raw=versionObj.raw;self.major=versionObj.major;self.minor=versionObj.minor;self.revision=versionObj.revision;self.revisionStr=versionObj.revisionStr;}}}}}();};FlashDetect.JS_RELEASE="1.0.4";
	if(FlashDetect.installed){
		//alert("Flash major: "+ FlashDetect.major);
		globalvarflashVersion = FlashDetect.major;
	}
}
/*allowing only english in input fields starts*/

function isArabic(str){
		 var isAr = false;
		 for(var i = 0; i < str.length; i++) {            
            var c = str.charCodeAt(i);
			if(c < 0 || c > 255) {
				isAr = true;
				break;
            }
        }		
		return isAr;		 
		}

function checkLanguage(){
	
var err = false;
var errtxtArea = false;

	   $(':text').each(function(idx, txtItem) {
	    if(txtItem.id.indexOf('.international')==-1 && txtItem.id != 'googleSearchCriteria'){
		    if(isArabic(txtItem.value)) {
				txtItem.value = '';
				setTimeout((function() { txtItem.focus() }), 0);
				err = true;
			}
	    }
	    });
	    
         if(err)
		 {
		 if(document.body.dir!='' && document.body.dir.toUpperCase()=='RTL') {
		 setTimeout((function() { document.getElementById('msgDiv').innerHTML = 'واحدة من الحقول التي تحتوي على النص العربي ، يرجى تقديم مدخلات باللغة الانكليزية'; }), 20);
		 }
		 else{	
		 setTimeout((function() { document.getElementById('msgDiv').innerHTML = 'One of the fields contain arabic text, please provide the input in english'; }), 20);
		 }
		 setTimeout((function() { document.getElementById('msgDiv').style.color = '#ff0000'; }), 20);
		 }
		 

}
/*allowing only english in input fields ends*/
