//alert(getCookie("screenwidth"));
//if (getCookie("screenwidth") == null || getCookie("screenheight") == null) {
	//alert('setting size cookies');
	var isNav4, isIE4;
	var screenwidth, screenheight;
	
	if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
		isNav4 = (navigator.appName == "Netscape") ? 1 : 0;
		isIE4 = (navigator.appName.indexOf("Microsoft") != -1) ? 1 : 0;
	}
	
	if (isNav4) {
	screenwidth = screen.availWidth;
	screenheight = screen.availHeight;
	}
	
	if (isIE4) {
	screenwidth = screen.availWidth;
	screenheight = screen.availHeight;
	}

	var expdate = new Date();
	expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
	setCookie ("screenwidth", screenwidth, expdate);
	setCookie ("screenheight", screenheight, expdate);
//}


function getCookie (name) {

	var dcookie = document.cookie; 
	var cname = name + "=";
	var clen = dcookie.length;

	var cbegin = 0;
	        while (cbegin < clen) {
	        var vbegin = cbegin + cname.length;
	                if (dcookie.substring(cbegin, vbegin) == cname) { 
	                var vend = dcookie.indexOf (";", vbegin);
	                        if (vend == -1) vend = clen;
	                return unescape(dcookie.substring(vbegin, vend));
	                }
	        cbegin = dcookie.indexOf(" ", cbegin) + 1;
	                if (cbegin == 0) break;
	        }
	return null;
}

function getCookieNotEscaped (name) {

	var dcookie = document.cookie; 
	var cname = name + "=";
	var clen = dcookie.length;

	var cbegin = 0;
	        while (cbegin < clen) {
	        var vbegin = cbegin + cname.length;
	                if (dcookie.substring(cbegin, vbegin) == cname) { 
	                var vend = dcookie.indexOf (";", vbegin);
	                        if (vend == -1) vend = clen;
	                return dcookie.substring(vbegin, vend);
	                }
	        cbegin = dcookie.indexOf(" ", cbegin) + 1;
	                if (cbegin == 0) break;
	        }
	return null;
}

function setCookie (name, value, expires) {
        if (!expires) expires = new Date();
document.cookie = name + "=" + escape (value) + 
"; expires=" + expires.toGMTString() +  "; path=/";
}

function delCookie (name) {
var expireNow = new Date();
document.cookie = name + "=" +
"; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}


function replace(string,text,by) {
// Replaces text with by in string
	if (string == null) return string;
	
    var strLength = string.length
	var txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function GetTableWidth() {
	var sTableWidth
	var lScreenWidth = getCookie("screenwidth");
	
	if (lScreenWidth == null) lScreenWidth = 0;
	lScreenWidth = parseInt(lScreenWidth);
	
	if (lScreenWidth < 1024) sTableWidth = "100%";
	else if (lScreenWidth >= 1024) sTableWidth = "900";
		
	return sTableWidth;
}

	function editMode(sAction, sURL) {
		if (sAction == 'openEditWindow') {
			MyWnd = window.open(sURL, 'backstream', '');
			MyWnd.focus();
			return false;
		}
	}

function showLayer(object) {
	if (document.getElementById && !document.all )
		document.getElementById(object).style.visibility = 'visible';
    else if (document.all)
        document.all[object].style.visibility = 'visible';
    else if (document.layers && document.layers[object] != null)
        document.layers[object].visibility = 'visible';
}

function hideLayer(object) {
	if (document.getElementById && !document.all )
		document.getElementById(object).style.visibility = 'hidden';
    else if (document.layers && document.layers[object] != null)
        document.layers[object].visibility = 'hidden';
    else if (document.all)
        document.all[object].style.visibility = 'hidden';
}


function formcheck_1(formobj){
	var fieldRequired = Array("c_fname", "c_lname", "c_email", "department", "concern", "note");
	var fieldDescription = Array("First Name", "Last Name", "Email Address", "To", "Concern", "Note");
	var alertMsg = "Please complete the following fields:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			if (obj.type == null){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				continue;
			}

			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}


function formcheck_2(formobj){
	var fieldRequired = Array("name_first", "name_last");
	var fieldDescription = Array("First Name", "Last Name");

	var fieldRequired_1 = Array("company", "position", "country", "city");
	var fieldDescription_1 = Array("Company", "Your Position", "Country", "City");

	var alertMsg = "Please complete the following fields:\n";
	
	var l_Msg = alertMsg.length;
	

	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			if (obj.type == null){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				continue;
			}

			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:

			}


		}

	}


//priv_prof

  if (!document.create_account_1.priv_prof[0].checked &&
      !document.create_account_1.priv_prof[1].checked) {
    alertMsg += " - " + "priv_prof" + "\n";
  }





	for (var i = 0; i < fieldRequired_1.length; i++){
		var obj = formobj.elements[fieldRequired_1[i]];
		if (obj){
			if (obj.type == null){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription_1[i] + "\n";
				}
				continue;
			}

			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription_1[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription_1[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription_1[i] + "\n";
				}
				break;
			default:

			}


		}

	}








	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}



function formcheck_ca_cd(formobj){

	var alertMsg = "Please complete the following fields:\n";

	var l_Msg = alertMsg.length;




  if ( document.create_account_1.name_first.value == "" ) {
    alertMsg += " - " + "First Name" + "\n";
    document.getElementById("first_name_point").className = 'red_point_1';
  }
  else {
    document.getElementById("first_name_point").className = 'green_point_1';
  }

  if ( document.create_account_1.name_last.value == "" ) {
    alertMsg += " - " + "Last Name" + "\n";
    document.getElementById("last_name_point").className = 'red_point_1';
  }
  else {
    document.getElementById("last_name_point").className = 'green_point_1';
  }

  if (!document.create_account_1.priv_prof[0].checked &&
      !document.create_account_1.priv_prof[1].checked) {
    alertMsg += " - " + "Professional" + "\n";
    document.getElementById("priv_prof_point").className = 'red_point_1';
  }
  else {
    document.getElementById("priv_prof_point").className = 'green_point_1';
  }

  if ( document.create_account_1.company.value == "" ) {
    alertMsg += " - " + "Company" + "\n";
    document.getElementById("company_point").className = 'red_point_1';
  }
  else {
    document.getElementById("company_point").className = 'green_point_1';
  }

  if ( document.create_account_1.position.value == "" ) {
    alertMsg += " - " + "Your Position" + "\n";
    document.getElementById("position_point").className = 'red_point_1';
  }
  else {
    document.getElementById("position_point").className = 'green_point_1';
  }

  if ( document.create_account_1.country.selectedIndex == 0 ) {
    alertMsg += " - " + "Country" + "\n";
    document.getElementById("country_point").className = 'red_point_1';
  }
  else {
    document.getElementById("country_point").className = 'green_point_1';
  }

  if ( document.create_account_1.country.value == "United States" ) {
    if ( document.create_account_1.state_sel.selectedIndex == 0 ) {
      alertMsg += " - " + "State" + "\n";
      document.getElementById("state_point").className = 'red_point_1';
    }
    else {
      document.getElementById("state_point").className = 'green_point_1';
    }
  }

  if ( document.create_account_1.city.value == "" ) {
    alertMsg += " - " + "City" + "\n";
    document.getElementById("city_point").className = 'red_point_1';
  }
  else {
    document.getElementById("city_point").className = 'green_point_1';
  }

  if ( document.create_account_1.zip.value == "" ) {
    alertMsg += " - " + "ZIP Code" + "\n";
    document.getElementById("zip_point").className = 'red_point_1';
  }
  else {
    document.getElementById("zip_point").className = 'green_point_1';
  }

  if ( document.create_account_1.address_1.value == "" ) {
    alertMsg += " - " + "Address 1" + "\n";
    document.getElementById("address_1_point").className = 'red_point_1';
  }
  else {
    document.getElementById("address_1_point").className = 'green_point_1';
  }

  if ( document.create_account_1.phone_number.value == "" ) {
    alertMsg += " - " + "Phone" + "\n";
    document.getElementById("phone_number_point").className = 'red_point_1';
  }
  else {
    document.getElementById("phone_number_point").className = 'green_point_1';
  }

  if ( document.create_account_1.email_1.value == "" ) {
    alertMsg += " - " + "Email 1" + "\n";
    document.getElementById("email_1_point").className = 'red_point_1';
  }
  else {
    document.getElementById("email_1_point").className = 'green_point_1';
  }

  if (!document.create_account_1.gender[0].checked &&
      !document.create_account_1.gender[1].checked) {
    alertMsg += " - " + "Gender" + "\n";
    document.getElementById("gender_point").className = 'red_point_1';
  }
  else {
    document.getElementById("gender_point").className = 'green_point_1';
  }

  if ( document.create_account_1.age_1.selectedIndex == 0 ) {
    alertMsg += " - " + "Year";
  }
  if ( document.create_account_1.age_2.selectedIndex == 0 ) {
    alertMsg += " Month";
  }
  if ( document.create_account_1.age_3.selectedIndex == 0 ) {
    alertMsg += " Day";
  }
  if ( document.create_account_1.age_1.selectedIndex == 0  || 
      document.create_account_1.age_2.selectedIndex == 0  || 
      document.create_account_1.age_3.selectedIndex == 0 ) {
    alertMsg += " of Birth" + "\n";
    document.getElementById("age_point").className = 'red_point_1';
  }
  else {
    document.getElementById("age_point").className = 'green_point_1';
  }

  if (!document.create_account_1.tos[0].checked) {
    alertMsg += " - " + "Accept our Terms of Service" + "\n";
      document.getElementById("tos_point").className = 'red_point_1';
  }
  else {
    document.getElementById("tos_point").className = 'green_point_1';
  }



	if (alertMsg.length == l_Msg){
		return true;
	}
  else{
		alert(alertMsg);
		return false;
	}
}


function change_state(country_chosen){

//country code
var country_arr = new Array("Afghanistan","Albania","Algeria","Andorra","Angola",
  	"Antigua and Barbuda","Argentina","Armenia","Aruba",
  	"Australia","Austria","Azerbaidjan","Bahrain","Bangladesh",
  	"Barbados","Belarus","Belgium","Belize","Benin","Bermuda",
  	"Bolivia","Bosnia-Herzegovina","Botswana","Brazil",
  	"Brunei","Bulgaria","Burkina Faso","Burkina Faso","Burundi","Cambodia",
  	"Cameroon","Canada","Cape Verde","Cayman Islands",
  	"Central African Republic","Chad","Chile","China",
  	"Colombia","Congo","Congo Democratic Republic",
  	"Croatia","Cuba","Curacao","Cyprus","Czech Republic","Denmark",
  	"Dominica","Dominican Republic","Ecuador",
  	"Egypt","El Salvador","Equatorial Guinea","Estonia","Ethiopia",
  	"Faroe Islands","Fiji","Finland",
  	"France","French Guyana","French Polynesia","Gabon","Gambia",
  	"Georgia","Germany","Ghana","Gibraltar","Great Britain","Greece",
  	"Greenland","Guadeloupe","Guam","Guatemala","Guinea",
  	"Guyana","Haiti","Honduras","Hong Kong","Hungary",
  	"Iceland","India","Indonesia","Iran","Iraq","Ireland","Israel",
  	"Italy","Ivory Coast","Jamaica","Japan","Jordan","Kazakhstan",
  	"Kenya","Korea (South)","Kuwait","Kyrgyzstan","Laos","Latvia","Lebanon",
  	"Lesotho","Liberia","Libya","Liechtenstein","Lithuania","Luxembourg",
  	"Macedonia","Madagascar","Malawi","Malaysia","Maldives",
  	"Mali","Malta","Marshall Islands","Martinique","Mauritania",
  	"Mauritius","Mexico","Micronesia","Moldavia","Monaco",
  	"Mongolia","Montserrat","Morocco","Mozambique","Myanmar","Namibia",
  	"Nepal","Netherlands Antilles","Netherlands",
  	"New Caledonia","New Zealand","Nicaragua","Niger","Nigeria",
  	"Norfolk Island","North Korea","Norway","Oman","Pakistan",
  	"Palestine","Panama","Papua New Guinea","Paraguay","Peru","Philippines",
  	"Poland","Polynesia","Portugal","Puerto Rico",
  	"Qatar","Romania","Russian Federation","Rwanda",
  	"Saint Helena","Saint Vincent and the Grenadines",
  	"San Marino","Saudi Arabia","Senegal","Serbia","Seychelles",
  	"Sierra Leone","Singapore","Slovak Republic","Slovenia",
  	"Solomon Islands","Somalia","South Africa","South Korea","Spain",
  	"Sri Lanka","Sudan","Suriname","Swaziland","Sweden","Switzerland",
  	"Syria","Tadjikistan","Taiwan","Tanzania","Thailand",
  	"Togo","Tonga","Trinidad and Tobago",
  	"Tunisia","Turkey","Turkmenistan","Tuvalu","Uganda","Ukraine",
  	"United Arab Emirates","United States","Uruguay",
  	"Uzbekistan","Vanuatu","Vatican","Venezuela","Vietnam",
  	"Virgin Islands (British)","Virgin Islands (USA)",
  	"Wallis and Futuna Islands","Yemen",
  	"Zaire","Zambia","Zimbabwe","Elsewhere in America",
  	"Elsewhere in Asia","Elsewhere in Europe","Elsewhere in Africa");

var country_cc_arr = new Array("93","355","213","376","244",
  	"1268","54","374","297",
  	"61","43","994","973","880",
  	"1246","375","32","501","229","1441",
  	"591","387","267","55",
  	"673","359","226","226","257","855",
  	"237","1","238","1345",
  	"236","235","56","86",
  	"57","242","243",
  	"385","53","5999","357","420","45",
  	"1767","1809","593",
  	"20","503","240","372","251",
  	"298","679","358",
  	"33","594","689","241","220",
  	"995","49","233","350","44","30",
  	"299","590","1","502","224",
  	"592","509","504","852","36",
  	"354","91","62","98","964","353","972",
  	"39","225","1876","81","962","7",
  	"254","82","965","996","856","371","961",
  	"266","231","218","423","370","352",
  	"389","261","265","60","960",
  	"223","356","692","692","222",
  	"230","52","691","373","377",
  	"976","664","212","258","95","264",
  	"977","599","31",
  	"687","64","505","227","234",
  	"672","850","47","968","92",
  	"970","507","675","595","51","63",
  	"48","689","351","1787",
  	"974","40","7","250",
  	"290","1784",
  	"378","966","221","381","248",
  	"232","65","421","386",
  	"677","252","27","82","34",
  	"94","249","597","268","46","41",
  	"963","992","886","255","66",
  	"228","676","1868",
  	"216","90","993","688","256","380",
  	"971","1","598",
  	"998","678","39","58","84",
  	"1340 ","1340 ",
  	"681","967",
  	"243","260","263","",
  	"","","");

  var country_cc;
  country_arr_no = country_arr.length;
	for (loop=0; loop < country_arr_no; loop++) {
    if(country_arr[loop] == country_chosen) {
      country_cc = loop;
      break;
    }
  }
  country_cc = country_cc_arr[country_cc];
  document.getElementById("phone_cc").value = country_cc;
  document.getElementById("fax_cc").value = country_cc;
  document.getElementById("mobile_cc").value = country_cc;


//change state/province
  if (country_chosen == "United States") {

		document.getElementById("province").style.display = 'none';

    document.getElementById("state").style.display = 'block';

    document.getElementById("state_point").className = 'red_point_1';

  }
  else {
		document.getElementById("province").style.display = 'block';

    document.getElementById("state").style.display = 'none';

    document.getElementById("state_point").className = 'bg_point_1';
  }
}


function passwordChanged(pass_str) {

  if(pass_str.length >= 10 && pass_str.length <= 20) {
    document.getElementById("strength_1").className = 'gray';
  }
  else {
    document.getElementById("strength_1").className = 'red';
  }

  var ucase_count = pass_str.match(/[A-Z]/g);

  if(ucase_count == null) {
    document.getElementById("strength_2").className = 'red';
  }
  else {
    document.getElementById("strength_2").className = 'gray';
  }

  var lcase_count = pass_str.match(/[a-z]/g);
  if(lcase_count == null) {
    document.getElementById("strength_3").className = 'red';
  }
  else {
    document.getElementById("strength_3").className = 'gray';
  }

  var number_count = pass_str.match(/[0-9]/g);
  if(number_count == null) {
    document.getElementById("strength_4").className = 'red';
  }
  else {
    document.getElementById("strength_4").className = 'gray';
  }

  var s_char_count = pass_str.match(/[!,@,#,$,%,^,&,*,?,_,~]/g);
  if(s_char_count == null) {
    document.getElementById("strength_5").className = 'red';
  }
  else {
    document.getElementById("strength_5").className = 'gray';
  }
}


function formcheck_ca_ad(formobj) {

	var alertMsg = "Please complete/correct the following fields:\n";
	var l_Msg = alertMsg.length;

//email
  var email_str = document.access_data_form.email.value;

  var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
  if (!filter.test(email_str)) {
    alertMsg += " - " + "Email" + "\n";
//    alertMsg += " - " + "Email" + "\n" + email_str + "\n";

    document.getElementById("ac_email_id").className = 'red_point_1';
  }
  else {
    document.getElementById("ac_email_id").className = 'green_point_1';
  }

//pass
  var pass_str = document.access_data_form.password.value;
  var pass_error_count = 0;

  if(pass_str.length >= 10 && pass_str.length <= 20) {
    document.getElementById("strength_1").className = 'gray';
  }
  else {
    document.getElementById("strength_1").className = 'red';
    pass_error_count++;
  }

  var ucase_count = pass_str.match(/[A-Z]/g);

  if(ucase_count == null) {
    document.getElementById("strength_2").className = 'red';
    pass_error_count++;
  }
  else {
    document.getElementById("strength_2").className = 'gray';
  }

  var lcase_count = pass_str.match(/[a-z]/g);
  if(lcase_count == null) {
    document.getElementById("strength_3").className = 'red';
    pass_error_count++;
  }
  else {
    document.getElementById("strength_3").className = 'gray';
  }

  var number_count = pass_str.match(/[0-9]/g);
  if(number_count == null) {
    document.getElementById("strength_4").className = 'red';
    pass_error_count++;
  }
  else {
    document.getElementById("strength_4").className = 'gray';
  }

  var s_char_count = pass_str.match(/[!,@,#,$,%,^,&,*,?,_,~]/g);
  if(s_char_count == null) {
    document.getElementById("strength_5").className = 'red';
    pass_error_count++;
  }
  else {
    document.getElementById("strength_5").className = 'gray';
  }

  if(pass_error_count > 0) {
    alertMsg += " - " + "Password" + "\n";
    document.getElementById("ac_pass_id").className = 'red_point_1';
  }
  else {
    document.getElementById("ac_pass_id").className = 'green_point_1';
  }

//challenge
  if ( document.access_data_form.pc_choose.selectedIndex == 0 ) {
    document.getElementById("pc_id").className = 'red_point_1';
    alertMsg += " - " + "Password Challenge" + "\n";
  }
  else {
    document.getElementById("pc_id").className = 'green_point_1';
  }

//answer
//answer_id
  if ( document.access_data_form.pc_answer.value == "" ) {
    document.getElementById("ac_answer_id").className = 'red_point_1';
    alertMsg += " - " + "Your Answer";
  }
  else {
    document.getElementById("ac_answer_id").className = 'green_point_1';
  }




//return
	if (alertMsg.length == l_Msg){
		return true;
	}
  else{
		alert(alertMsg);
		return false;
	}
}




function zoom_item(max_width, max_height, item_id) {

  var nw_max_width = max_width + 40 + 100;
  var nw_max_height = max_height + 40 + 26 + 26 + 10;

  var conf_str = 'left=20,top=20,width=' + nw_max_width + ',height=' + nw_max_height + ',toolbar=0,resizable=0,location=0';
  var url_str = 'http://www.the-medical-market.com/serv1.php?type=zoomed_imgages&id=' + item_id;

  myRef = window.open(url_str,'mywin',conf_str);
  myRef.focus();


}

function image_organizer_1(item_id) {

  var conf_str = 'left=20,top=20,width=700,height=800,toolbar=0,resizable=1,location=0,scrollbars=1';

  myRef = window.open('http://www.the-medical-market.com/serv1.php?type=image_organizer&item_id='+item_id,'mywin',
      conf_str);
  myRef.focus();

}


function limitText_1(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

