// JavaScript Document
function show_Old(){
//document.formAddProduct.grp.style.display=""; grpNew
document.formAddProduct.grpOld.style.display=""; 
document.formAddProduct.grpNew.style.display="none"; 
document.formAddProduct.grp.value=""; //clear the value
document.formAddProduct.grpOld.value=""; //clear the value
}
function show_New(){
//document.formAddProduct.grp.style.display=""; grpNew
document.formAddProduct.grpNew.style.display=""; 
document.formAddProduct.grpOld.style.display="none"; 
document.formAddProduct.grp.value=""; //clear the value
document.formAddProduct.grpNew.value=""; //clear the value
}
function check_Value(){
	var grpOld = document.getElementById('grpOld');
	var grpNew = document.getElementById('grpNew');

	if (grpOld.style.display == "none"){
	//alert("Listbox is hidden");//therefore textbox is active, then get the value of grpNew/textbox
	document.formAddProduct.grp.value = document.formAddProduct.grpNew.value;
	
	}
	else if(grpNew.style.display == "none"){
	//alert("textbox is hidden");//therefore listbox is active, then get the value of grpOld/listbox
	document.formAddProduct.grp.value = document.formAddProduct.grpOld.value; 
	
	}
}

function myFocus(textfield){
document.getElementById(textfield).focus();
}

//for addingredients page
function check_blank(){
    //ssvar ingrdnts = document.addIngredients.'ingrdnts[]'.value;
	var ingrdnts = document.getElementById('ingrdnts[]').value;
	if(ingrdnts == ""){
	alert("Please make sure that all your text field has a value before submitting. Thank you");
	return false;
	}
}


function login_check(){
    if (document.login.user.value == "") {
        alert('Please provide your username and password');
        document.login.user.focus();
        return false;
    } else if (document.login.pass.value == "") {
        alert('Please provide your username and password');
        document.login.pass.focus();
        return false;
    } else {
        return true;
    }
}

function click(e) {
var message="All Rights Reserved to msbi.com.sa";
if (document.all) {
if (event.button == 2) {
alert(message);
return false;
}
}
if (document.layers) {
if (e.which == 3) {
alert(message);
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;


//testing erase me afterwards
var DDSPEED = 10;
var DDTIMER = 15;
var OFFSET = -2;
var ZINT = 100;

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);
    c.style.display = 'block';
    if(c.maxh && c.maxh <= c.offsetHeight){return}
    else if(!c.maxh){
      c.style.left = (h.offsetWidth + OFFSET) + 'px';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';
    }
    ZINT = ZINT + 1;
    c.style.zIndex = ZINT;
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }else{
    h.timer = setTimeout(function(){ddCollapse(c)},50);
  }
}

function ddCollapse(c){
  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
}

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);
  }
}

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 > (c.maxh - 2) && d == 1){
    clearInterval(c.timer);
  }else if(dist < 1 && d != 1){
    clearInterval(c.timer);
    c.style.display = 'none';
  }
}

//add textbox
var arrInput = new Array(0);
var arrInputValue = new Array(0);

function addInput() {
  //arrInput.push(createInput(arrInput.length));
  arrInput.push(arrInput.length);
  //arrInputValue.push(arrInputValue.length);
  arrInputValue.push("");
  display();
}

function display() {
  document.getElementById('parah').innerHTML="";
  for (intI=0;intI<arrInput.length;intI++) {
    document.getElementById('parah').innerHTML+=createInput(arrInput[intI], arrInputValue[intI]);
  }
}

function saveValue(intId,strValue) {
  arrInputValue[intId]=strValue;
}

function createInput(id,value) {
  return "<input name='ingrdnts[]' id='ingrdnts[]' class='text10DBlue' size='150' maxlength='150' type='text' id='test "+ id +"' onChange='javascript:saveValue("+ id +",this.value)' value='"+ value +"'><br>"; }

function deleteInput() {
  if (arrInput.length > 1) {
     arrInput.pop();
     arrInputValue.pop();
  }
  display();
}
//end of fucntion add input

//all functions fro upd_Latest_News_1.php
function show_uploadBox(){
var pixCurVal = document.getElementById('pixCurVal');
pixCurVal.style.display="none";
document.form1.pix.style.display="";
document.form1.pix2.style.display="";

}
function hide_uploadBox(){
var pixCurVal = document.getElementById('pixCurVal');
pixCurVal.style.display="";
document.form1.pix.style.display="none";
document.form1.pix2.style.display="none";
}
function check_pix(){
//var pix = document.getElementById('pix');
var pixStatus = document.form1.pix.style.display;
var pix = document.form1.pix.value;

if(pixStatus == ""){
	if(pix == ""){
		alert("please upload a picture");	
		return false;
		}
}else{
return true;
}
}

function check_pix2(){
//var pix = document.getElementById('pix');
var pixStatus2 = document.form1.pix2.style.display;
var pix2 = document.form1.pix2.value;
if(pixStatus2 == ""){
	if(pix2 == ""){
		alert("please upload a thumbnail picture");	
		return false;
		}
}else{
return true;
}
}

