// JavaScript Document

var domainroot="www.onechipphotonics.com";

function siteContentSearch(curobj){
	curobj.q.value = "site:" + domainroot +" "+ curobj.search_box.value;
	curobj.submit();
}


if(top.frames.length!=0)
{
	top.location = self.document.location;
}

function launchNewWin(mypage,myname,w,h,scroll){

		if (screen.width)
		{
			if (w>screen.width)
			{
				w = screen.width;
				leftPosition=0;
			}
			else
			{
				leftPosition = (screen.width-w)/2;
			}
		}
		if (screen.height)
		{
			if (h>screen.height)
			{
				h = screen.height;
				topPosition=0;
			}
			else
			{
				topPosition = (screen.height-h)/2;
			}
		}
		
			settings ='height='+h+',width='+w+',top='+topPosition+',left='+leftPosition+',scrollbars='+scroll+', toolbar=no,location=no,directories=no,menubar=no,resizable=no';		

			windemo = window.open(mypage, myname, settings);
	    
}


function leadTrim(value){
	var reStr = /\s*((\S+\s*)*)/;
	return value.replace(reStr, "$1");
}

function rearTrim(value){	
	var reStr = /((\s*\S+)*)\s*/;
	return value.replace(reStr, "$1");
	
}

// trims leading and ending whitespaces
function trimStr(value){	
	return leadTrim(rearTrim(value));
	
}


function checkIsFieldEmpty(theFormElement){
	if(document.getElementById){
		elementValue = trimStr(theFormElement.value);
  		if(elementValue == ''){
      		document.getElementById(theFormElement.id + '_err').innerHTML = "<span style='color: #CC0000'>Please fill in " + theFormElement.id + ".</span>";
      		return 1;
    	}
	  	else{  		
	  		document.getElementById(theFormElement.id + '_err').innerHTML = "<img src='../images/spacer.gif' width='1' height='1' border='0'/>";
		return 0;
	  	}
	  }
	return 0;
}


function checkEmailFormat(theFormElement){
	var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
	var theFormElementValue = theFormElement.value;
	theFormElementValue = trimStr(theFormElementValue);
  	if(document.getElementById){
  		if (checkIsFieldEmpty(theFormElement) == 0){ 	
			if(!theFormElementValue.match(emailfilter)){
			  document.getElementById(theFormElement.id + '_err').innerHTML = "<span style='color: #CC0000'>Email format is not valid.</span>";
      			return 1;
				}
    			else{
      			document.getElementById(theFormElement.id + '_err').innerHTML = "<img src='../images/spacer.gif' width='1' height='1' border='0'/>";
      			return 0;
   			}
    		}else{
			return 1;
		}
  }
}


function registerForPaper(theFormName, subjectText)
{
	var theForm = document.forms[theFormName];
	email="steve.bauer@onechipphotonics.com";
	subject=subjectText;
	
	if(checkIsFieldEmpty(theForm.elements['name']) + 
		checkIsFieldEmpty(theForm.elements['title']) +
		checkIsFieldEmpty(theForm.elements['company']) +
		checkIsFieldEmpty(theForm.elements['location']) +
		checkIsFieldEmpty(theForm.elements['phone']) +
		checkEmailFormat(theForm.elements['email']) == 0)
	{
	body_message="Name: " + theForm.elements['name'].value + "; " + "Title: " + theForm.elements['title'].value + "; " + "Company: " + theForm.elements['company'].value + "; " + "Location: " + theForm.elements['location'].value + "; " + "Email: " + theForm.elements['email'].value + "; " + "Phone: " + theForm.elements['phone'].value + "; ";
	mailto_link = 'mailto:'+email+'?subject='+subject+'&body='+body_message; 
	win_email = window.open(mailto_link,'emailWindow'); 		
	self.window.close();
	}
	else{
		return false; 
	}

}

function switchVideo(dv, param)
{
	if(document.getElementById)
	{
		switch(param)
	  	{
			case "video01":
			{
			document.getElementById(dv).innerHTML="<h3>OneChip's Value Proposition</h3><object width=\"640\" height=\"400\"><param name=\"movie\" value=\"http://www.youtube.com/v/02e7DIYzOzQ&rel=0&color1=0xb1b1b1&color2=0xcfcfcf&hl=en&feature=player_detailpage&fs=1\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowScriptAccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/02e7DIYzOzQ&rel=0&color1=0xb1b1b1&color2=0xcfcfcf&hl=en&feature=player_detailpage&fs=1\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowScriptAccess=\"always\" width=\"640\" height=\"400\"></embed></object>"; 

/*		document.getElementById(dv).innerHTML="<div id='ytapiplayer'>You need Flash player 8+ and JavaScript enabled to view this video.</div>";

    		var params = { allowScriptAccess: 'always' };
    		var atts = { id: 'myytplayer' };

    		swfobject.embedSWF("http://www.youtube.com/v/02e7DIYzOzQ&hl=en&fs=1&enablejsapi=1&playerapiid=ytplayer", 
                       "ytapiplayer", "640", "400", "8", null, null, params, atts);
*/

			break;
			}
			case "video02":
			{
/*			document.getElementById(dv).innerHTML="<h3>CEO's Vision</h3><object width=\"640\" height=\"400\"><param name=\"movie\" value=\"http://www.youtube.com/v/CnOqtnrAQFY&hl=en&fs=1&\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/CnOqtnrAQFY&hl=en&fs=1&\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"640\" height=\"400\"></embed></object>";
*/
		document.getElementById(dv).innerHTML="<h3>CEO&rsquo;s Vision</h3><a href='javascript:void(0);' onclick='playOneChipVideo();return false'><img src='../images/video_CEOvision.jpg' name='oc_CEOvision' width='640' height='400' border='0'/></a><div id='ytapiplayer' style='display: none'>You need Flash player 8+ and JavaScript enabled to view this video.</div>";

/*
    		var params = { allowScriptAccess: 'always' };
    		var atts = { id: 'myytplayer' };

    		swfobject.embedSWF("http://www.youtube.com/v/CnOqtnrAQFY&hl=en&fs=1&enablejsapi=1&playerapiid=ytplayer", 
                       "ytapiplayer", "640", "400", "8", null, null, params, atts);
*/
			break;
			}
		}
	}
}



	function onYouTubePlayerReady(playerId) {

      			ytplayer = document.getElementById("myytplayer");
  			if (ytplayer) {
    				ytplayer.playVideo();
  			}
			
    	}

	function playOneChipVideo() {

		document.images["oc_CEOvision"].style.display = "none";
		document.getElementById("ytapiplayer").style.display = "block";

    		var params = { allowScriptAccess: 'always' };
    		var atts = { id: 'myytplayer' };

    		swfobject.embedSWF("http://www.youtube.com/v/CnOqtnrAQFY&hl=en&fs=1&enablejsapi=1&playerapiid=ytplayer", 
                       "ytapiplayer", "640", "400", "8", null, null, params, atts);
		

	}





//arrays for images
oc_img01 = new Image();
oc_img01.src = "../images/oc_up_left_cnr.jpg";
oc_img02 = new Image();
oc_img02.src = "../images/oc_up01.jpg";
oc_img03 = new Image();
oc_img03.src = "../images/oc_up_bk.jpg";
oc_img04 = new Image();
oc_img04.src = "../images/oc_up02.jpg";
oc_img05 = new Image();
oc_img05.src = "../images/oc_up_right_cnr.jpg";
oc_img06 = new Image();
oc_img06.src = "../images/oc_left.jpg";
oc_img07 = new Image();
oc_img07.src = "../images/oc_right.jpg";
oc_img08 = new Image();
oc_img08.src = "../images/oc_left_btm.jpg";
oc_img09 = new Image();
oc_img09.src = "../images/oc_btm_left.jpg";
oc_img10 = new Image();
oc_img10.src = "../images/oc_btm_bk.jpg";
oc_img11 = new Image();
oc_img11.src = "../images/oc_btm_right.jpg";
oc_img12 = new Image();
oc_img12.src = "../images/oc_right_btm.jpg";
oc_img13 = new Image();
oc_img13.src = "images/oc_left_bk.jpg";
oc_img14 = new Image();
oc_img14.src = "images/oc_right_bk.jpg";
oc_img_splash = new Image();
oc_img_splash.src = "images/oc_splash.jpg";