window.status = "GIDS2010 POST SUMMIT";

/**
* This fuction is used to download speaker presentation also check for user login
*
* @access   presentation
* @param    null
*
* @return   null
*/
function downloadPDF(presentation) {
	loginName=document.getElementById("hidSessionName").value;
	siteurl=document.getElementById("hidURL").value;
	if (loginName) {
		document.getElementById("action").value="downloadPDF";
		document.getElementById("hidPresentation").value=presentation;
		document.getElementById("hidPDF").value=presentation;
		document.pageform.submit();
	}
	else {
		alert('You have to login to download this document.');
		document.getElementById("action").value="goToDevmarchLogin";
		document.pageform.submit();
	}
}

/**
* This fuction is used to open Speaker Video panel
*
* @access   public
* @param    e vsrc
*
* @return   null
*/
function viewVideoLayer(e, vsrc) {
	//alert (vsrc);
	var posx = 0;
	var posy = 0;
	if (!e) {
		e = window.event;
	}
	var vid = document.getElementById('dialog');

	if (vid!=null) {
		if (e.pageX || e.pageY)	{

			posy = e.pageY-180;
			vid.style.top = posy+130+"px";
			vid.style.left=350+"px";
		}
		else if (e.clientX || e.clientY) {//IE
			posy = e.clientY + document.body.scrollTop;
			vid.style.top = posy-140+"px";
			vid.style.left= 335+"px";
		}
		vid.style.display='';

		vid.innerHTML='';

		vid.innerHTML="<div id='handle' style=background:#FFF;moz-opacity:0;opacity:0;filter:alpha(opacity=0);color:black;height:17px;_height:19px;cursor:move;padding-bottom:4px;'><a href='javascript:void(0);' onclick='closeLayer(\"dialog\")'><b style='color:red;font-size:10pt;float:right;margin:0px 0px 0px 0px;cursor:pointer;font-family:Arial, Helvetica, Sans-serif'>[X]</b></a></div>";
		vid.innerHTML+='<div style="padding:2px 0 0 20px"><embed width="322" height="242" wmode="opaque" allowscriptaccess="always" allowfullscreen="true" quality="high"  src="'+vsrc+'" type="application/x-shockwave-flash"></embed></div>';

		var theHandle = document.getElementById("handle");
		var theRoot = vid;
		Drag.init(theHandle, theRoot);
	}
}

/**
* This fuction is used to close open Speakers Video panel
*
* @access   public
* @param    divId
*
* @return   null
*/
function closeLayer(divId) {
	document.getElementById(divId).style.display="none";
}

/**
* This fuction is used to save contact
*
* @access   public
* @param    null
*
* @return   null
*/
function saveContact() {
	if (contactValidation()) {
		document.getElementById("action").value="SaveContact";
		document.getElementById("pageform").submit();
	}
}

/**
* This fuction is used to validate contact details
*
* @access   public
* @param    null
*
* @return   true / false
*/
function contactValidation() {
	if(document.getElementById("moreinfo").value=='new') {
		alert("Please select contact title.");
		document.getElementById("moreinfo").focus();
		return;
	}
	else if(document.getElementById("firstname").value.match(/^ *$/)) {
		alert("Please enter first name");
		document.getElementById("firstname").focus();
		return;
	}
	else if(document.getElementById("lastname").value.match(/^ *$/)) {
		alert("Please enter last name.");
		document.getElementById("lastname").focus();
		return;
	}
	else if(checkEmail(document.getElementById("email").value)!=true) {
		//alert("*Invalid E-mail Address! Please Enter valid E-mail Address.");
		document.getElementById("email").value='';
		document.getElementById("email").focus();
		return;
	}

	return true;
}

/**
* This fuction is used to validate email address
*
* @access   public
* @param    str
*
* @return   true / false
*/
function checkEmail(str) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str)) {
		return (true);
	}
	alert("Invalid E-mail Address! Please Enter valid E-mail Address.");
	return (false);
}

var keynum;
var keychar;
var numcheck;
/**
* This fuction is used to validate only characters on keypress event on text
*
* @access   public
* @param    e
*
* @return   true / false
*/
function validChar (e)	{
	keynum = (window.event) ? window.event.keyCode : e.which;
	if (keynum == parseInt(8) || keynum == parseInt(0))
		return true;
	keychar = String.fromCharCode(keynum);
	var validchars = new RegExp("[ A-Za-z]");	/*[ A-Za-z0-9&,.-]*/
	return validchars.test(keychar);
}

/**
* This fuction is used to validate character or digits on keypress event on text
*
* @access   public
* @param    e
*
* @return   true / false
*/
function validAlphaChar (e)	{
	keynum = (window.event) ? window.event.keyCode : e.which;
	if (keynum == parseInt(8) || keynum == parseInt(0))
		return true;
	if ( (keynum == parseInt(47)) || (keynum == parseInt(61)) )
		return false;

	keychar = String.fromCharCode(keynum);
	var validchars = new RegExp("[ A-Za-z0-9.-@]");
	return validchars.test(keychar);
}

/**
* This fuction is used to validate only digits on keypress event on text
*
* @access   public
* @param    e
*
* @return   true / false
*/
function validDigits (e)	{
	keynum = (window.event) ? window.event.keyCode : e.which;
	if (keynum == parseInt(8) || keynum == parseInt(0))
		return true;
	keychar = String.fromCharCode(keynum);
	var validchars = new RegExp("[0-9]");
	return validchars.test(keychar);
}

/**
* This fuction is used to move curosor top location
*
* @access   public
* @param    id
*
* @return   null
*/
/* usage
	<a href="" onClick="goToByScroll('1')">top</a>
	<div id="1"> sdf sadf asdf sad f </div>
*/
function goToByScroll(id){
	$('html,body').animate({scrollTop: $("#"+id).offset().top},'slow');
}

/**
* This fuction is used to print on the console
*
* @access   public
* @param    msg
*
* @return   null
*/
/*

	$("input:text").val( function(index, value) {
			$().log(value + ' ' + index);
			return value;
		});

*/
jQuery.fn.log = function (msg) {
	if (window.console)
		window.console.log("%s: %o", msg, this); //$(this).text()
	return this;
};

/**
* This fuction is used to save track age of an image
*
* @access   public
* @param    imgName
*
* @return   null
*/
function addImageImpressions(imgName) {
	//alert (imgName); return;
	document.getElementById("action").value="addImageImpression";
	document.getElementById("hidImgName").value=imgName;
	$('form').submit();
	//document.pageform.submit();
}

$( 'a#addImgImps' ).click( function (event) {
		event.preventDefault();
		event.stopPropagation();
		if ($.browser.msie) {
			event.originalEvent.keyCode = 0;
			event.originalEvent.cancelBubble = true;
			event.originalEvent.returnValue = false;
		}
	});

/**
* This fuction is used to save track age of an image
*
* @access   public
* @param    imgName
*
* @return   null
*/
/* how to use
* $('form').clearForm();
* $(':input').clearForm();
* $( "form" )[0].reset();
*/

$.fn.clearForm = function() {
  return this.each(function() {
    var type = this.type, tag = this.tagName.toLowerCase();
    if (tag == 'form')
      return $(':input',this).clearForm();
    if (type == 'text' || type == 'password' || tag == 'textarea')
      this.value = '';
    else if (type == 'checkbox' || type == 'radio')
      this.checked = false;
    else if (tag == 'select')
      this.selectedIndex = 0;
  });
};
