
var DDSPEED = 10;
var DDTIMER = 15;


// collapse the menu //
function ddCollapse(c){
  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
}




// main function to handle the mouse events //
function ddMenu(id,d){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearInterval(c.timer);
  if(d == 1){
    clearTimeout(h.timer);
    if(c.maxh && c.maxh <= c.offsetHeight){return}
    else if(!c.maxh){
      c.style.display = 'block';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';

    }
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }else{
    h.timer = setTimeout(function(){ddCollapse(c)},50);
  }
}



// cancel the collapse if a user rolls over the dropdown //
function cancelHide(id){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(c,d){
  var currh = c.offsetHeight;
  var dist;
  if(d == 1){
    dist = (Math.round((c.maxh - currh) / DDSPEED));
  }else{
    dist = (Math.round(currh / DDSPEED));
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  c.style.height = currh + (dist * d) + 'px';
  c.style.opacity = currh / c.maxh;
  c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
  if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    clearInterval(c.timer);
  }
}  




//main page blur************
// incrementally expand/contract the dropdown and change the opacity //
function addEvent(obj ,evt, fnc)
      {
        if (obj.addEventListener)
          obj.addEventListener(evt,fnc,false);
        else if (obj.attachEvent)
          obj.attachEvent('on'+evt,fnc);
        else
          return false;
        return true;
      }

function removeEvent(obj ,evt, fnc)
{
if (obj.removeEventListener)
  obj.removeEventListener(evt,fnc,false);
else if (obj.detachEvent)
  obj.detachEvent('on'+evt,fnc);
else
  return false;
return true;
}

//----------

function appendElement(node,tag,id,htm)
{
var ne = document.createElement(tag);
if(id) ne.id = id;
if(htm) ne.innerHTML = htm;
node.appendChild(ne);
}

//----------

function showPopup(p)
{	
greyout(true);
document.getElementById(p).style.display = 'block';
}

function hidePopup(p)
{
greyout(false);
document.getElementById(p).style.display = 'none';
}

//----------

function greyout(d,z)
{
	var obj = document.getElementById('greyout');
	if(!obj)
	{
	  appendElement(document.body,'div','greyout');
	  obj = document.getElementById('greyout');
	  obj.style.position = 'absolute';
	  obj.style.top = '0px';
	  obj.style.left = '0px';
	  obj.style.background = '#000';
	  obj.style.opacity = '.5';
	  obj.style.filter = 'alpha(opacity=50)';
	}
	if(d)
	{
	  if(!z){ z - 50 }
	  obj.style.zIndex = z;
	  obj.style.height = Math.max(document.body.scrollHeight,document.body.clientHeight)+'px';
	  obj.style.width  = Math.max(document.body.scrollWidth,document.body.clientWidth)+'px';
	  obj.style.display = 'block';
	  addEvent(window,'resize',greyoutResize);
	}
	else
	{
	  obj.style.display = 'none';   
	  removeEvent(window,'resize',greyoutResize);
	}
}


function greyoutResize()
 {
	var obj = document.getElementById('greyout');
	obj.style.height = document.body.clientHeight+'px';
	obj.style.width  = document.body.clientWidth+'px';
	obj.style.height = Math.max(document.body.scrollHeight,document.body.clientHeight)+'px';
	obj.style.width  = Math.max(document.body.scrollWidth,document.body.clientWidth)+'px';
 }



//SUBMITTING FORM
function validate(){
	obj=document.form_update_profile;
	
		if (obj.comp_name.value.trim()==""){
				alert("Please enter your Company Name.")
				obj.comp_name.focus();
				return false;
		}
		if (obj.address.value.trim()==""){
			alert("Please enter Company Address.")
			obj.address.focus();
			return false;
		}
		if (obj.con_person.value.trim()==""){
			alert("Please enter the Person to Contact.")
			obj.con_person.focus();
			return false;
		}
		if (obj.con_no.value.trim()==""){
			alert("Please enter Contact No.")
			obj.con_no.focus();
			return false;
		}
		if (obj.sec_question.value.trim()==""){
			alert("Please specify your Security Question.")
			obj.sec_question.focus();
			return false;
		}
		if (obj.sec_answer.value.trim()==""){
			alert("Please enter the Answer for your Security Question.")
			obj.sec_answer.focus();
			return false;
		}
		
		alert("Profile Updated Successfully.")
		document.form_update_profile.method="post";	
		document.form_update_profile.action="client_account.php";
		document.form_update_profile.submit();
	
}


function validate2(old){
	obj=document.form_change_password;
	
		if (obj.old_password.value==""){
				alert("Please enter the Old Password.")
				obj.old_password.focus();
				return false;
		}
		if (obj.old_password.value!=old){
			alert("Please enter the Correct Old Password.")
			obj.old_password.focus();
			return false;
		}
		if (obj.new_password.value==""){
			alert("Please enter the New Password.")
			obj.new_password.focus();
			return false;
		}
		if (obj.confirm_password.value==""){
			alert("Confirm your New Password.")
			obj.confirm_password.focus();
			return false;
		}
		if (obj.new_password.value!=obj.confirm_password.value){
			alert("Confirm your New Password.")
			obj.confirm_password.focus();
			return false;
		}
		
		alert("Password Successfully Changed.")
		document.form_change_password.method="post";	
		document.form_change_password.action="client_account.php";
		document.form_change_password.submit();
				
}

//VALIDATE NEW SUPPORT TICKET
function validate3(){
	obj=document.new_support_ticket;
	
		if (obj.type_request.value.trim()==""){
			alert("Specify Type of Request.")
			obj.type_request.focus();
			return false;
		}
		if (obj.product_involve.value.trim()==""){
			alert("Specify the Product Involved.")
			obj.product_involve.focus();
			return false;
		}
		if (obj.contact_details.value.trim()==""){
			alert("Enter your Contact Details.")
			obj.contact_details.focus();
			return false;
		}
		if (obj.message.value.trim()==""){
			alert("Please type your Message.")
			obj.message.focus();
			return false;
		}
		
		alert("Support Ticket Sent.")
		document.new_support_ticket.method="post";	
		document.new_support_ticket.action="client_account.php";
		document.new_support_ticket.submit();
	
}

//VALIDATE ADD MESSAGE
function validate_add_message(){
	obj=document.add_message_ticket;
	
	if (obj.message.value.trim()==""){
		alert("Please type your Message.")
		obj.message.focus();
		return false;
	}
	
	alert("Support Ticket Sent.")
	document.add_message_ticket.method="post";	
	document.add_message_ticket.action="add_message_ticket.php";
	document.add_message_ticket.submit();
	this.location.reload(true);
	obj.message.focus();
}


//VALIDATE VALIDATE SEARCH KEYWORD
function search_validate(){
	
	//obj=document.go_search;
	
	var keyword = document.getElementById('Keyword').value.trim();
	
	if (keyword=="" || keyword=="<SEARCH BY KEYWORD>"){
		obj.keyword.focus();
		return false;
	}
	else
	{ 
	/*
	document.go_search.method="post";	
	document.go_search.action="header.php";
	document.go_search.submit();
	*/
	
		window.location= "search_result.php?keyword=" + keyword;
	}
}


//VALIDATE ORDER
function validate_order(){
	
	obj=document.form_order;
	
	/*
	if (obj.odate_needed.value.trim()==""){
		alert("Specify Date Needed.")
		obj.odate_needed.focus();
		return false;
	}
	*/
	
	if (obj.ocomp_name.value.trim()==""){
		alert("Please enter your name.")
		obj.ocomp_name.focus();
		return false;
	}
	
	/*
	if (obj.ocontact_no.value.trim()==""){
		alert("Enter Conatact No.")
		obj.ocontact_no.focus();
		return false;
	}
	*/
	
	/*
	if (obj.oaddress.value.trim()==""){
		alert("Enter the Company Address.")
		obj.oaddress.focus();
		return false;
	}
	*/
	
	/*
	if (obj.ocountry.value.trim()==""){
		alert("Specify Country.")
		obj.ocountry.focus();
		return false;
	}
	*/
	
	
	if (obj.oemail.value.trim()==""){
		alert("Please enter your email address.")
		obj.oemail.focus();
		return false;
	}
   //validate email address...	
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = obj.oemail.value.trim();	
   
   if(reg.test(address) == false) 
    {
      alert('Please enter a valid email address');
	  obj.oemail.focus();
      return false;
    }
	
	/*
	if (obj.ocontact_person.value.trim()==""){
		alert("Enter the Name of the Person to Contact.")
		obj.ocontact_person.focus();
		return false;
	}
	*/
	
	alert("Inquiry submitted successfully.")
	document.form_order.method="post";	
	document.form_order.action="products.php";
	document.form_order.submit();
	//obj.message.focus();
}


//VALIDATE LOGIN...
function validate_login(){
	obj=document.form_in;
		
	if (obj.username_in.value.trim()==""){
		alert("Enter Username.")
		obj.username_in.focus();
		return false;
	}
	
	if (obj.password_in.value.trim()==""){
		alert("Enter Password.")
		obj.password_in.focus();
		return false;
	}
	
	//alert("Order Submitted Successfully.")
	document.form_in.method="post";	
	document.form_in.action="products.php";
	document.form_in.submit();
}




//TRIM FUNCTION 
String.prototype.trim = function() {
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};

//FUNCTION FOR POPUP
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=1');");
}



//VALIDATE EMAIL
function validate_email(get_pass_id,email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.forms[get_pass_id].elements[email].value;
   if(reg.test(address) == false) 
    {
      alert('Invalid Email Address');
      return false;
    }
   else
    {
		alert("The account info has been sent to your email.")
		document.form_get_password.method="post";	
		document.form_get_password.action="support.php";
		document.form_get_password.submit();
	}
}


	/************************************************************************************************************
	(C) www.dhtmlgoodies.com, November 2005
	
	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
	
	Terms of use:
	You are free to use this script as long as the copyright message is kept intact. However, you may not
	redistribute, sell or repost it without our permission.
	
	Thank you!
	
	www.dhtmlgoodies.com
	Alf Magne Kalleland
	
	************************************************************************************************************/
		
var slideTimeBetweenSteps = 45;	// General speed variable (Lower = slower)


var scrollingContainer = false;
var scrollingContent = false;
var containerHeight;
var contentHeight;	

var contentObjects = new Array();
var originalslideSpeed = false;
function slideContent(containerId)
{
	var topPos = contentObjects[containerId]['objRef'].style.top.replace(/[^\-0-9]/g,'');
	topPos = topPos - contentObjects[containerId]['slideSpeed'];
	if(topPos/1 + contentObjects[containerId]['contentHeight']/1<0)topPos = contentObjects[containerId]['containerHeight'];
	contentObjects[containerId]['objRef'].style.top = topPos + 'px';
	setTimeout('slideContent("' + containerId + '")',slideTimeBetweenSteps);
	
}

function stopSliding()
{
	var containerId = this.id;
	contentObjects[containerId]['slideSpeed'] = 0;	
}

function restartSliding()
{
	var containerId = this.id;
	contentObjects[containerId]['slideSpeed'] = contentObjects[containerId]['originalSpeed'];
	
}





function initSlidingContent(containerId,slideSpeed)
{
	scrollingContainer = document.getElementById(containerId);
	scrollingContent = scrollingContainer.getElementsByTagName('DIV')[0];
	
	scrollingContainer.style.position = 'relative';
	scrollingContainer.style.overflow = 'hidden';
	scrollingContent.style.position = 'relative';
	
	scrollingContainer.onmouseover = stopSliding;
	scrollingContainer.onmouseout = restartSliding;
	
	originalslideSpeed = slideSpeed;
	
	scrollingContent.style.top = '0px';
	
	contentObjects[containerId] = new Array();
	contentObjects[containerId]['objRef'] = scrollingContent;
	contentObjects[containerId]['contentHeight'] = scrollingContent.offsetHeight;
	contentObjects[containerId]['containerHeight'] = scrollingContainer.clientHeight;
	contentObjects[containerId]['slideSpeed'] = slideSpeed;
	contentObjects[containerId]['originalSpeed'] = slideSpeed;
	
	slideContent(containerId);
	
}


function EnterPressed(e)
 {
// Code adapted from Jennifer Madden
// http://jennifermadden.com/162/examples/stringEnterKeyDetector.html

  var characterCode
  if(e && e.which){           // NN4 specific code
    e = e
    characterCode = e.which
  }
  else {
    e = event
    characterCode = e.keyCode // IE specific code
  }
  if (characterCode == 13) return true   // Enter key is 13
  else return false
}




